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
}
When I comment those lines, I get the "Byte received" message. I believe I need to create an interrupt to read a received byte, but I am not sure how to do that. I would appreciate any help.
I tried with delay(100); already, didn't work. But I will try longer delay as well. I can't do it before Monday as I am away, but I will get back to you on this.
Thank you for your help, I really appreciate it.
I am sorry for the late reply. I resolved the issue by creating an external interrupt. I guess serial port could not handle the amount of data it was receiving.