Arduino on the nRF51822 Bluetooth Low Energy microcontroller

Arduino on the nRF51822 Bluetooth Low Energy microcontroller

This is the first in a series of posts about programming the Nordic Semiconductors nRF51822 Bluetooth low energy micro-controller using the Arduino IDE. The post is a big one as it describes the entire hardware and setup process.


The board I’m using can bought bought on eBay, AliExpress or Amazon for well under $10

(Update 20th Oct 2016. I found who actually makes these module. See  however they are only available via companies like WaveShare and various other vendors on eBay and AliExpress etc)

nrf51822 module

The board does not have either USB or an onboard serial based bootloader, so at least initially, it has to be programmed using an external SWD programmer.

I’m currently using a Maple Mini STM32 board as a programmer


By programming it with a custom version of the Black Magic Probe firmware (more on this later), but any SWD compatible programmer should be able to program this device, as long as the programmer explicitly supports the nRF51822 – One other programmer which I know works is the JLink by Segger.


The Maple Mini is available mainly through eBay and AliExpress for around $5 ( ) and you will also need a USB to serial converter to program it, like this one  or any USB to serial that supports 3.3V devices.



Although not essential, its a lot easier to connect the nRF51822 RF module if you use a “Motherboard” like this one, which are also available on eBay and AliExpress etc, for around $12 (USD) (without the radio module)

nrf51822 motherboard



The main reason that you should consider buying this board, is that the RF module, uses pin size and spacing which is not commonly used on other development boards, i.e the pins are not 0.1 inch apart, and the pins are shorter and thinner than used on Arduino shields etc.

However if you are happy to solder some wires to the module, you can save yourself at least $10, which is what I’ve done as I’m still waiting for my Motherboard to arrive.


Anyway, enough of the hardware you’ll need…

What software is required.

The first thing you’ll need, if you don’t already have it, is a copy of the Arduino IDE. Currently the only versions of the IDE that I’m supporting are 1.6.4 and 1.6.5

Once you have installed the Arduino IDE you need to add either the Arduino Due or Arduino Zero board using the  Boards Manager. The reason this is currently required, is to install the ARM compiler and not for the actual Due or Zero. At a later date I will make a JSON file so that the nRF51822 can be installed without needing to install the Due, but at the moment this is the workaound you will need to use.

The next thing you need to do is download the third party core files from github, specifically this zip file

Next, go to your Arduino sketches folder and if there isn’t already a hardware folder, make a folder called hardware

Unzip it, and copy the RBL folder from inside /arduino-1.6.x/hardware into your newly created hardware folder, and restart the Arduino IDE

Now under the boards manager you will have a new board “Generic nRF51822”


Now to make yourself a SWD programmer from your Maple mini



First you will need to download the firmware from github


In order to be able to send updates to the Blackmagic probe team, I’m probably going to need to maintain a direct fork of their master version.

In which case I will move the version with working binaries to


And also on Windows download the Flash Loader from STM


Connect the USB Serial to the Maple mini by RX <–>TX and using GND and Vcc to GND and 3.3V on the USB to serial connector.

You also need to connect the Boot1 pin to gnd on the maple mini during programming

Then press and hold the button at the end of the Maple mini and then press and release the reset button (this will put it into serial upload mode)

Then use the STM Flash loader to upload the binary file to the Maple mini.

Once its been flashed, connect the Maple mini via its USB connector to your PC and it should be detected as 3 new USB devices.

On windows you will need to install the drivers for these, by downloading and unziping, then open the device manager and select each of the 3 unknown usb devices in turn and select update driver software, then browse to the folder you have just unziped and allow windows to install the drivers.

Note in the Windows device manager, which new USB device is shown as the GDB server, as you need to select that COM port number in the Arduino IDE to upload.


To connect the Maple mini to the nRF51822, you need to connect the following pins

For the SWD programming of the module use

Pin 6 -> SCLK on the nRF51822 or on the JTAG connector on the motherboard

Pin 7 -> SDO on the nRF51822 or on the JTAG connector on the motherboard

For USB to serial, you can use these pins on the Maple mini

Pin 8 -> P0.09

Pin 9 > P0.11

GND -> Gnd on the nRF51822 or Motherboard


You can use the USB to Serial that is on the Motherboard instead of the Maple mini, in which case don’t connect pins 8 and 9



If you are not using the motherboard or want to power everything from the Maple mini, you will also need to connect

