no data from Arduino
I followed the Serial Communication tutorial of Max's documentation to communicate with an Arduino board. The Arduino board is programmed with the example code of the Max-tutorial. When I run the Max-patch, the Arduino-board is activated and starts sending data (as indicated by a blinking light on the Arduino-board), but no data appear in the Max patch or console. (While I'm using the Max patch, the Arduino IDE is not running.)
When I check the serial monitor of the Arduino IDE, the output is as should be: numbers appear as programmed and initiated by the Max patch signal.
I tried with two different Arduino boards (UNO R4 and Leonardo), and on a Max and a Windows system. Strangely, at some point Max did start to show data received from the Arduino board. But when I tested a bit later, again it didn't. Some months ago this all worked fine. Any suggestions as to why it is not working anymore?
Max version 8. Tested on a Macbook Pro M3 (Sequoia), and a PC (Windows 10).
can you provide your Arduino code and the Max patch you are using? Quite impossible to give any advice without the details. There are too many possible issues.
Hi Jan,
thank you for your reaction. Here they are:
Arduino code (directly taken from the Max-Tutorial):
// Arduino Serial Tester
// rld, cycling'74, 3.2008
long randomvalue = 0; // random value
long countervalue = 0; // counter value
int serialvalue; // value for serial input
int started = 0; // flag for whether we've received serial yet
void setup()
{
Serial.begin(9600); // open the arduino serial port
}
void loop()
{
if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
started = 1; // set the started flag to on
}
if(started) // loop once serial data has been received
{
randomvalue = random(1000); // pick a new random number
Serial.print(countervalue); // print the counter
Serial.print(" "); // print a space
Serial.print(randomvalue); // print the random value
Serial.print(" "); // print a space
Serial.print(serialvalue); // echo the received serial value
Serial.println(); // print a line-feed
countervalue = (countervalue+1)%1000; // increment the counter
delay(100); // pause
}
}
Max-patch (serial port d should be the right port), also taken from tutorial:
Hello Arne,
I don't see anything unusual in your code or patch. I assume that you have checked that the port "d" is the correct port on your system.
Currently the only thing I can think of is playing around with with the following settings of the serial object:
DTR (data terminal ready): setting it to off - would be my guess for an Arduino.
Xon (Data Flow control): try to explicitly setting it to off.
RTS (Request to send): try setting it explicitly to off.
It's been a while that I used an Arduino for serial communication. Mostly I use Raspberry Picos. I remember that one time in the past the serial connection with the Pico became unreliable on MacOS. I changed something with the above mentioned attributes and it became reliable again. I believe it was DTR, Xon and RTS to off (and freezing the attributes). But I am not sure if I remember right.
Hi Jan,
all settings you mentioned were turned off in my patch. But when I turned on DTR, data from the Arduino-board were detected. Seems to work well.
Thank you for your advice. It made my day! Cheers,
Arne
Happy to hear! Serial connections are at the same time incredibly simple (in theory) and incredibly complex (in praxis) :)