Serial.begin hang question (altered from Serial.start)

If my sketch uses the Serial.start and serial.print functions and it isnot connected to a computer usb port running a terminal softeware does it hang?

It won’t hang up your code, so there’s not hurt if you accidentally (or intentionally) don’t remove it from the code. Leaving it in there does take up a little more RAM, but is otherwise innocuous.

Just to clarify, the function is Serial.begin(...) instead of Serial.start(...).

I hope that helps!

1 Like

Note, if you do have

while(!Serial.available) WLAN_LOOP(); 

then it will hang if I remember correctly until you have connected to the serial console so keep that in mind

It’s not hanging. You simply need to press any key in order to continue.

Perhaps “hang” was the wrong word but I was under the impression that progress in the user code would be halted until you have connected over serial and sent some data. Is that not the case?

Indeed. It’s done deliberately to wait for a user input so that’s not hanging :stuck_out_tongue:

Thank you for your response.
My code has no while loop, I use the following snipet if (Serial.available()) { ... }

When I do have the USB cable attached to a pc with drivers it does not “hang” but when connectd to a 5v usb power only it seems to not respond to TCP requests if they result in Serial,print commands being issued,

Would you mind posting your code either here on in a gist?

@RufusMaker, I was so free to alter your title, to avoid confusion, since there is no Spark.start() function, but people might get puzzled whether they missed some new function.

I have commented out all Serial functions in my code and it no longer “hangs”

Is there any harwdare or software handshaking on the USB Serial port? How can I disable it?

There is not handshaking per say. The data will continue to send but you will not see it unless you connect to the Serial COM port of the core using a terminal.

Why would you want to disable it? :wink:

I am tryig o determine why my core hangs. While connected to a pc using the proper driversall is well. When connected to a power source other than a pc with drivers it hangs. I commented out the rferences to Serialin my code and now it works on any power source.

I suspect it hangs because most usb wall warts don’t drive the two data lines, just the 5V DC and ground. Once you do Serial,begin() the Spark’s USB hardware interface is looking for specific signaling on these data lines that are part of the USB standard, and never gets them.

I don’t think you can ever use Serial.begin() if you are just using the USB for power, unless you can find a UPS power module that is fully compliant with the USB device standard

I do doubt that. I’ve never had a problem with a wall wart.

As @kennethlimcp said, by default there is no handshake and if you send serial data the TX line just changes from HIGH to LOW and back as the data requires, no matter if there is someone actually watching that line - so no blocking there.

On the other hand it’s more likely that there might be some code in your program that waits/blocks or just skips the code you expect to be executed until some data arrives on the RX line - but since we don’t see enough of your code, it’s impossible to tell.

void setup()
  pinMode(D7, OUTPUT);
  digitalWrite(D7, HIGH);


void loop()
  digitalWrite(D7, !digitalRead(D7));

Try running this sketch. The blue LED should blink - no matter if you power it off you PC or a wall wart.
If it does blink you have confirmed that Spark.begin() does actually NOT block.

I’m confident that you can. All (except one) of my Spark Cores are powered using a USB charger, and I often forget or neglect to remove Serial code from my firmware. The one that isn’t USB powered is powered by a 5v wall wart.