I have an arduino micro and several clone "pro micro"'s both of which are based on the 32u4, i'm trying to make my project have a debug mode which is only active when the serial port is open, the documentation states that using:
if (Serial)
on these boards should only return true if the port is open (on uart based connections it always returns true), i wrote my sketch to take advantage of that but it didn't seem to be working properly, so i stripped back to basics and wrote this sketch:
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial){
digitalWrite(2, HIGH);
}
else{
digitalWrite(2, LOW);
}
}
I connected an LED to pin 2 and then tested it by connecting and disconnecting the arduino from the PC, and opening and closing the com port.
after freshly connecting the arduino to the PC the LED is off, when i open a connection to the virtual com port the LED turns on. however i would expect the LED to go out once the port is closed, but it remains on.
My questions are:
1) have i got an out of date bootloader?
2) if so how do i check?
3) is this intended behavior and if so why?
4) is this a bug in the arduino bootloader or libraries?
5) short of having to change my code to look for serial data to start and stop the debug mode (serial comms are being used for other things in the background) is there any way i can work around this? reading from hidden registers etc?
Edit:
should have mentioned i'm seeing this behavior with or without a call to Serial.begin
Serial.begin