BLE POC Tracking System – Implementation Notes – Programming NRF51822 BLE & ESP8266 Wi-Fi Chip

I’ve recently completed an Honours Degree in Software Development and as part of this I spent a few months off and on working on a proof of concept tracking system utilising Bluetooth Low Energy (BLE) in order to track small asset tags. I believe this system could quite easily be scaled up to an industrial scale with further work but don’t personally plan to follow this up in the near future due to working on other projects. As such I figured I’d release a lot of what I have and hopefully it can help somebody else.

If you do something cool with this then please get in touch, otherwise do with it all as you wish.

This post is one of eight scheduled to be released over the next few weeks, all posts in this series may be found by selecting the tag below.

This post functions as a log of the steps required to implement this project in a practical manner, the goal is that somebody else with minimal knowledge may be able to follow it.

Programming the NRF51822 BLE Tag

The BLE beacon will transmit every 30 seconds and will also push through data regarding whether the button has been short or long pressed, this could potentially be used to automatically deprecate or change the status of an asset to reduce overhead time.

Instructions are similar to previous stage, but the connectors are slightly different.

Figure 11 Demonstrates the connection points on a NRF51822 BLE Tag, Taken from AliExpress -
Figure 11 Demonstrates the connection points on a NRF51822 BLE Tag, Taken from AliExpress –
NRF51822Raspberry PI 4
SCLK/SWCLK (Input)GPIO 25 Pin 22
SDD/SWDIO (Output)GPIO 24 Pin 18
BAT +3V3 Power Pin 1
BAT –GND Pin 6
Connection Table

The code for this has already been developed by Eric Tsai and can be found here –

This must be compiled and flashed to the device as per the previous post.

Programming the ESP8266 Wi-Fi Chip

The ESP8266 can be programmed from the Arduino IDE which makes it straightforward to program luckily. It will be connected to the BLE module and will receive BLE data, process it to MQTT then publish it to the local Wi-Fi network.

Download and Setup Arduino IDE

First step is to download the Arduino IDE which will let us program the ESP8266 chip, this can be done from

Once installed open it up and then we need to add support for the ESP8266 –

Programming the ESP8266

Before attempting to connect to the device, first we need to verify that it is properly connected.

  1. Connect the ESP8266 module to the Raspberry PI using a microUSB to USB connector.
  2. In the Raspberry console type ‘lsusb’ to view connected devices.
  3. There should be a device called “CP2102/CP2109”, if not try a different cable.
  4. Then type ‘dmesg | grep “tty” to return all connected devices and their serial port, for USB this is likely to be ttyUSB0.

Note: The Raspberry Pi cannot power both the ESP8266 and the NRF51822 modules in serial. They must be disconnected to program the ESP8266

Using the Arduino IDE, do the following before programming –

  1. Go to Tools > Board > ESP8266 Boards > Generic ESP8266 Module.
  2. Go to Tools > Port
  3. Select the port that the device is attached to. (/dev/ttyS0 for USB)
  4. Open or write a script.
  5. Click Compile to start compiling the sketch to the device.
  6. The script will run as soon as it is uploaded.
  7. Output can be found using the Serial Monitor

The specific code we need to run on the ESP8266 module will be this –


Arduino IDE comes with a Serial Monitor which we can use to monitor any serial output from the chip.

  1. Open Arduino IDE.
  2. Ensure the correct board and port are selected.
  3. Go to Tools > Serial Monitor
  4. Change the baud rate to 115200.

Connecting the NRF51822 to the ESP8266

To connect the two devices requires custom Dupont cables for simplicity, although they could also be soldered.

Cables should be connected as below –

GND (Ground)GRD
VDD (Power)3V3 (3.3V)
TX P01.09 (Serial Output)SD3
Connection Table
Figure 12 Example of the NRF51822 and the ESP8266 chips connected using Dupont cables
Figure 12 Example of the NRF51822 and the ESP8266 chips connected using Dupont cables

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.