Hi there,
I'm working on a project where I'm using an Arduino Mega to send ASCII commands to 2 syringe pump and valve units.
I've been writing a code that communicates with the pumps in two ways.
- by writing a program in the loop, and
- by sending commands manually from the serial monitor.
Ive been successful in writing a code to dispatch the message in the serial monitor to the proper pump/valve unit but the issue I'm having trouble with is that I can't seem to clear the last message from the serial monitor. i've tried
to explain it better ill give some examples:
(I have it in the code to echo the message for troubleshooting)
-
If I were to type /1 in the message box and send it by pressing enter i see /1 in the serial monitor, (this is okay)
-
then if I type 3444 in the message box and send it by pressing enter i see 3444 in the serial monitor, (this is okay)
-
next if I type /2 in the message box and send it by pressing enter I see /244 in the serial monitor, (this is not okay)
-
furthermore if i just type enter in the message box it resends the /2 command and I see /244 in the serial monitor. (this is not okay)
the only way to clear this is by resetting the Arduino and this isn't an option for the final implementation. I would be more than grateful if anyone whos experienced something like this before could share their insight or a solution.
I have been watching tutorials and tried changing the code in many ways including adding serial.flush()
serial.begin() again
serial.print(serial.read())
the only thing I tried that may work but wasn't successful in implementing was creating another function called serial.flushRX() in the hardware serial library (described on the sparkfun website forum) https://forum.sparkfun.com/viewtopic.php?t=32715
if its not a common problem i can upload the code if someone thinks it will help. (though its pretty clunky at the moment - im on revision 14 of this version trying to figure this out)
thanks for reading