When the Photon starts up, I have some serial outputs I’d really like to see in the setup() section, but it takes a while (5-10 seconds) until the device can be read…
I try to read the Serial output with this:
You could put a delay before the first prints, so you have time to connect. Alternatively, you could have it wait until you input something over serial before continuing. Either should work.
If it’s for debugging purposes, it does make sense somehow. If not, then what exactly do you need the serial output for that soon? Any reason the device should start immediately, since a three second delay is often more than enough to connect with serial. The setup is progressed through incredibly fast, and you connecting before it finishes is rather rare. I haven’t got enough experience with Linux to know if there are options to do so automatically, but other than that, the delay works.
If you have a free IO pin, a technique like this can be handy if you want to see your Serial.prints during setup during development. If D6 is left unconnected, the code runs through setup normally. If you tie D6 low, then setup either waits until you hit a key over serial, or for 10 seconds, whichever comes first.
void setup() {
Serial.begin(9600);
pinMode(D6, INPUT_PULLUP);
if (digitalRead(D6) == LOW) {
// Only check for waiting for serial when D6 is pulled low
unsigned long waitStart = millis();
// Wait for 10 seconds or until a key is pressed
while(!Serial.available() && ((millis() - waitStart) < 10000)) {
Particle.process();
}
}
Serial.println("exiting setup");
}