I'm trying to have a pair of Arduino yuns communicate with one another via Xbee, however my only experience with Arduinos as of now has been with the uno and I know that there is difference in coding when it comes to this. Can someone give me a hand with explaining what needs to be changed in order for this code to do as I want? The attach code is meant to preform a constant handshake between two yuns, and if a response is wrong or not heard within a set time frame then an email is sent to a targeted addressed.
I know that there is difference in coding when it comes to this.
A Yun has a Linux side, an Arduino side, and a bridge between them. The Arduino side is programmed the same as the Uno, as far as talking to the serial port - hardware or software.
Can someone give me a hand with explaining what needs to be changed in order for this code to do as I want?
Without knowing what it actually does, and how that differs from what you actually want? Probably not.
Its designed so that every several seconds the yun will send out the char 'a' over the serial and wait to see if during those several seconds the char 'b' is heard over the serial to complete the handshake. It then repeats this process again and again. What I need help understanding is how to transmit the signal to another arduino and listen for a return signal ('b') over the serial using the xbees on a pair of yuns.
What I need help understanding is how to transmit the signal to another arduino and listen for a return signal ('b') over the serial using the xbees on a pair of yuns.
The ONLY benefit of using Strings is that they can dynamically grow and shrink. Adding const just shit all over that advantage. Quit abusing the Arduino. Do NOT use Strings where they are not needed.
if(Serial.read() == 'b'){
//reset timer
count = -1;
//test that signal is heard correctly
//Serial.println("Clear");
}
//when signal is heard and incorrect
else if((Serial.read() != 'b') && (Serial.read() != 'a') && (Serial.read() >= 0)){
Regardless of whether there is data to be read, read the next character. If it isn't a 'b', throw it away, and see if the next character is a b or the one after than is a or the one after that is available. You don't have a clue what Serial.read() does, do you?
"It doesn't work" is too lame for words. You are sending some unknown data. The code does something unknown (but obviously stupid). You have some unknown expectations about what the code is doing. All we know is that your expectations don't match reality.