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
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
https://cycling74.com/forums/arduino-uno-max
*/
# 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.
Hey, thank you very much--I got that up and running with no problems. Now the sky's the limit!
-etk-
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
How do you have the LEDs wired up? if you're seeing something physically weird, my guess would be the circuit.
I am using this exact schematic:
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]
That was the problem! From now on I'll know not to group such statements like I had.. Thanks, Darwin!
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.
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.
i find the processing way clearer and easier to use.