Need to send one char from one Arduino to another. My current code can successfully transfer the char and display it on the receiving Arduino, however the message keeps getting printed every loop. Looking for a simple way to have one message displayed on the receiving Arduino. So far I've tried Serial.flush(), and writing a new value to the variable outside of the range of incoming messages. Ideally, i would prefer to set Serial.Available = or < 0 so the system will only act if there is a new incoming message waiting to be read. Any help would be appreciated. Code is listed below.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Think i just figured out the problem! It had nothing to do with the code. I had the tx tied to the rx and vice versa going to each board along with a common ground. Since the code would print out the char value after 1 second i removed the USB cable from the transmitter and plugged in the corresponding TX / RX cable into it. Since the board was getting power, i assumed nothing of it. By plugging in an external power source into the transmitter along with the TX RX GND leads, the code is working fine now with no repeating values. Thanks for the insight!
cjr7315:
Think i just figured out the problem! It had nothing to do with the code. I had the tx tied to the rx and vice versa going to each board along with a common ground. Since the code would print out the char value after 1 second i removed the USB cable from the transmitter and plugged in the corresponding TX / RX cable into it. Since the board was getting power, i assumed nothing of it. By plugging in an external power source into the transmitter along with the TX RX GND leads, the code is working fine now with no repeating values. Thanks for the insight!