Arduino Mega to send data to Max/Msp
Hello I am having problems getting the Arduino Mega to send the data from the analogue and the digital ports back into Max/msp. I have it working for the Arduino UNO
Hi
What's the reason for moving from Uno to Mega?
This might depend on several things, you should perhaps be a little more specific.
Brendan
Hello I am trying to make a laser harp that triggers samples in a max patch, I have it working on the Uno with the 6 analogue ports. The reason for using the Mega over the Uno is it has the number of analogue ports that I require as I want it to be able to use 12 individual analogue sends for each photo-sensor so I can create a octave with individual note control/triggering.
Ok, so I'm suspecting Maxuino? Or did you write your own code in Arduino?
just tried to adapt the Arduino2max code and patch
I'd need to see the code snippet that is doing the sending to Max. Have you updated or changed the sketch to take account of the input numbering system? Newer IDEs use A0, A1 etc for analogue inputs, although AFAIK this shouldn't really make a difference; and the newer IDE also involves different behaviour between Serial.print and Serial.write.
Brendan
. . . in the meantime, similar issues have been raised or addressed here:
Thanks, i'll take a look, this is the Arduino code
int x = 0; // a place to hold pin values
int ledpin = 13;
void setup()
{
Serial.begin(9600); // 115200 is the default Arduino Bluetooth speed
digitalWrite(13,HIGH); ///startup blink
delay(5);
digitalWrite(13,LOW);
pinMode(13,INPUT);
}
void loop()
{
if (Serial.available() > 0){ // Check serial buffer for characters
if (Serial.read() == 'r') { // If an 'r' is received then read the pins
for (int pin= 0; pin
{
x = analogRead(pin);
sendValue (x);
}
\
for (int pin= 2; pin
{
x = digitalRead(pin);
sendValue (x);
}
Serial.println(); // Send a carriage returnt to mark end of pin data.
delay (5); // add a delay to prevent crashing/overloading of the serial port
}
}
}
void sendValue (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.write(32);
}
Several things:
1. not much point in declaring the LED pin if you are never going to refer to it by its variable name.
2. if pin 13 is in LED, then don't declare it as an input. But later you are using it as both an analog and digital input, so something isn't right there.
3. pins 0 - 15 are not capable of analog input in the mega. Plus they are never declared as input pins in your set-up. The first analog pin is actually pin 54 on the mega, btw. As was mentioned above, you can use A0, A1, etc. instead.
4. I'm assuming in your second for loop you are actually wanting to read pins 2-53. Declare the pins as input in your set-up.
That's a start at least.
HTH,
David