Vdd to Vdd (either on the nRF51822 or the Motherboard)





open an example sketch like Blink and upload, and if everything is working, you should see a LED blinking on the Motherboard.

If you won’t have a motherboard, you’ll need to connect a LED to pin P0.15, as this is currently the mapping that I’ve inherited from the RebBearLab files.

256 Responses

  1. hobby16

    Evothings is essentially Cordova, but much faster to write code with. Evothings’ examples “BLE scan” and “BLE discovery” work perfectly at the outset on an nrf518222 board flashed with Sandeep core, I have several low cost smartphones with Android 4 and Android 6 and they all work, that’s why I don’t give up trying it, yet. Hopefully, I’ll get a working Android app where I can send/receive data from the nrf518222 That’s why I’ll try to compile the Redbearlabs BLE examples on Sandeep core because Evothings has precisely nice example projects for Redbearlabs BLE.

  2. Roger Clark

    I had a quick look at Evothings again, and it looks very much like Adobe’s PhoneGap product, were I seemed to need to install their App to use it.

    I initially used PhoneGap as I already had a Adobe account which gave me PhoneGap as a free add-on, however I found that needing to upload via the web to their server and then to download again back onto the phone to give very slow code iterations.

    I also didn’t find the debugging much use.

    I see Evothings BLE plugin is also directly available for Cordova

    I think I tried it as well, but I can’t remember why I didn’t use it

    Its possibly because the last commit date was Nov 24, 2016 , and I tend not to use projects on github which dont seem to be active.

    There are also 41 open issues on github for the Evothings BLE plugin

    I think some of them should be closed as they were user errors, but as Evothings does seem to reply to bugs dating back to last May, e.g. reporting it doesnt work with Android N

    I don’t think I’ll be rushing to us Evothings

    It could be that the Evothings studio does not use the same version as they put in github, but I’m not comfortable with using closed source software etc, when there can be perfectly good open source alternatives

  3. hobby16

    indeed, the low activity on Evothings and a nearly empty forum has been definitively a big doubt factor.
    I don’t give up (yet) because according to them, Evothings is open source and a project written with Evothings can be compiled straight away with Cordova (quite credible claims but I have not yet verified if they are true).
    AFAIK, there is really no alternative to Evothings. To write code with Cordova, you must recompile, generate APK, upload and run, whereas it’s just one click with Evothings. Coming from the RFOBasic world, where changing code and relaunch is just a matter of fraction of second and developping a fully functional app is just a matter of an hour or two, Cordova is definitily a no-go for me. Problem is RFOBasic works nice with Bluetooth 2 but has not implemented Bluetooth LE, grrr.

  4. Roger Clark

    I don’t see the problem with using Cordova

    The only difference seems to be that with Cordova you have to connect your phone to the PC via USB. This works really well, and is a very fast way to update the app.

    I just open a command window and type

    cordova run android

    and it uploads and runs.

    To debug you can use Chrome, as it has a “devices” section where you can connect to any Cordova type browser app that is running and use Chrome to inspect the page and the variables etc, pretty much like you can do with a regular web page

  5. hobby16

    “cordova run android”
    Thank you Roger for the tip. I’ve seen so far only horribly slow Cordova setups in video demos. I thought that Cordova always recompiles and regenerates an apk at each code iteration, I did’nt know that it could be as fast as Evothings (using a usb-debug cable is no problem),
    I’ll give (again) it a try. If ever you are successful using Evothings BLE plugin with Cordova, please let us know.

  6. Roger Clark

    I think I just followed the instructions here

    I had to install Node, but that was all

    I already had the phone drivers installed (I think they installed themselves when I connected the phone)

    You have to enable USB debugging in the developer settings, and you also have to authenticate the PC with the phone.
    I probably already did that buy running ADB for something else, but I suspect when you first try to upload from Cordova it may ask you to authenticate (confirm that the PC is allowed to access the phone)

    Compile and upload is really fast, as it only recompiles what is needed e.g. whats changed.

    Debugging with Chrome is a bit of a pain as even time you upload it breaks the connection to Chrome and you have to re-attach,

    The URL is


    I suspect I’m doing something wrong and there is an easier way, and that it may be possible to edit in Chrome like you can on normal web pages, but I’ve only managed to change the CSS etc in Chrome and inspect the Javacript and not modified the javascript on the fly

    Anyway, its worth trying Cordova

    BTW. I think Cordova may need to run in Windows Power Shell.

Leave a Reply