Is while(!Serial.available()) necessary?

It’s been a little while since I’ve worked on a photon, but it seems in that time, using while(!Serial.available()) Particle.process() has become necessary to get serial working at all on windows.

Reference :

// EXAMPLE USAGE
void setup()
{
  Serial.begin(9600);   // open serial over USB
  // On Windows it will be necessary to implement the following line:
  // Make sure your Serial Terminal app is closed before powering your device
  // Now open your Serial Terminal, and hit any key to continue!
  while(!Serial.available()) Particle.process();

  Serial1.begin(9600);  // open serial over TX and RX pins

  Serial.println("Hello Computer");
  Serial1.println("Hello Serial 1");
}

void loop() {}

I don’t mind missing some messages so I don’t need the photon to wait for me to connect. It’d also be nice to have a photon running for some time (days) and be able to connect and disconnect through USB.

Is there a work around for this?

Nope, it’s not required and my devices work well without it.

Stating your system version and OS version would also help understanding possible issues.

1 Like

I think I’ve answered my own question. You don’t have to have the while(!Serial.available)... line but you DO need to send a message through the serial terminal before it will log anything. Seems odd to me.

Working on windows 10. How do I get my system version?

Hmm, nope - not for me.


Via Listening Mode and particle identify or a Serial terminal and sending v

System version is 0.5.3

0.5.3 should not pose a problem.
0.6.0+ might require you to remove the old Particle Serial drivers (completely) and reinstall newer ones (Windows pre 10 - not required for 10+) in order to prevent collisions between the new USB HID features and USB Serial.

I was using Termite without DTR/RTS flow control. Reading the release notes for 0.5.3 I noticed

DTR/RTS support (open/closed detection: Serial.isConnected()). #1073

Changing the flow control in Termite now starts logging automatically, which is how I remembered it.

Thanks for the help

2 Likes