Forums > MaxMSP

Handling multiple variables over serial from Max/MSP to Arduino

Feb 23 2012 | 7:09 pm


I’m a third year at university in the UK working on a project which is essentially (for the time being) controlling a 4×4 Matrix of LEDs that have been multiplexed through programming using Arduino, via Max/MSP. Without Max/MSP, I’m able to program the Matrix as I like, chosing which LEDs are on, and which are off. However I’m having very little luck using Max/MSP to control it.

My Max/MSP patch uses switches to represent a binary value (ie. 1010 = On/Off/On/Off) for each row of the matrix, converts the binary value to an integer, and adds an identifier (0-3) before sending through serial to Arduino.

Max/MSP Code:

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

The code below attempts to gather 2 bytes of data from the serial buffer, and put each byte into an array. Depending on what the first byte is (0,1,2,3) depends on what row of the LED matrix the second value of the buffer is assigned to.

if (Serial.available() > 1){ //if 2 bytes available in the Serial buffer…

for (int i=0; i

Feb 24 2012 | 9:57 am

The problem may be that the stream is not synced, i.e. bufferArray[0] doesn’t contain the identifier but the data, and bufferArray[1] the identifier (you can check this sending back the datas to Max over serial).

Instead of using 0, 1, 2 & 3 to identify your rows, i would use values which are different from the 4 bits you want to send. I generally tag my datas with ‘A’, ‘B’, ‘C’, etc. ‘A’ is ASCII 65, so greater than the biggest value you can get with the 4 bits you send.

Then I’d wait for an incoming value >= ‘A’, then read the next incoming value (which is the binary data representing the state of your LEDs).

BTW, a metro 1 is generally a bad idea, it’s too fast.

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

Forums > MaxMSP