I've written a small routine that should wait for a signal over serial before the program begins. It goes like:
boolean connectionEstablished = false;
byte connectByte=0;
void establishContact() {
while (!connectionEstablished){
if (Serial.available()>0){
connectByte = Serial.read();
if (connectByte=='X'){
Serial.println("Connection accepted");
connectionEstablished=true;
}else{
Serial.println("Invalid connection attempt:");
Serial.println(connectByte,DEC);
}
}else{
Serial.println("waiting for start signal");
}
delay(200);
}
}
Basically the program should wait for the character 'X' before leaving that while loop. This is a simple extension of the SerialCallResponse example.
The problem is that both this and that example exit the while loop if nothing is connected. I am using the bluetooth arduino. If I initiate a connection to the modem over bluetooth before the program starts then it waits in the loop as expected. If I don't have something connected then somehow the loop terminates. It is mind boggling!
If anyone has any ideas of what is happening here I'd love to hear them!
Regards,
Kallin Nagelberg.