Forums > MaxMSP

Arduino > Max Serial read problems


Apr 25 2014 | 12:05 am

Hi folks, I’ve recently come back to Max after a lengthy break and I’m trying to collect data from a light sensor as a simple stream of values in Max.

I achieved this a couple of years ago, but currently I’m having issues with Max reading the Serial object. Everything is fine in the Arduino Serial Monitor, it’s just not making it’s way across to Max.

Any thoughts or suggestions would be hugely appreciated! :)

Here’s the Max patch (with the itoa sub patcher pasted into the main patcher for reference)


-- Pasted Max Patch, click to expand. --

And here’s the Arduino code:

int lightLevel;

void setup()
{
Serial.begin(38400);
}

void loop()
{
lightLevel = analogRead(A0);
Serial.println(lightLevel, DEC);
delay(200);

}

Apr 25 2014 | 12:40 am

Hi
assuming you have the latest version of the Arduino IDE, and have selected the correct serial-usb port (dev/tty . . ., or COM3 e.g.), then all you should need is this:


Serial.write(lightLevel);

If you’re using an older board and IDE, then


Serial.print(lightLevel, BYTE);

does exactly the same. Then in Max just bang the serial object (serial a 38400; serial b 38400, or whatever) for the data.

HTH
Brendan

Apr 25 2014 | 12:56 am

Thanks for your reply. The IDE is up to date and the board is pretty new. Where exactly should the additional arduino code go – after Serial.println?

Apr 25 2014 | 1:02 am

Additionally, it’s going through port /dev/tty.usbmodem1421 and in Max it’s set up as serial a 38400 (I can’t see the reasoning in defining it as ‘b’) Cheers, TLR

Apr 25 2014 | 1:07 am

Replace println with write and you don’t need the ‘convert’ subpatcher on the other end:

int lightLevel;

void setup()
{
Serial.begin(38400);
}

void loop()
{
lightLevel = analogRead(A0);;
Serial.write(lightLevel);
delay(200);

}

Max patch:


-- Pasted Max Patch, click to expand. --

  • This reply was modified 2 years by  Medd.
Apr 25 2014 | 1:15 am

Thanks, Medd! Worked a treat! :D Thanks also, N00b, for the initial help :)

Apr 25 2014 | 3:10 am

Thanks for filling in the blanks medd – I was in a hurry, hence my concision

Viewing 7 posts - 1 through 7 (of 7 total)

Forums > MaxMSP