Nrf52840 BLE autostart?

Using the Seeed Xiao Nrf52840 board in the Arduino IDE (1.8). I have tried several of the “getting started” sketches, including the Blink and the BLE controlled Blink. In addition, i have modified the DHT11 sketch to instead use the Bosch BMP180 Temp and Pressure sensor.

All 3 of these work fine when they are uploaded to the Nrf52840 board. They run and can be scanned and connected to using the Nrf Connect applicationon my Android phone.

The simple Blink sketch (no BLE) also starts automatically when attached to a battery pack or an USB hub, similar to the Arduino behavior.

However, with the other two sketches (BLE controlled blink and BMP180) this does not occur. When the USB connection is moved to a hub or battery pack, the Nrf52840 powers down and apparently does not restart. Scanning with Nrf Connect does not find the 52840. Instead, I have to re-connect to the Arduino IDE and re-upload the sketch, at which point everything works again.

I suspect that I’m overlooking something very simple, but have not found it. Any help?

Well, as I suspected, upon further investigation, the problem is actually very simple. There is a statement in “void setup” of the BLE-enabled examples:

while (!Serial);

that is appropriate during troubleshooting the uploaded sketch, but, when the board is not connected to the Arduino IDE (As when it’s on a battery pack) actually blocks the code’s progression, causing it to hang and be non-responsive. Simply commenting this line solved the problem and now, both the LED control sketch and my BMP180 sensor sketch operate completely as expected.

1 Like