Arduino Uno + Max


    Jul 02 2011 | 2:30 am
    I just bought an Arduino Uno + Inventors Kit from Sparkfun, and now after building the introductory circuits I am curious as to how one would (if possible) go about changing parameters within the Arduino Code from MaxMSP. Forgive me, for I am just starting with this stuff. Any help/advice will be much appreciated!
    -etk

    • Jul 02 2011 | 1:17 pm
      i have attached the world's simplest example of serial communication from max/msp to arduino. a toggle will set digital pin 13 high/low to turn on/off the on-board led (or whatever you have connected to digital pin 13).
      and the arduino code:
      /* simple arduino sketch to turn the on-board led on and off from max/msp
      http://cycling74.com/forums/topic.php?id=34141
      */
      
      # define LED 13             // the on-board LED
      int maxData = 0;            // byte sent from max
      
      void setup()
        {
          Serial.begin(9600);     // init the serial port
          pinMode(LED, OUTPUT);   // make pin 13 an output
        }
      
      void loop()
        {
          while(Serial.available() > 0) {
            maxData = Serial.read();
          }
          if(maxData == 1)digitalWrite(LED, HIGH);   // turn led on
          if(maxData == 0)digitalWrite(LED, LOW);    // turn led off
        }
      
      // eof
      the ladyada serial tutorials are very easy to understand and non-patronizing.
    • Jul 02 2011 | 10:52 pm
      Hey, thank you very much--I got that up and running with no problems. Now the sky's the limit!
      -etk-
    • Jul 02 2011 | 11:37 pm
      Quick question: I've expanded and coded a Max patch that controls 8 LEDs. But, I'm running into an issue--my LED's are only barely lighting up, except the last one (pin 9). I checked my circuit, and tried swapping out a few, and that doesn't appear to be the issue. Would you/any others mind looking over my patch/code an see if its an error on my part? I am new to this, so I may be overlooking something rather simple...
      Max Patch:
      Arduino Code:
      //8_LED_MaxMSP//
      int maxData = 0;
      void setup()
      {
      Serial.begin(9600);
      pinMode((2,3,4,5,6,7,8,9), OUTPUT);
      }
      void loop()
      {
      while(Serial.available() > 0) {
      maxData = Serial.read();
      }
      if(maxData == 1)digitalWrite(2, HIGH); // turn led on
      if(maxData == 0)digitalWrite(2, LOW); // turn led off
      if(maxData == 3)digitalWrite(3, HIGH); // turn led on
      if(maxData == 2)digitalWrite(3, LOW); // turn led off
      if(maxData == 5)digitalWrite(4, HIGH); // turn led on
      if(maxData == 4)digitalWrite(4, LOW); // turn led off
      if(maxData == 7)digitalWrite(5, HIGH); // turn led on
      if(maxData == 6)digitalWrite(5, LOW); // turn led off
      if(maxData == 9)digitalWrite(6, HIGH); // turn led on
      if(maxData == 8)digitalWrite(6, LOW); // turn led off
      if(maxData == 11)digitalWrite(7, HIGH); // turn led on
      if(maxData == 10)digitalWrite(7, LOW); // turn led off
      if(maxData == 13)digitalWrite(8, HIGH); // turn led on
      if(maxData == 12)digitalWrite(8, LOW); // turn led off
      if(maxData == 15)digitalWrite(9, HIGH); // turn led on
      if(maxData == 14)digitalWrite(9, LOW); // turn led off
      }
      //end
    • Jul 03 2011 | 12:42 am
      How do you have the LEDs wired up? if you're seeing something physically weird, my guess would be the circuit.
    • Jul 03 2011 | 1:48 am
      I am using this exact schematic:
    • Jul 03 2011 | 2:40 am
      I find the following piece of code:
      pinMode((2,3,4,5,6,7,8,9), OUTPUT);
      to be suspect. Have you tried separating it out into eight statements:
      pinMode(2, OUTPUT);
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);
      pinMode(5, OUTPUT);
      pinMode(6, OUTPUT);
      pinMode(7, OUTPUT);
      pinMode(8, OUTPUT);
      pinMode(9, OUTPUT);
      One of the reasons that the lights are dim might be that the statement only recognizes the last entry (9), and therefore the pulldown resistors are not disabled on the other pins.
      Just something to try...
      [ddg]
    • Jul 03 2011 | 3:55 am
      That was the problem! From now on I'll know not to group such statements like I had.. Thanks, Darwin!
    • Jul 03 2011 | 4:49 am
      checkout this on getting osc working with the arduino too.
      you just run a patch in processing to handle communication.
    • Jul 03 2011 | 8:44 am
      regarding the link above: cool idea and, people have been using that method for a while but it seems messy (max talks to processing applet via osc then processing relays to a firmata-loaded arduino via serial). if firmata is already on the chip, might as well just use maxuino and i'm sure there would be less latency too. then theres always udp over ethernet... or direct serial. its not like we are limited to just 1 byte.
    • Jul 03 2011 | 9:36 am
      i find the processing way clearer and easier to use.