arduino to arduino missing serial commands

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);
}

Why not add flashing a different LED to see if something besides G or H is received?

Also, while the
delay(1000);
is going on, the uC is kinda locked up.
Consider changing that to use millis() to capture the time you turned it on, then capture millis() everytime thru your loop and see if its time to turn it off: i.e., "blink without delay".

@jstone2ke,
Why did you lock this topic?

Sorry, must have clicked it by accident. Thanks for the heads up! :sweat_smile: