Serial use causing flash to fail?

Here are two very small pieces of code. The first one flashes and works, the second one doesn’t. Both were working ~10 days ago. The failing one opens the serial port and sends text to it every 500 ms. Yet when I attempt to flash it, I get the blinking magenta for a bit, then the RGB LED goes blank for a minute and then blinks green, then breathing cyan (with the previous flashed app working or it goes from flashing magenta to flashing green, then flashing blue. What am I doing wrong? Thanks!

//THIS FLASHES
int LED = D6;

void setup() {
pinMode(LED, OUTPUT);
}

void loop() {
digitalWrite(LED, HIGH);
delay(250);
digitalWrite(LED, LOW);
delay(250);
}

//THIS DOES NOT FLASH
int LED = D5;
void setup()
{
Serial.begin(9600); // open serial over USB
Serial.println(“Startup”);
pinMode(LED, OUTPUT);
}
void loop() {
Serial.println(“Loop”);
digitalWrite(LED, HIGH);
delay(250);
digitalWrite(LED, LOW);
delay(250);
}

You are are right the second version does not work. I added a 500mS delay after the Serial.begin and that does flash.

unfortunately the Spark Core USB tp my Windows machine connection is not opened until the Serial .begin function is run. The terminal software (terminal.exe) I am using can not be preset to a comm port until it is opened, so I miss the first print "Startup" and who knows how many loops until I manage to set the port number in Terminal.. Th esolution of course would be to add a rather long delay to allow time from Windows burbling "USB connected" to setting the port number in Terminal.

Just tested that with a 29 second delay...works great.

Good luck!

David G.

@sierrasmith71 That fixed it! Thanks!

2 Likes

Just making a note here that I’m adding this to our bug tracker, and I’ll ask them to update this thread if they find anything.

Thanks!
David

1 Like