I have a robot with a XBee module (ROUTER) and a bunch of sensors. Another Xbee module (COORDINATOR) is connected via USB to the PC. They work in AT mode, broadcasting.
I would like to send the readings of the sensors from ROUTER to COORDINATOR in a loop, but still being able to interrupt it by sending (manually) some byte from the COORDINATOR to the ROUTER, and then again continue on receiving the sensors' readings. I get the sensors' readings sent and received, but I cannot get the ROUTER to receive the byte sent from the COORDINATOR.
I would appreciate your help.
Here is my code:
int sensorValue = 0;
void setup() {
Serial.begin(9600);
int readSensorValue();
}
void loop() {
if ( Serial.available() ) {
if ( Serial.read() == 'R' ) { // "R" is the byte addressing the robot
Serial.println("Byte received");
}
}
sensorValue = readSensorValue();
Serial.println(sensorValue );
}
int readSensorValue(){
// this function returns the sensor reading
}