Arduino Uno + Max

Jul 2, 2011 at 2:30am

Arduino Uno + Max

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

#57851
Jul 2, 2011 at 1:17pm

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).

– Pasted Max Patch, click to expand. –

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.

#207539
Jul 2, 2011 at 10:52pm

Hey, thank you very much–I got that up and running with no problems. Now the sky’s the limit!

-etk-

#207540
Jul 2, 2011 at 11:37pm

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:

– Pasted Max Patch, click to expand. –

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

#207541
Jul 3, 2011 at 12:42am

How do you have the LEDs wired up? if you’re seeing something physically weird, my guess would be the circuit.

#207542
Jul 3, 2011 at 1:48am

I am using this exact schematic:

http://oomlout.com/a/products/ardx/circ-02/

#207543
Jul 3, 2011 at 2:40am

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]

#207544
Jul 3, 2011 at 3:55am

That was the problem! From now on I’ll know not to group such statements like I had.. Thanks, Darwin!

#207545
Jul 3, 2011 at 4:49am

checkout this on getting osc working with the arduino too.

http://liamtmlacey.blogspot.com/2011/03/arduino-to-maxmsp-via-osc-guide-and.html

you just run a patch in processing to handle communication.

#207546
Jul 3, 2011 at 8:44am

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.

#207547
Jul 3, 2011 at 9:36am

i find the processing way clearer and easier to use.

#207548

You must be logged in to reply to this topic.