NRF51822 with an accelerometer and an Oled display

The CJMCU-8223 is a small breakout board featuring an NRF51822 and an LIS3DH accelerometer. It is shown above attached to an SSD1306 Oled display. Programs are loaded on to it using an ST-Link debugger clone.

There are many different ways to program this chip but I decided to develop code for it using the online compiler at This environment allows you write and compile code within your browser. Compiled programs are dropped in to your downloads directory in the form of “hex” files. These downloads can then be written to your target MCU using your preferred debugger. The advantage of this approach is that you don’t have to set up a toolchain on your PC and, you can avail of lots of ready made libraries and example code.

This particular example provides two Gatt services over BLE. An LEDService allows a connected bluetooth device to control the blue LED on the breadboard. An accelerometer service allows the connected device read the accelerometer values (scaled up by a factor of 1000 to avoid floating point printing). The code for this example can be found via this link over at

When you compile this code, the hex file delivered to your PC needs to be uploaded to the NRF51822. This is done as follows:

In one command window (terminal) start openocd as shown here:

Leaving that window running, open a new one and run telnet entering the commands shown below.

Once you have done this, type reset into the telnet session and the board should start running.

You can interact with the board using BLE Scanner on your phone or maybe work with node.js or python to develop a PC based application.

If you need to do some debugging, it is possible to export the program from the mbed environment into a format that is compatible with a number of toolchains (including gcc/gdb). I have tried this and it works pretty well although you may need to disable interrupts on the MCU while doing this as the debugger can get confused if there is bluetooth activity during the debug session.

9 thoughts on “NRF51822 with an accelerometer and an Oled display

  1. walter August 20, 2020 / 6:04 pm

    nice work !! what is the address of the OLED I don’t see defined in the code? do you have a schematic this setup ?


    • fduignan August 20, 2020 / 6:09 pm

      Hi Walter, I don’t have a schematic on me right now but SDA is on P0_30, SCL is on P0_0. The OLED address is 0x3c (shift left 1 bit for read/write bit). See OLED.h for more details.


  2. Sulis January 4, 2021 / 12:36 pm

    Hi FDUIGNAN, nice work! sorry if I’m bothering you, but do you have a video tutorial of accelerometer bluetooth?


    • fduignan January 4, 2021 / 1:03 pm

      Hi Sulis, I don’t have a video tutorial but I’m happy to answer any questions you may have


  3. Sulis January 7, 2021 / 5:19 am

    thank you for your answer, I will try it first then when I have any problems I will ask you


  4. Sérgio September 29, 2021 / 2:24 pm

    Please, do you have the CJMCU-8223 datasheet?


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 )

Facebook photo

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

Connecting to %s