connection sustain pedal into Max
If you have no midi keyboard with footwitch or controller input,
simpest I can think off is to insert 1.5 v battery cell and
switch it using that pedal to one of analog inputs on motu
using some resistance in series, to avoid battery drain.
that wil give you signal rise in max.
one could also short 1 of phantom powered pins on mic inputs to ground.
You will notice that allright in max on adc~, ha ha
or then arduino, switch one digital input short, and report the change.
best would be little 32u4 based board, it can act as midi or hid device.
or any other board as serial device.
whatever you decide, let me know if you need any schematic drawings
or arduino code etc
the idea using a battery will require opening the pedal so I guess I will avoid it.
The Arduino solution sounds interesting. I would love if you could share some schematics and Arduino code.
What is actually happens when pressing the pedal? because it is passive I could just guess then when the pedal is pressed the audio jack is shorting Tip to sleeve?
unscrewing pedal cover makes trouble for you ?
How would you go about soldering wires to Arduino,
mounting it into a litle box for protection, etc ?
Anyway, to do that dirty battery switch , you don't need to open the pedal.
insert male/female jack with battery holder and off you go.
----------
you posted the link to pedal, it states to have polarity switch,
which means that it can perfom both, short on press,
or open on press.
for arduino it does no matter at all, because it can react to both states.
If you need any precise, fast and time critical reporting,
that pedal is not good.
It has too long travel and maybe too hard action, typical for such pedals.
Better switch would make even 2 wires mounted on peace of wood and a bit of rubber in between.
anything that makes contact when pressed a bit...
There is no need for any schematics,
post which arduino you have at hand, I can send you the code for it.
all it needs is a female jack connector.
unscrewing pedal cover makes trouble for you ?
How would you go about soldering wires to Arduino,
mounting it into a litle box for protection, etc ?
I was thinking of connecting the 1/4" TS cable of the pedal into 1/4" Audio jack
My idea (so creative I know) is to use the sustain pedal for.. sustain a sound in max.
I have Arduino Uno
I do have female jack conector
uno rev3 ?
Can you send me more details , please.
main thing is which usb-serial chip it uses.
Also which OS and arduino IDE you use
I'll post you some code soon.
Yes it is arduino uno rev3 (aliexpress clone)
Im using mac os
Im not with my computerso im not sure which ide im usinng but probably the latest
I think your aliexpress clone uses cheap CH340 usb-serial,
instead of ATmega16u2.
Which if so, only leaves serial communication option, no midi.
But you must send me that info, ok ?
This code reads digital input 2 (with activated input pullup resistor) .
when you short it to ground, code sends "1" out, when released "0".
to avoid false retriggering it sends only if state changes and has debounce time 20ms.
If switch in the pedal is not really clean, increase delay time to 50 or more.
in max, set baud rate to 9600 and select your board, for example:

arduino code for ftdi or CH340 UNO
int SW; int exSW = 1;
void setup() {pinMode(2, INPUT_PULLUP); Serial.begin(9600);}
void loop() {SW = digitalRead(2);
if (SW != exSW and SW == 0) {Serial.write(1); delay(20); exSW = SW;}
if (SW != exSW and SW == 1) {Serial.write(0); delay(20); exSW = SW;}
}
Thanks! What is the difference between serial.write and serial.print? until now I have always used serial.print and route that data inside max.
The chip on my Uno is Atmega328P-PU
328 is processor, not usb-serial.
I need that info.
serial.write sends raw bytes 0-255.
same as midi does, for example.
as all you need is 0 and 1, no need to convert to ascii and then back in max.
Edit: working great!!
I accidentally connected tip to pin 3 instead of 2.
I've connected the tip of the pedal to arduino pin 2 and the sleeve of the pedal to arduino ground.
the output I'm getting from the serial object in max is rapid change between 0 and 1 no matter if I'm pressing the pedal or not.
What I'm doing wrong?
Ok I noticed something strange. when added the Max patch into a max for live device I have I can't read the pedal. I press one time and it output 1 but when released it won't back to 0 rather stay stuck.
edit: The above happens only in presentation mode. When I open the patch (by pressing the edit button below) it work fine.
edit2: solved from the info in this https://cycling74.com/forums/keep-serial-port-open-while-m4l-editor-is-closed
how can I add an id named "pedal" to the data I'm reading (0 or 1 ) from the sustain pedal via arduino into max?
I have the following code which is not working adding id "pedal" to the sustain pressing( 0 or 1)
void pedal() {
SW = digitalRead(A4);
if (SW != exSW and SW == 0) {
Serial.println("pedal");
Serial.write(1);
delay(20);
exSW = SW;
}
if (SW != exSW and SW == 1) {
Serial.println("pedal");
Serial.write(0);
delay(20);
exSW = SW;
}
}
You don't want to understand difference between print and write
in arduino, even after sooo many attempts from my side to explain it.
you should not mix print and write in same serial message.
Serial.print("pedal "); Serial.println(SW);
don't miss space in"pedal "
you can shorten the code a bit now that you want to prepend "pedal ",
I dislike writting too many letters ...
you invert reading using SW = 1 - digitalRead(A4);
here is complete code :
int SW; int exSW = 0;
void setup() {Serial.begin(9600); pinMode(A4, INPUT_PULLUP); }
void loop() {SW = 1 - digitalRead(A4);
if (SW != exSW) {Serial.print("pedal "); Serial.println(SW); delay(20); exSW = SW; }
}
in max :

Are you really using analog input A4 ?
Thanks for your code!
Are you really using analog input A4 ?
Yes, because all the other digital inputs/outputs are occupied
regarding the code:
because my code is doing different stuff at the same time - I wonder if the delay(20) is the best solution as it block the arduino from running for 20ms. I know 20ms is not much but maybe is better to avoid it by using millis() ?
int SW; int exSW = 0;
unsigned long startMillis;
unsigned long currentMillis;
int interval = 20;
void setup() {Serial.begin(9600); pinMode(A4, INPUT_PULLUP); }
void loop() {
SW = 1 - digitalRead(A4);
if (SW != exSW)
{
currentMillis = millis();
if (currentMillis - startMillis >= interval)
Serial.print("pedal "); Serial.println(SW);
startMillis = currentMillis;
exSW = SW;
}
}
if your switch is a good one, you don't need delay at all.
it helps only to avoid fast retriggering if switch is not reliable.
I'm not sure if my sustain pedal consider reliable.
Is the logic of my code using millis make sense?
I am afraid not.
this is correct :
( I set interval to 20, no need for declarations ....)
int SW; int exSW = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup() {Serial.begin(9600); pinMode(A4, INPUT_PULLUP); }
void loop() { SW = 1 - digitalRead(A4); currentMillis = millis();
if (currentMillis - previousMillis >= 20 and SW != exSW) {previousMillis = currentMillis;
Serial.print("pedal "); Serial.println(SW); exSW = SW;}
}
I don't know what else is running in your loop,
maybe safer woud be to place pedal into function :
int SW; int exSW = 0;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup(){Serial.begin(9600); pinMode(A4, INPUT_PULLUP);}
void loop(){ pedal(); }
void pedal(){SW = 1 - digitalRead(A4); currentMillis = millis();
if (currentMillis - previousMillis >= 20 and SW != exSW) {previousMillis = currentMillis;
Serial.print("pedal "); Serial.println(SW); exSW = SW;}}