Serial data to Arduino

moris526's icon

Hi.

Im trying to control a led grid from Max via Arduino.

I can do it from the Serial window in Arduino IDE, but im doing something wrong when I try it from Max.

I use strtok in Arduino to parse the string of data. But since I can do it from the Serial on the IDE, the code seems to be OK.

Lets say I type <A, 1, 25, 25, 25>

I run the message throu the atoi object before sending it to serial port.....

Any idea.....?

Source Audio's icon

You probably know that comma separated items in a message in Max
get sent itered, one after one, and not as a list.
And maybe you need to send or new line feed at the end ?

Can't say more , not knowing the arduino serial receiver part
that you use.
I usually get data in a bit different way, I assume A is sort of ID
and 4 ints are led number and 3 RGB values.

Example with neopixel lib could look something like this:

void loop() {if (Serial.available() > 0 ) {
inByte = Serial.read();
if (inByte == 'A') {
int led = Serial.parseInt();
int red = Serial.parseInt();
int green = Serial.parseInt();
int blue = Serial.parseInt();
if (Serial.read() == '\n')
{strip.setPixelColor(led, red, green, blue); strip.show();}
}
}

moris526's icon

Thank you Man.

That was exactly it.

In the parse part of the IDE the strtok separeted items with coma. I replace it with a Space, and that was it.

Have a Nice week!!