Whats going on peeps, I have two arduinos connected together via an xbee link. Both of these arduinos are able to send and receive data.
My problem is that, when i pass data over the serial link some commands are miss.
How can i avoid this?
Thanks:
Arduino 1 code:
const int RECled = 11; // the pin that the LED is attached to
const int SENDled = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(RECled, OUTPUT);
pinMode(SENDled, OUTPUT);
}
void loop() {
Serial.print('G');
digitalWrite(SENDled, HIGH);
delay(1000);
digitalWrite(SENDled, LOW);
delay(1000);
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(RECled, HIGH);
delay(1000);
digitalWrite(RECled, LOW);
}
}
}
Arduino 2 code:
const int RECled = 11; // the pin that the LED is attached to
const int SENDled = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(RECled, OUTPUT);
pinMode(SENDled, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'G') {
digitalWrite(RECled, HIGH);
delay(1000);
digitalWrite(RECled, LOW);
}
}
Serial.print('H');
digitalWrite(SENDled, HIGH);
delay(1000);
digitalWrite(SENDled, LOW);
delay(1000);
}