Hi
I have what I deem to be a simple sketch that receives a letter from a pc and turns an LED on or off. the Sketch works perfectly, BUT I must first activate the serial monitor from within the arduino IDE on the PC
I would like to NOT have to do the serial monitor activation step, so that the sketch is automatic.
after i once call the serial monitor and then close it all works fine. Here is the command line from the pc
set /p x="a" \.\COM20
set /p x="b" \.\COM20
and here is the sketch
All of the loop() code is inside the while (Serial.available()) loop. Nothing will happen until that while is true (their is 1 or more bytes available in the receive buffer).
void loop()
{
while (Serial.available())
{
mychar = Serial.read();
if (mychar == 'a')
{
digitalWrite(LED_BUILTIN, HIGH);
}
//delay(3000);
if (mychar == 'b')
{
digitalWrite(LED_BUILTIN, LOW);
}
}
}
but if you don't open the Serial monitor, nothing will happen on the sketch side since it only reacts to Serial commands... The arduino is happily running doing nothing but testing for a byte to arrive on the Serial port.
I can see why you think that is true but test it it lights the led and turns it off as many times as I wish. but only after calling the serial monitor and closing it. this works with the serial monitor closed and the ide closed