Hi,
I have a project, where I connect one (sending) Arduino Mega to the computer, with Xbee, and another Arduino Mega with Xbee to receive Data.
the project requires sending a letter from the computer using the Serial Monitor (USB cable) to the first Arduino, then the Arduino will send this info to the second one using the Xbee.
I tried to do that by putting this code to the first Arduino
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
And this is the part where the second Arduino receive the data,
void performCommand() {
if (Serial1.available()) {
val = Serial1.read();
}
if (val == 'f') { // Forward
go_forward();
} else if (val == 'z') { // Stop Forward
stop_go_forward();
} else if (val == 'b') { // Backward
go_reverse();
} else if (val == 'y') { // Stop Backward
stop_go_reverse();
} else if (val == 't') { // Turbo
go_turbo();
} else if (val == 'x') { // Stop Turbo
stop_go_turbo();
} else if (val == 'l') { // Right
go_right();
} else if (val == 'r') { // Left
go_left();
} else if (val == 'v') { // Stop Turn
stop_turn();
} else if (val == 's') { // Stop
stop_car();
} else if (val == 'a') { // Short Lights
lights_on();
} else if (val == 'c') { // Stop Short Lights
lights_off();
} else if (val == 'd') { // Long Lights
long_lights_on();
} else if (val == 'e') { // Stop Long Lights
long_lights_off();
}
}
void loop() {
performCommand();
}
This Does NOT work, everytime I try, my computer crashes. Any ideas??
Thanks a lot,