Adafruit NRF52 BLE Example - Gists · GitHub

Converting this example for use with PlatformIO

I use PlatformIO for most of my embedded dev these days, rather than the Arduino IDE. I find it to be a generally better experience. But I hacked this example together originally for use with Arduino IDE, since that's more common for hobbyist developers.

If you're like me, and you want to use this example with PlatformIO, there are a couple of things you'll want to do. First is to use pio init to create a new project. Once you've got that, add this to the project's platformio.ini:

[env:adafruit_feather_nrf52832] platform = nordicnrf52 board = adafruit_feather_nrf52832 framework = arduino upload_protocol = nrfutil

Note that is is using the current, upstream version of the PIO nordicnrf52 platform (which was needed as of 7/24/19, because it includes the Adafruit BSP version 0.11.1).

That will set up the device target and uses the develop version of the Nordic nRF52 board support in PlatformIO (required as of 3/3/19, as the Adafruit Feather support hasn't been included in a release yet). This will use the current production release of the Adafruit Feather nRF52 board support from PlatformIO. Note: Release 3.4.0 of platformio-nordicnrf52 has a bug that will attempt to force the inclusion of the nrfjprog utility. On most platforms, this is not an issue. I run most of my PlatformIO code from a Raspberry Pi, however, and nrfjprog isn't available for ARM-based systems (I rely on adafruit-nrfutil instead).

PlatformIO can handle .ino files, but I prefer to use more standard C++ .cpp files for Arduino projects. So the next step is to copy the contents of adafruit_nrf52_example.ino into src/main.cpp in the project. You will need to include the Arduino framework, too, so append the following above the other #include statements:

#include <Arduino.h>

Lastly, because this is real C++ and not the Arduino IDE, the functions used in the code need to get defined, so create include/main.h and put this in it:

#include <Arduino.h> bool getUniqueID(); void setUniqueID(); void writeState(); uint8_t readState(); void setState(); void connectCallback(uint16_t handle); void disconnectCallback(uint16_t handle, uint8_t reason);

You'll need to make sure main.h is used, so append this after the other includes at the top of main.cpp:

#include "main.h"

With this done, everything should be set and you can get all of the needed dependencies and build the example with:

$ pio run

Assuming that works (I've tested it, so it should), you can deploy this code to an Adafruit nRF52 Feather with

$ pio run -t upload

Tag » Arduino Nrf52 Ble Example