Alright, here is what I am looking for.
A mobile automata carries an Arduino board #1 with an Xbee module and a PCB with an embedded Atmega. The Atmega drives the motors and controls different sensors, among them an ultrasonic transmitter which is turned on when the Arduino #1 receives an 'A' and off when it is a 'B' .
if (Serial.available()) {
valUS = Serial.read();
if (valUS == 'A') {
digitalWrite(outputPin, HIGH);
}
if (valUS == 'B') {
digitalWrite(outputPin, LOW);
}
}
Connected to the PC there is another Arduino board (#2) also with an Xbee, it computes from the ultrasonic receiver signals the time-of-flight th1, i.e., it trigers the US transmitter with an 'A' and then computes the time before receiving an US pulse with a while():
Serial.print('A');
t = micros();
while (val1 == LOW){
val1 = digitalRead(inUS1);
th1 = micros() - t;
}
Serial.print(th1);
Serial.print(10, BYTE);
Serial.print('B');
Serial.print(10, BYTE);
This works fine.
Now, I would like the mobile to be able to send a signal to the PC when it encounters an obstacle. So, I would like to add on the Arduino #1 something like this:
valMoteur1 = digitalRead(inPin9);
if(valMoteur1 == HIGH) {
Serial.print('H');
}else if(valMoteur1 == LOW){
Serial.print('I');
}
and the Arduino #2 will receive these 'H' and 'L' and use them to pass 1 and -1 to the PC:
if (Serial.available()) {
valRF = Serial.read();
if (valRF == 'H') {
Serial.println('E');
Serial.print(1);
Serial.print(10, BYTE);
}
if (valRF == 'L') {
Serial.println('E');
Serial.print(-1);
Serial.print(10, BYTE);
}
Unfortunately this doesn't work!
As I said in my previous posts I am unable to get both Arduinos to send and receive serial data.