nRF52840 Development with Arduino and CircuitPython

Pages
Contributors: jimblom
Favorited Favorite 4

Arduino Installation

With the Arduino Board Manager, installing new board support within your Arduino IDE is a breeze! There will be one extra step to install the recommended support for the SparkFun Pro nRF52840 Mini, however.

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

Installing the Arduino Core for nRF52 Boards

Adafruit, who have done an amazing job developing their nRF52 Arduino core for the nRF52832, have been extending their support to the nRF52840.

To install the nRF52 Arduino Core:

  • Open the Arduino IDE (must be v1.6.12 or later)
  • Navigate to Preferences
  • In the "Additional Board Manager URL" box, add:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
  • Go to Tools > Board and select the Board Manager.
  • Search for "nRF", and you should find the Adafruit nRF52 board package.
  • Make sure the latest version is selected and click Install

board manager showing nrf52 install

Having a hard time seeing? Click the image for a closer look.

Installation may take a few minutes -- included in the install are all necessary source files for the Arduino core and nRF52 libraries, plus all of the compiler and software-upload tools you'll need to use the nRF52840 with Arduino.

Once the board definitions have been installed, you should see a new set of nRF52 boards under your Tools > Board menu. You won't, however, see an option for the SparkFun Pro nRF52840 Mini. For that, we need to manually add a new board.

Adding the SparkFun Pro nRF52840 Mini to the Board Menu

To add a "SparkFun Pro nRF52840 Mini" option to the nRF52 boards list, we need to make a couple small, manual modifications to the Arduino core you just installed.

Why the SparkFun Pro nRF52840 Mini board definitions?

The addition of these board modifications are not required for uploading code to your nRF52840 via Arduino. Most significantly, these board definitions help define pin-routing. They'll help to route the following serial buses and pins:

  • Hardware Serial (Serial1) to pins 17 (TX) and 15 (RX) to match the Arduino Pro Mini pinout
  • I2C to pins to 8 (SDA) and 11 (SCL). Important if you're using the qwiic connector.
  • SPI to pins 31 (MISO), 3 (MOSI), 30 (SCK) – again matches the Arduino Pro Mini pinout.
  • Built-in LED (LED_BUILTIN) to pin 7

If you'd rather skip this step – even temporarily you can use Adafruit Bluefruit on nRF52840DK PCA10056 as your board selection.

To add SparkFun nRF52840 board support to the nRF52 Arduino core, one file (boards.txt) needs to be modified, and one new folder (variants/sparkfun_nrf52840_mini) needs to be copied in. You can grab the latest version of these files from our GitHub respository or by clicking the button below and unzipping the ZIP files contents:

To place the files, first navigate to your Adafruit nRF52 core installation. If you installed via the board manager it'll probably be in one of these folders:

  • Windows: %LOCALAPPDATA%\Arduino15\packages\adafruit\hardware\nrf52\<version>
  • OS X: ~/Library/Arduino15/packages/adafruit/hardware/nrf52/<version>
  • Linux: ~/.arduino15/packages/adafruit/hardware/nrf52/<version>

If you installed the core manually into your Arduino sketchbook, it'll be in "hardware/adafruit/nrf52".

Then open boards.txt. Scroll to the bottom and paste the below into the bottom of that file:

language:text
#**********************************************
# SparkFun Pro nRF52840 Mini
#**********************************************
sparkfunnrf52840mini.name=SparkFun Pro nRF52840 Mini

# DFU Mode with CDC only
sparkfunnrf52840mini.vid.0=0x1B4F
sparkfunnrf52840mini.pid.0=0x002A

# DFU Mode with CDC + MSC (UF2)
sparkfunnrf52840mini.vid.1=0x1B4F
sparkfunnrf52840mini.pid.1=0x0029

# Application with CDC + MSC
sparkfunnrf52840mini.vid.2=0x1B4F
sparkfunnrf52840mini.pid.2=0x8029

# CircuitPython
sparkfunnrf52840mini.vid.2=0x1B4F
sparkfunnrf52840mini.pid.2=0x802A

sparkfunnrf52840mini.bootloader.tool=bootburn

# Upload
sparkfunnrf52840mini.upload.tool=nrfutil
sparkfunnrf52840mini.upload.protocol=nrfutil
sparkfunnrf52840mini.upload.use_1200bps_touch=true
sparkfunnrf52840mini.upload.wait_for_upload_port=true
#sparkfunnrf52840mini.upload.native_usb=true

# Build
sparkfunnrf52840mini.build.mcu=cortex-m4
sparkfunnrf52840mini.build.f_cpu=64000000
sparkfunnrf52840mini.build.board=NRF52840_FEATHER
sparkfunnrf52840mini.build.core=nRF5
sparkfunnrf52840mini.build.variant=sparkfun_nrf52840_mini
sparkfunnrf52840mini.build.extra_flags=-DNRF52840_XXAA {build.flags.usb}
sparkfunnrf52840mini.build.vid=0x1B4F
sparkfunnrf52840mini.build.pid=0x5284
sparkfunnrf52840mini.build.usb_manufacturer="SparkFun"
sparkfunnrf52840mini.build.usb_product="nRF52840 Mini Breakout"

# SofDevice Menu
# Ram & ROM size varies depending on SoftDevice (check linker script)

sparkfunnrf52840mini.menu.softdevice.s140v6=s140 6.1.1 r0
sparkfunnrf52840mini.menu.softdevice.s140v6.build.sd_flags=-DS140
sparkfunnrf52840mini.menu.softdevice.s140v6.build.sd_name=s140
sparkfunnrf52840mini.menu.softdevice.s140v6.build.sd_version=6.1.1
sparkfunnrf52840mini.menu.softdevice.s140v6.build.sd_fwid=0x00B6
sparkfunnrf52840mini.menu.softdevice.s140v6.build.ldscript=nrf52840_s140_v6.ld
sparkfunnrf52840mini.menu.softdevice.s140v6.upload.maximum_size=815104
sparkfunnrf52840mini.menu.softdevice.s140v6.upload.maximum_data_size=248832

# Debug Menu
sparkfunnrf52840mini.menu.debug.l0=Level 0 (Release)
sparkfunnrf52840mini.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0 -Os
sparkfunnrf52840mini.menu.debug.l1=Level 1 (Error Message)
sparkfunnrf52840mini.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1 -Os
sparkfunnrf52840mini.menu.debug.l2=Level 2 (Full Debug)
sparkfunnrf52840mini.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 -Os
sparkfunnrf52840mini.menu.debug.l3=Level 3 (Segger SystemView)
sparkfunnrf52840mini.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 -Os

Then copy the contents of the "variants" folder in this directory into the "variants" folder of the original directory. Nothing should be overwritten, but a new "sparkfun_nrf52840_mini" directory should be added in.

directory location for arduino board variant

Having a hard time seeing? Click the image for a closer look.

After making these modifications, restart the Arduino IDE if it was open.

Installing adafruit-nrfutil

A program called adafruit-nrfutil is used to package and upload compiled code to the nRF52840 -- similar to what avrdude does for Arduino Uno's and other AVR boards.

If you're on a Windows or Mac machine, you can ignore this part. adafruit-nrfutil is automatically installed with the board definitions.

Linux users will need to manually install adafruit-nrfutil. adafruit-nrfutil is a Python-based program, to install it with PyPi type:

language:python
pip3 install adafruit-nrfutil --user

(You may need Python 3 installed if you don't already have it.)