Handling multiple variables over serial from Max/MSP to Arduino

Feb 23, 2012 at 7:09pm

Handling multiple variables over serial from Max/MSP to Arduino

Hi,

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

#61941
Feb 24, 2012 at 9:57am

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.

#223702

You must be logged in to reply to this topic.