Xbee serial comms via Arduino

HI guys,

My objective is to have the seeduino out in the garden in report moisture and temp readings. The etherten with relay shield and xbee shield will receive this data and trigger the relay and turn on/off a water valve depending on the readings.

The I have the Seeduino transmitting “D” via serial BR 9600 every 5 seconds atm to test it. I can see the 2nd Xbee to associating with the Xbee on the Seeduino when it sends the “D” every 5 seconds.

Your right there is no loop in that code snippet. It wasn’t the full set of code. It would not compile with out that.

When you say that I’m using the hardware serial port == fail. What do you recommend to use?

I tried some really basic code:

Sender: (Seeeduino Stalker)

void setup()
{ 
  Serial.begin(9600); 
} 

void loop() { 
    Serial.print('D');  // send a capital D over the serial port every 5 seconds
    delay(5000); 

}

Receiver: (Etherten)

void setup() { 

   Serial.begin(9600);
   pinMode(5, OUTPUT);

}

void loop() {
 
  // look for a capital D over the serial port and turn on LED if found

if (Serial.available() > 0) { 
  if (Serial.read() == 'D'){ 
    digitalWrite(5, HIGH); //turn on LED to show it has received the data
    delay(2000); //wait for 2 seconds
   } 
 } 
 
      digitalWrite(5, LOW);
 }

I tried removing the if statement for checking the value and just turn on LED if anything was received and still not getting anything.

I tried using the SoftwareSerial library with this code:

Receiver:

#include <SoftwareSerial.h>

uint8_t pinRx = 0, pinTx = 1;
SoftwareSerial mySerial(pinRx, pinTx);

long BaudRate = 9600;

int led = 5;

void setup()
{
  pinMode(led, OUTPUT);
  
  Serial.begin(BaudRate);
  mySerial.begin(BaudRate);  
  mySerial.listen();
}

void loop()
{
  // transmit
  if (Serial.available())
  {
    digitalWrite(led, HIGH);
    char gotChar = Serial.read();
    Serial.print(gotChar);
    mySerial.print(gotChar);
    digitalWrite(led, HIGH);
    delay(2000);
    digitalWrite(led, LOW);
  }
  
  // receive
  if (mySerial.available())
  {
    char gotChar = mySerial.read();
    Serial.print(gotChar);
    digitalWrite(led, HIGH);
    delay(2000);
    digitalWrite(led, LOW);    
  }
}

I still didn’t receive anything.

I feel I’m missing something basic here because all the stuff I have read it should work. I can see via the Xbee status that they are associating and if I hook the Etherten xbee via USB to X-UTU it is receiving the “D”

Also if I hook up via USB and type in “D” the LED turns on so I know the code is right (logic wise).

http://www.youtube.com/watch?v=XnU6PUObBh4 - 2 x Xbees on arduino

http://www.youtube.com/watch?v=RpT7fxLGHEo xBee on Ardiuno with Xbee via USB to X-UTU