Max/MSP & Arduino

    Sep 02 2009 | 4:45 pm
    I have been struggling to get the max serial object to read any data from the analog inputs on the Arduino board for weeks now and can see from previous discussions that I am not alone in this. I have tried every solution suggested on both the Arduino forum and also the Max forum to no avail.
    I have now got Max talking to Arduino using Maxuino and standard Firmata however there are two things which don't seem to be functioning as I would anticipate.
    The patch I am using is from a tutorial found here:
    I have the Arduino Mega also - but this is not working with the patch beyond analog input 5 despite extending the patch to account for the additional inputs - so I am back to Duemilanove with fewer inputs.
    The inputs need to be ready to receive the data from all analog inputs and these are enabled by toggles in the patch, however when for example I have a sensor in analog input 0 the numbers are fed to the number box for that analog input with the aim of triggering other things in a separate subpatch. The problem is that if all 6 inputs are enabled and I insert for example a sensor into analog input 0 the data is fed to all the analog inputs which are enabled, and then when the second sensor for example in input 1 is triggered it will do the same overwriting the data sent from input 0 as it sends to all the inputs , and so on for all the sensors , which is not what I want.
    I am trying to think of a solution such as a gate or switch or something which will resolve this and ensure that data from analog input 0 is fed to the right output and not to all the others as well. If I was using just one sensor i could have the other outputs static ie not routed to anything else in the patch but they should all have inputs routed to their corresponding subpatches which will be triggered by different sensors.
    Also .. can anybody who is using Arduino and Max please clarify the actual process when uploading to the board and then using Max. ie are you supposed to upload to Arduino, select the correct serial baud rate, then press send to the right of the page. Are you then supposed to close Arduino Firmata down and then open Max as when using Arduino in stand alone or with Processing I am not sure whether you are supposed to do this or if in fact it makes a difference.
    Any suggestions on this would be great.
    Thank you very much in advance.

    • Sep 25 2009 | 10:16 pm
      I was just now struggling to get input in Max with a Duemilanove and Maxuino-005. It turned out that there was a bug in the Arduino 017 included Firmata v2.1. I couldn't get any of the inputs to work properly. Not in Max nor Processing.
      I removed the Firmata folder from the Arduino distribution (on OSX its located in app contents/resources/hardware or something.) copied the updated Firmata folder from the SVN there and uploaded the new standard Firmata to the board.
      It's important that you close Arduino before starting another application which uses the serial port (like Max or Processing). I didn't have to configure the baud rate anywhere. I think it's hardcoded in Firmata.
      Maxuino-005 seems to work well now.
      Hope this helps.
    • Sep 28 2009 | 8:45 am
      I have just spent the last week working with a nano and a mega with max/msp.
      I lately discovered that the arduino mega wasn't compatible with the standard firmata (for now) so I spent some time programming with the arduino software.
      The API is simple and well documentented with lots of examples. In my opinion, what's missing is a simple explanation on a how to connect each type of components (at least the most common ones : knobs, switches...), because lots of mistakes are on this side when you're not an expert in elecronics.
      I would now encourage anyone to write their own firmware and use it with the serial object in max/msp.
    • Sep 29 2009 | 9:46 pm
      Yes it's seems straightforward, and I think I actually need it since I'm using shift registers for input and output.
      In Arduino everything is working properly, but once I get to Max I have this stupid problem where it stops working completely. For example with the following simple code in Arduino:
      int incomingByte = 0; // for incoming serial data
      void setup() { Serial.begin(9600); // open the arduino serial port }
      void loop() { int buf = Serial.available();
      if(buf == 0){ // nothing is happening Serial.print(0); delay(1000); } else{ // we got input, echo it to output
      while(buf > 0) // all of it { incomingByte =; Serial.println(incomingByte); --buf; } } }
      This makes the board output everything you put in, and if you don't do anything it sends me a 0 every second. When I check the Arduino serial monitor everything is looking good, and I see the TX led light up every second on idle.
      Now, when I close Arduino and start Max, it seems that the thing stops working as soon as a Max [serial] object is instantiated. I never get any communication with Max working even though the baud rate and port are set correctly.
      Any idea what might be wrong?
    • Sep 29 2009 | 10:42 pm
      I lost a few hours on something like this myself.
      Don't forget to bang the serial object every X ms in order to read what's received.
      Hope this helps.
    • Sep 29 2009 | 10:57 pm
      I did bang it, but really nothing comes out. I've tried the patches from the serial Max tutorial but can't get it to work either.
      I find it very strange that the TX light stops flashing the moment I instantiate the [serial] object. If the hardware is not indicating that it's sending something I don't have high hopes of receiving anything on the Max side.
      If I send something from Max the RX led lights up, but it doesn't seem to trigger anything, even if I'm just using it to change the digital output pins.
      To me it looks like the Arduino chip is being reset somehow. Is this possible?
    • Sep 29 2009 | 11:30 pm
      after making the connection to max, try hitting the reset button on the arduino. I know it's not ideal, but it use to have to do this all the time with older arduinos.
    • Sep 30 2009 | 6:11 am
      I tried your code on my diecimila w ATMmega168 with the following patch and it works.
      By the way, I imagine this code is just a kind of test case but while your delaying your loop method during 1000ms, it becomes less reactiv. The best would be to do nothing, when nothing is received.
      Hope this helps.
    • Sep 30 2009 | 7:09 am
      Hitting reset solved the problem. Thanks!.
      I thought the reset button would also reset the program, but apparently not. It works now. I'm using a Duemilanove with OSX.
      I looked into this reset thing and found this:
      Quote:When the Duemilanove is connected to either a computer running Mac OS X or Linux, it resets each time a connection is made to it from software (via USB). For the following half-second or so, the bootloader is running on the Duemilanove. While it is programmed to ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first few bytes of data sent to the board after a connection is opened. If a sketch running on the board receives one-time configuration or other data when it first starts, make sure that the software with which it communicates waits a second after opening the connection and before sending this data.
      The Duemilanove contains a trace that can be cut to disable the auto-reset. The pads on either side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum thread for details.
      The reset button won't be accessible to the user, so I guess it's easiest to cut the auto-reset trace on the board.
    • Oct 05 2009 | 10:23 pm
      The StandardFirmata in 0017 turned out to be kind of buggy, unfortunately. We have things mostly fixed in SVN, but would love to have more testing and bug reports! So here's a new release. I fixed all bugs that I knew about, including the one where analog pins sometimes acted like they had a log curve on them.
      I tested this on a Diecimila, I hear there are troubles with the Arduino Pro and others, but I only have the older ones, so testing and bug reports on those are very helpful. The maxuino version should work with Firmata 2.1 as long as the baud/bitrate is set to 57600.
    • Oct 05 2009 | 10:28 pm
      Hi hans,
      thanks for the update, I'll try as soon as possible and let you know.