Avoiding Serial.Read what the arduino is Serial.Print:ing?

Hi all and happy hollidays!

Im trying to get my project to report some variables, but only when asked for them.
Im new with programming and not that bright with code so please help me… :slight_smile:

I want to send a letter, say “v”, and get ("voltage reading " (Value)) in return, witch i kinda get…
But when the arduino replies, it also triggers its own incomming commands, so that example would also trigger a few of my other triggers, repeatively if the trigger letter re-occurs…

i tried the Serial.flush command, but that seems to lock me out instead…

The code im running is MUCH more than merely the below included code snippet, but i figure the snippet should cover all essentials…

My code snippet:

// serial troubleshooting segment
Serial.flush();
if (Serial.available() > 0) { // checks if incomming serial
char input = Serial.read(); // saves serial input
if (input > 0x7F){
input = 0x00;
}

if ( input = 0x74){ // asci for “t”, sets troubleshoot mode ON.
Serial.print("OK, Got: ");
Serial.println(input);
Serial.println(“Turning ON Troubleshoot mode”);
SerialTroubleshoot = 1;}

i figure the snippet should cover all essentials..

If the code doesn't work, how could you possibly know what covers "all essentials"?

Best to reduce the code to the smallest bit that fails in a way you don't understand, and post that [u]using code tags.[/u]

I've never seen the stuff I print get received by the Arduino that sent it. Either it's wired wrong (tx and rx shorted), or the computer is echoing it.

if ( input = 0x74){

input = 0x74 is an assignment, not compare (==).

Also, since you know and have documented that 0x74 is a "t", why not: if (input == 't')?

xarvox: I want to send a letter, say "v", and get ("voltage reading " (Value)) in return, witch i kinda get.. But when the arduino replies, it also triggers its own incomming commands, so that example would also trigger a few of my other triggers, repeatively if the trigger letter re-occurs..

If the data from the Arduino is to cause other actions on the PC then you need a program on your PC that can do that.

This Python - Arduino demo could provide a starting point.

Also look at Serial Input Basics for simple reliable ways to receive data. Make the PC program conform to one of the systems. The 3rd example would be the most reliable.

Serial.flush() is for outgoing Arduino data - it waits until all the outgoing data has been sent.

...R