Is Serial.begin a blocking function?

Is Serial.begin a blocking function?

void setup() 
{
  Serial.begin(921600);
  Serial.print("Start of setup. Starting device in 40 seconds:");
  for (int i=0;i<4;i++){ //check all buttons
    delay(10000); //let's wait 40 seconds before breaking everything, just in case
    Serial.print(4-i);
  }
...
<the rest of the code here>

My code doesn't start unless I connect the USB port. After that I remove the USB cable and let it run without problems.

  1. I connect the arduino power supply, everything seems fine
  2. I wait for a few minutes just in case and it doesn't matter how much time I wait, it never starts
  3. I connect the usb cable to the PC, I get: "Start of setup. Starting device in 40 seconds:"
  4. After 40 seconds everything works as expected
  5. I disconect the USB cable and everything keeps working.
<the rest of the code here>

I looked; it isn't.

Put a small delay in between these two, like 1 millisecond.

Serial.begin(921600);
Serial.print("Start of setup. Starting device in 40 seconds:");

  1. I connect the arduino power supply, everything seems fine
  2. I wait for a few minutes just in case and it doesn't matter how much time I wait, it never starts

Almost assuredly this is a voltage issue with your board drawing enough current to lower the voltage to the uC ...
When you plug in the USB, you are supplying USB current in addition to Arduino PS current. The voltage goes up beyond "brown out" and things start. Removing USB lowers the voltage but not quiet enough to force the uC into brown-out.

Ray

Almost assuredly this is a voltage issue with your board drawing enough current to lower the voltage to the uC ...
When you plug in the USB, you are supplying USB current in addition to Arduino PS current. The voltage goes up beyond "brown out" and things start. Removing USB lowers the voltage but not quiet enough to force the uC into brown-out.

Ray

How is that possible? The power adapter supplies 2 amps. I only have the arduino, an nrf24l01 module powered through a very small 78L33 (max current: 100 mA) and an RF module that draws 4.5 mA

This is the RF module
http://www.electrodragon.com/product/2262-2272-wireless-module/

How is that possible?

Have a voltmeter? If the voltasge rises at all when the USB is connected, that is the issue. If the voltage does not change when USB is connected, then I am wrong. (Been there B4)

Ray

4.97v stable before and after connecting the USB. But I added a pause of 1 second after the begin(), and now it works. I have 2 boards working.

One of them is randomly failing to send data through the nrf24L01, but that doesn't seem related. Maybe there is a short circuit somewhere. At least both boards start now.

Thanks!!!

You seem to have a very high baud rate - maybe that is part of the "problem".

I've never used a baud rate higher than 115200 and I have never needed to put a pause between the begin() and the print().

...R