Low power Bluetooth advertising with XIAO BLE and PlatformIO

Enzo Lombardi
3 min readMay 6, 2022

--

I’ve been toying with the idea of building a Bluetooth device capable to operate for months when not connected; my first attempt brought me to experiment with an ESP32 WROOM based module only to discover that the device needs to be fully powered when broadcasting. The lowest I could go as far as consumption was tens of mA, which translates to roughly 10 days of battery life when powered by 3xAAA batteries (3450mAh total). Even keeping the device asleep most of the time by broadcasting only a fraction of the time, I could push the life of the batteries to a little more than a month, while at the same time increasing the time required for a client to connect.

It’s possible, with an external clock, to reduce the consumption to mere 3mA by following the instructions I found on a bug report, but still the complexity of the workaround (will a crystal work on the breadboard? can the configuration steps required be applicable to my code?) didn’t seem a good trade-off for the amount of consumption that was achievable. There are new ESP32 modules out that should be able to achieve better results, but they are fairly new (ESP32-S3) and with not a strong support deriving from usage.

I decided to look at the promises of the nRF52840, whose smaller sibling x832 powers Apple’s AirTags, capable to go below 1mA when advertising. I fell in love with the XIAO BLE Sense board which has everything I need on a tiny package that can be easily employed in my semi-final prototypes.

Very tiny nRF52840 based board

Documentation shows the ability go down to 3μA in deep sleep mode, so really really promising. The biggest problem though is that the examples provided require the first release of the board Arduino’s core, based on Adafruit’s nRF52840 core. In order to run them in Arduino, the version 1.0.0 of the “board package” must be the one installed.

The goal I was going to achieve is to find a way to get such examples buildable in PlatformIO. There is a very good article that explains how to add support for the board in PlatoformIO here, but it addresses the latest version of the board, based on mbed and ArduinoBLE, and as such missing some low power functionality. After a few miserably failed attempts, I came down to this minimal set of steps in order to get the PlatformIO project setup for a XIAO BLE module.

  1. create and build an empty project that targets any Adafruit nrf52840 based board (in order to avoid mbed); the nrf52840 feather express is a good pick
  2. build the project, which will download and create the proper folder structure if not there yet
  3. run the script here
  4. change the board in platform.ini to xiao_ble_sense
  5. build and upload the project

In order to achieve low consumption the bootloader of the board must be updated by following the instructions on the Wiki. There is an UF2 version of the file that doesn’t even require a JLink to operate: download it, drop it on the USB-drive associated with the dev board and it will automatically update the bootloader for you. If you don’t have an SMD debugger though, the JLink mini-Edu might be perfect (just be sure to respect the license agreement) along with the Xiao Expansion board which makes JFlashing the bootloader or debugging a solderess operation.

The results, tested using a slightly modified version of this broadcast example, speak volumes about the expected life-span when operating with batteries. My code is here.

good luck!

P.S. read this story for more progress with the board.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (4)

Write a response