Gettng two independent arduinos to communicate with max through serial

Apr 17, 2013 at 6:47pm

Gettng two independent arduinos to communicate with max through serial

Hi I’m currently working on a project which consists of a digital theremin that works with two motion sensors one controlling pitch and one controlling volume. Basically I am using two arduinos one for each sensor and am trying to make them communicate with max using serial ports. I have managed to get them working separately but not when I plug them in together. When I plug them in together only one communicates with max. I think it must be a problem with how I’m using the serial ports but I’ve been investigating for ages and haven’t found a solution. Any help would be much appreciated. Thanks in advance.

Ian

Here is the max patch I’m currently using:

– Pasted Max Patch, click to expand. –

And this is the code used for programming the different arduinos:

-Arduino1:
#define echoPin 4 // 4 pin, connect to echo
#define trigPin 5 // 5 pin, connect to trig

void setup() {
Serial.begin(9600);
pinMode(echoPin, INPUT); // define 4 pin to in
pinMode(trigPin, OUTPUT); // define 5 pin to out
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin,HIGH);
long distancia = duration /29 / 2 ;

Serial.println(distancia);

}

-Arduino2:
#define echoPin 6 // 6 pin, connect to echo
#define trigPin 7 // 7 pin, connect to trig

void setup() {
Serial.begin(9700);
pinMode(echoPin, INPUT); // define 6 pin to in
pinMode(trigPin, OUTPUT); // define 7 pin to out
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long length = pulseIn(echoPin,HIGH);
long distance = length /29 / 2 ;

Serial.println(distance);

}

#67779

You must be logged in to reply to this topic.