Hi! For my project, I have two Arduinos connected to 1 computer (which is running processing) via two serial ports.
In my setup there are 4 potentiometers and 4 LEDs connected to each Arduino and my goal is to get the potentiometers on one Arduino to fade in and out the LEDs on the other Arduino, as simultaneously as possible.
I've actually gotten the communication to work using the processing-arduino library here:
http://www.arduino.cc/playground/Interfacing/Processingand the Processing code here:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino1, arduino2;
int ledPin1 = 3;
int ledPin2 = 6;
int ledPin3 = 10;
int ledPin4 = 11;
int bright;
void setup()
{
//println(Arduino.list());
arduino1 = new Arduino(this, Arduino.list()[1], 57600);
arduino2 = new Arduino(this, Arduino.list()[2],57600);
arduino1.pinMode(ledPin1, Arduino.OUTPUT);
arduino1.pinMode(ledPin2, Arduino.OUTPUT);
arduino1.pinMode(ledPin3, Arduino.OUTPUT);
arduino1.pinMode(ledPin4, Arduino.OUTPUT);
arduino2.pinMode(ledPin1, Arduino.OUTPUT);
arduino2.pinMode(ledPin2, Arduino.OUTPUT);
arduino2.pinMode(ledPin3, Arduino.OUTPUT);
arduino2.pinMode(ledPin4, Arduino.OUTPUT);
}
void draw()
{
bright = arduino2.analogRead(0)/4;
arduino1.analogWrite(ledPin1, bright);
bright = arduino2.analogRead(1)/4;
arduino1.analogWrite(ledPin2, bright);
bright = arduino2.analogRead(2)/4;
arduino1.analogWrite(ledPin3, bright);
bright = arduino2.analogRead(3)/4;
arduino1.analogWrite(ledPin4, bright);
bright = arduino1.analogRead(0)/4;
arduino2.analogWrite(ledPin1, bright);
bright = arduino1.analogRead(1)/4;
arduino2.analogWrite(ledPin2, bright);
bright = arduino1.analogRead(2)/4;
arduino2.analogWrite(ledPin3, bright);
bright = arduino1.analogRead(3)/4;
arduino2.analogWrite(ledPin4, bright);
}
Then I just loaded onto each Arduino the Standard Firmata code given in the Arduino examples.
My problem is that while the communication works perfect, the connection is extremely extremely slow. When I try to fade LEDs, the update speed is so slow that the LEDs pretty much blink from super dim to super bright!
As a result, I'm trying to program the Arduinos and Processing separately using the "handshake" method given in the communication example "SerialCallResponse." While I can get this method to work for talking between one Arduino and processing, I'm completely lost as to how to connect two Arduinos.
For example, in the Processing code, there is a setup
void serialEvent(Serial myPort)
I can only call this once and it specifies only one serial port (that I know of!) so how would I get it to talk to two serial ports?
Is there another way to get the Arduinos to communicate faster while still keeping the communication happily synced?
Thanks so much for any advice!