How to read serial data from arduino in Max/MSP?

How can I read and 8-bit value sent using Serial.println() in Max/MSP? I have spent the last two hours on google trying to figure out how to do it and the best that I have achieved is some random numbers in the max window. I seem to be hopelssly lost when it comes to interfacing the arduino with max...

What I have right now is an arduino uno running a model train around a loop, accelerating and stopping at stations. What I want to do is get the speed value that I'm sending to the train into max, so that I can create a realistic sound for the motor that corresponds with the speed. All I need is to get that speed value correctly into max; how can I do that? I am sending the data every time it changes.

It would help if you posted the code you are running on the Arduino and the code in Max, then we might be able to spot where you are going wrong.

I assume you have read this:-
http://playground.arduino.cc/interfacing/MaxMSP

I have read through the playground page on Max, but a lot of it seems to be about controlling the arduino from max, rather than controlling max with the arduino. Either that or I am glazing over something. The basic guts of the code is like this inside loop():

currentTime = millis()

  // ****Acceleration**** 
  if (currentTime - lastAccelTime > accel) {
    lastAccelTime = currentTime;
    if (spd < val) {//checks if val (the target speed) is greater than spd (the actual speed)
      spd++;
      analogWrite(outPin, spd);
      Serial.println(spd); //this is the value I want to send to max
    }
  }
  
  // ****Coasting****
  if (currentTime - lastCoastTime > coast) {
    lastCoastTime = currentTime;
   
   //check to make sure nothing else is happening:
    if (but2s == HIGH) {
      //do nothing
    }
    else if (but3s == HIGH) {
      //do nothing
    }
    else if (timeout == 1) {
      //do nothing
    }
    else if (spd > 50) { //only coast if speed is slow
      //do nothing
    }
    else { //slowly decrease speed
      spd = spd * 0.98;
      analogWrite(outPin, spd);
      Serial.println(spd); //the value I want in Max
    }
  }

  // ****Braking**** 
  if (currentTime - lastBrakeTime > brake) {
    lastBrakeTime = currentTime;
    if (spd > val) { //checks that the target speed is less than the real speed
      spd = spd * 0.93;
      analogWrite(outPin, spd);
      Serial.println(spd); //the value I want in Max
    }
  }
}

Within Max, I currently have a toggle going to "metro 1" left input (I have tried changing the time, no luck), "metro"'s output to "Serial a 9600" input, and "Serial a 9600"'s left output to "print" object. All I want to get right now is a reliable signal printed within max.

Does nobody know how to do this? Or am I just an idiot who's missing something obvious? :roll_eyes:

You have to break your problem down.
That code does not look good. There is a whole lot of nothing going on.

You have to get something that just prints out at regular intervals to see if Max can pick it up. Once you are receiving prints in Max you then need to look to see if your code is actually printing something.
I other words the secret of debugging is to break it own into very small steps.