I have Arduino Leonardo board operating lots of AC relays in quite noisy environment. USB works unstable, which sometimes causes the board to hang, so I decided to use secondary serial connection as "debug console":
Serial1.begin(115200);
.....
.....
if (Serial1.available()) {
char ch = Serial1.read();
if ( isalnum(ch) ) {
switch (ch) {
case 'M': {
turnOn_pin_Motor();
break;
}
case 'm': {
turnOff_pin_Motor();
break;
}
.......
My problem is that noise affects Serial1 the same way it messes USB (but at least it doesn't cause it to freeze). I'd like to use some sort of error checking to prevent Leonardo from acting on "phantom" commands. I could, for example, prefix each keyboard command my Arduino should receive with special symbol, maybe "!".
So I must be reading one char, checking if it is "!" and reading second character.
Unfortunately, I can't modify my code so it would use 2-character buffer and shift its contents as characters arrive, without locking the main loop while waiting for the next char. Any hints on what should I do in this case?
Serial1
on a Leonardo is not “Software Serial”, it’s arguably more “hardware” thanSerial
. How does the noise on your serial port manifest? Are the characters injected truly random?[3819448 void turnOff_pin_Inlet()] WкК•╧╠•я² [3819570 void checkTempSensors()] DS18B20 on Door failed!