Hi all,
I'm new to Arduino. Recently, I was playing around with serial communication between 2 Arduino Uno. Basically, I have 2 arduino Unos, each rigged with a multicolor LED and initially setup to flash a different color. The idea is that if the 2 arduino boards are connected through the pins designated by the software serial port, their colors would sync. The strange thing is that the code seems to work prefectly fine when I attached (powered) the 2 boards via USB cable, but when I switch both (or either) over to v9 batteries, they do not seem to communicate any more (Each arduino just flashes their own color). Anybody got an idea why this is so? Thanks!
Here's the code snippet:
...
SoftwareSerial neighbor(2,3);
int my_color = 0;
void setup() {
my_color = 0; // uploaded to arduino board 1
// my_color = 5; // uploaded to arduino board 2
// Serial.begin(9600);
neighbor.begin(4800);
}
void loop() {
if (neighbor.available()) {
int received_color = neighbor.read();
int new_color = (my_color + received_color) / 2;
// Serial.print("Received color suggestion: ");
// Serial.print(received_color);
// Serial.print("\n");
set_color(new_color);
neighbor.write(my_color);
} else {
// Serial.print("No suggest from neighbor, using my own color: ");
// Serial.print(my_color);
// Serial.print("\n");
set_color(my_color);
}
delay(500);
}
void set_color(int color_value) {
...
// Uninteresting bits... just tell LED to change color
}