Hi guys, I'm working on an application in C# in which i have to connect to a serial port(arduino).
Now, connection and transmission from arduino to c# runs smoothly, but then at some point i need to write back to the arduino some data. I found this script on arduino's website:
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
Problem is, the "if" condition seems to be always true, even if I didn't send any data from c#'s serial port write method. I tried even not connecting it to the C# program, the condition still remains true and all the instructions I put inside run anyways. Example:
if (Serial.available())
{
digitalWrite(ledPinWait, LOW); //led pins were declared in the same scope.
digitalWrite(ledPinOk, HIGH);
}
All of this runs on the loop().
Basically if I received something back, the leds have to turn on(and the other to turn off) but they do no matter what.
What have I done wrong?
Board: Arduino Uno