arduino-experiments/UART/arduino-cascade...
I'm trying to write an Arduino sketch that passes serial signals from one board to another after being triggered by either a button input or a serial input from the computer. I've gotten this to work: https://github.com/JeremySCook/arduino-experiments/blob/main/UART/arduino-cascade.ino via button presses and then via serial from the computer. However, after it receives serial signals it no longer recognizes button inputs. I'm assuming it has something to do with the if serial available bit - maybe I can just remove it. Thoughts?
May be slightly different code on the receiver, but board #1's onboard LED doesn't work either at that point.
GitHub
arduino-experiments/UART/arduino-cascade.ino at main · JeremySCook/...
Experiments in Arduino C. Contribute to JeremySCook/arduino-experiments development by creating an account on GitHub.
1 Reply
To follow up on this problem (as I have it solved, or at least working), it seems you have to get rid of the information in the serial buffer so that the Serial.available bit won't interfere with things. I'm still not 100% though.
I used Serial.end(), then Serial.begin(9600) to clear things out then reestablish the connection. Using Serial.flush() didn't work, which I thought was what that was for, but again I may be misunderstanding the mechanism. Anyway, I updated my code on GitHub, and the important bit is:
This was instructive: https://forum.arduino.cc/t/clearing-serial-buffer-solved/227853
Arduino Forum
Clearing serial buffer solved
Hi all, i had this question a few weeks back , after the change in flush() method it had become quite difficult to empty the serial buffer , so to all those who require to send large amounts of data from processing or serial monitor to arduino, just use this code. Only prerequisite is that the data must be sent as a bulk, no delays are required...