SOLVED:Arduino/MaxMSP/26 analog p via multiplexing


I have a big problem getting data via serial port from Arduino Diecimila to MaxMSP 5. When I send 17 integers via serial port it works no problem, but when I increase the output to 26 ints max gets bad data (I can see that sometimes it unpacs it correctly but most of the time is more or less random).

26 ints are comming from 3 4051 multiplexers connected to 3 analog ports on Arduino (24 in total) and 2 more analog inputs. (I know that Arduino uses multiplexing to switch between its analog inputs, etc)

Looking at the output via SerialMonitor on Arduino SDE all the numbers (26) come as the correct ones. So I am sure that there are no problems with schematic or my code. I am quite sure that serial object in max gets somehow overloaded when all the data comes.

Has any of you experienced such thing? Any recomendations about how to solve this data overload problem?

Thanks in advance.

Seems that forum does not allow me to post links until I made another post.

Here are some images:

How are you sending data to the serial port on the Arduino?


I am sending via USB cable.

By the way, problem is solved. This is what happens when one does not look at the objects carefully. All the mess was caused by zl object. It flushed the list after 78 menbers were in. I changed the number count to 200 (just a random number, will figure out the correct one later) and all the problems dissapeared :slight_smile:

from max manual:

The zl object performs several kinds of list processing functions. You set the function with a keyword argument, and can change the function performed with the mode message. The behavior of the zl object's inlets and outlets and the types of messages they expect or process varies according to the mode of the zl object. For brevity in the discussion that follows, we refer to any Max message as a list including single elements such as int, symbol, and float and messages that begin with a symbol (a Max list is a message that begins with a number).

If I understand it correctly zl flushes list out on bang. And bang is received when 0 (type byte) comes into the stream. This is the last thing that Arduino sends at the identifying the end of data. So member count is actually not inportant...

How are you sending data to the serial port on the Arduino?

I am sending via USB cable.

Really? You're not sending the data telepathically? Not using Morse code over IR?

I meant what code are you using to send the data to the serial port.

Sorry, PaulS, I misunderstood your question.

this is the full source code:

//#define DEBUG_MODE

void setup(){

  pinMode(10, OUTPUT);    // s0
  pinMode(11, OUTPUT);    // s1
  pinMode(12, OUTPUT);    // s2
  //digitalWrite(led, HIGH); 

void printToSerial(int value)
  Serial.print(32, BYTE);  //space

unsigned long time;

void loop () 
  if (Serial.available() != -1)
    // Check serial buffer for characters
    if ( == 'r')
      time = micros();
      for (char i = 0; i <= 7; i++)
        PORTB = i << 2;
        delay(1); // just to make sure that there was enough time to write data to PORT


      // send a carriage returnt to mark end of pin data.

      // notify serial comm (or XMLSocket for Flash) that the comunication is over
      Serial.print(0, BYTE);