Arduino with RN4870/1

RN4870_01_800The RN4870/1 is a small (only 12mm wide) BLE module from Microchip. What makes this a little bit special (when compared to modules like the HM-10) are the advanced features that allow you to create your own services and characteristics. This opens up true BLE functionality. It has been available for a while now and I am surprised it is not more popular in the hobby area.

The RN4870 is very different to common hobbyist modules like the HM-10, AT-09, and BT05 and if this is all you have used you may need a refresher on BLE. Especially if you want to use your own services and characteristics.

This is a first look / getting started guide that I will add to as I get time.
Latest update: May 27, 2018

RN4870/1 Features

  • Fully Qualified Bluetooth 4.2
  • Low Energy Module
  • Certified to FCC, IC, CE, KCC, NCC and SRRC
  • On-Board Bluetooth 4.2 Low Energy Stack
  • ASCII Command Interface API over UART
  • Scripting Engine for Hostless Operation
  • Beacon Private Service for Beacon Services
  • UART Transparent Service for Serial Data
  • Over The Air Remote Configuration

The RN48709/1 is configured using ascii commands similar to other BT modules. The main difference s that the The RN48709/1 has it’s own set of unique commands and does not use AT style commands. It also has a mini programming or scripting language built in. This means, depending on what you want to do, you may not need a MCU like the Arduino, the RN48709/1 can be used stand alone.

The UART Transparent Service for Serial Data allows an easy way to link 2 modules together. This can be considered a serial cable replacement, however, if this is all you need you may be better suited with the HM-05/06 or HM-10.

The The RN48709/1 has full BLE 4.2 functionality:

  • Secure AES128 Encryption
  • GAP, GATT, SM, L2CAP and Integrated Public Profiles
  • User Can Create up to Five Public and Four Private Services
  • Software Configurable Role as Peripheral or Central and Client or Server
  • Keyboard I/O Authentication

The RN4870/1 is available is a few different sizes/configurations. With shielding, without shielding, with antenna, without antenna, all pins available, only basic pins available.

Image from the Microchip RN784z data sheet.

Image from the Microchip RN4870/1 data sheet.

The ones I have are the RN4870-V/RM118 version. With antenna and all pins available.

These modules are more expensive that the common hobbyist modules like the HM-10 but they far more advanced, well supported with full data sheets and a user forum. Most questions, if not all, will have already been answered on the forum.

Microchip official information

RN4870 product overview
User guide, data sheet, firmwares and update tool. Same page as above, click the Documents tab and scroll down.
Technical details. This is a website with lots of details. Use the menu on the left.


Getting Started

The RX4870/1 is a very small SMD board which makes it a little difficult for hobbyists. A basic breakout board can be built if you have fairly steady hands. Here is my rather lack lustre attempt. I mounted the module upside down so that I still have access to the pads should I need to add more connections later.

Not the best soldering I have ever done but the board is very small and the iron tip has seen better days.

The jumper is connected between pin 18/P2_0 and GND. With pin 18 brought to GND when the modules start they enter programming mode. This allows you to update the firmware. The jumper is a simple way of connecting pin 18 to GND.

RN4870_02b_usbAdapterThe connections are arranged to match the usb/serial adaptor I am using.

RN4870_02c_usbAdapter_2_800Here is a second board which is slightly smaller. This one has a wire connected to the programming pin. I simply connect the wire to GND when I want to enter programming mode. The extra pin/socket on the end is not used.

You will notice that I used different pins for GND and VCC from the RN4870. This allowed me to use 2 pads to solder the wires which made life a little easier.

I am surprised that there are not more pre-made breakout boards for this module. The only one I can find is the RN4870/1 Click from MikroElektronika.

Jon Raymond contacted me to say he has created his own breakout boards (which look very nice) and is hoping to release the designs at some point. See Jon’s Twitter feed for pictures.


Pins & Basic Circuit


The pins we are initially interested in are:
Pin 3 – GND
Pin 4 – VBAT (3.3v vcc in)
Pin 23 – UART_TX
Pin 22 – UART_RX
These are all you need to use the module but it is a good idea to add a LED to Pin 30 so you know if it is on or not.

Remember that RN4870 RX goes to usb adaptor TX and RN4870 TX does to usb adpater RX.

The data sheet has full details for the other pins.

This is a corrected diagram. The previous diagram had the LED on the wrong pin and wired backwards…

New modules have a basic beacon set up and we can use this to test if the module is working or not. For this just add vcc and GND. Remember these are 3.3v devices so use 3.3v not 5v.

Power the module, then use a BLE scanner app to find the beacon. Here I am using Android BLE Scanner by Bluepixel Technologies LLP but there are many similar apps.

Open the app, you should see the RN4870 (it will not have the same name), connect and the LED should change to 2 quick blinks every second.
– Open the first characteristic (Generic Access 0x1800, this is the device name)
– Read the characteristic data by clicking the small R icon. You should get the name again.


Now we know it is working we can try talking to it through a serial terminal program, something like Tera Term or the Arduino IDE.

Talking to the RN4870/1

To talk to the RN4870/1 we need a usb to serial adaptor. I am using this one but other 3.3v versions will work. Make sure it is 3.3v. At a push you could use a spare Arduino but I don’t go in to this here.

usb-serial-adapterHere is a adapter I am using. 3.3v or 5v can be selected.

Connect the RN4870 to the usb adapter and connect to a PC, note that I am using Windows 7, this will give you a COM port. Mine is COM5. Yours will be different.

For the first few examples I am using the Arduino IDE. The Arduino IDE does not have local echo (it does not display what you have entered) but you can turn on local echo in the RN4870 with the “+” command if you wish. Use the “+” command after entering data mode.

RN4870_11_serialMonitor_02If you check the data sheet you see that it has a default baud rate of 115200 and all commands require a carriage return CR character (\r).

The RN4870 can operate in data mode or command mode. It is in data mode by default so we need to change to command mode using the “$$$” command. Small caveat though, Microchip do not class “$$$” as a command and it only works when there is no line end character. This really should be stated in the data sheet. So change the line endings to “No line ending” and enter $$$:

If the world loves you, or even likes you just a little bit, you will get a “CMD>” reply.

To return to data mode use “—\r”. This is 3 dash or minus characters + CR.

Now change the line endings back.

There are a few commands that return data (these are called GET commands). One is the “D” command and another is “V”. “D” returns information about the device and “V: returns the firmware version.

“D” command
The “D” command returns device information:
– Device MAC Address
– The random address (if a random address is used)
– Device Name
– Connected Device MAC address
– Authentication Method
– Device Features as set by the “SR” command
– Server Services
– The fixed pin code (if one is being used)


“V” command
The “V” command returns the firmware version.

Here you can see that the modules I have are using firmware V1.18.3. This is not the latest and I will look at updating it later. The latest firmware, at the time of writing, is v1.28.3 v1.30.

“GNR” command
“GNR” gets the name of a connected device. Of course, for this to work the module has to be connected to something. With the serial monitor still open. Use the BLE scanner app to connect to the RN4870.

When the module connects it sends the connection details to the serial monitor:

Now we have a connection we can get the name of the connected device with “GNR”

When you break the connection, the RN4870 outputs a “%DISCONNECT%” message.

For a full list of the GET commands see the data sheet.


First Communications

Please note I am using a module with 1.30 firmware.

Firmware 1.30 comes with a set of default services and characteristics built in and we can use these to try out making a connection. I am keeping it simple and using the Arduino IDE with the same serial adapter and BLE Android app as above. The RN4870 is on and in data mode.

In the Arduino IDE, select the correct COM port and open the serial monitor.

Start the BLE Scanner app, if it does not automatically start scanning, hit the Scanner button at the bottom. You should see the RN4870 appear in the list.

Hit the CONNECT button, after the connection is made, select the Custom Serice

In the serial monitor you should see the connection message

We can now try sending data to the serial monitor.
For the the custom characteristic 49535343-8841-43F4-A8D4-ECBE34729BB3, hit the write button, a text input box should appear, enter “hello” and click OK

The value of the characteristic changes to hello and you should see hello in the serial monitor

The RN4870 receives data via the 49535343-1E4D-4BD9-BA61-23C647249616 characteristic.

Click the HM-10_SERV+CHAR_003_N_Icon_015 notification button to turn notifications on (The indicate button also works).

In the serial monitor enter “hello to you” and click send and “hello to you” should magically appear in the characteristic.


Notify or Indicate?

In the above example I use Notify to confirm when data has been received but you can use either Notify or Indicate so what’s the difference? Notify does not need an acknowledgement, Indicate does. This makes Notify a little faster but less reliable. Notify also allows for constant data flow whereas Indicate has to wait after each piece of data for the acknowledgement before it can send the next piece.

Here is some data, get it while you can.
Here is some data, get it while you can.
Here is some data, get it while you can.
Here is some data, get it while you can.

Here is some data, have you got it yet? wait, wait… Reply “I have it” received now I can send the next data.
Here is some more data, have you got it yet? wait, wait… Reply “I have it” received now I can send the next data.
Here is some more data, have you got it yet? wait, wait… Reply “I have it” received now I can send the next data.
Here is some more data, have you got it yet? wait, wait… Reply “I have it” received now I can send the next data.

I like to think the modules have conversations with each other.


Connecting Two RN4870 Modules Together

The RN4870s have a transparent UART layer built in. This means it is easy to get them connected and start sending data. This is very similar to how the HM-10s (and similar modules) work, and, if this is all you need you might as well go with HM-10s. They are cheaper and come on hobbyist friendly breakout boards.

To get started I am using modules connected to the same computer with usb to serial adaptors. The same ones as above. One of the modules is on COM 7 and the other is on COM 8. I am using the module on COM 7 to initiate the connection. Everything is manual. The modules I am using have firmware 1.30.

Creating a connection is straight forward as long as you have the MAC address of the remote module. If you have the address you can simple use the connect to mac address command. If you don’t have the address then you can scan. Scanning returns the mac address and the name of found modules. The address for the device I want to connect to is D88039F914F5 but I’ll pretend I don’t know it.

On the main device, enter command mode with “$$$” (no EOL characters).

Enter SS,C0 to enable the UART transparent service.

Enter F to start a scan

I am looking for the module named RN4870. It is the second one and its mac address is D88039F914F5. To connect use the Connect “C” command. The “C” command expects 2 parameters;
1 – the type of address, 0 or 1). 0 for public address, 1 for private address.
2 – the mac address

So, to connect I use “C,0,D88039F914F5″

If the connection is successful you will get connection messages in both serial monitors.

And once the connection is made the modules can talk to each other



Updating the Firmware

The official Microchip information only covers updating the firmware when using the PICtail development board but it is fairly easy to update using just the RN4870 module. You will need:
– A RN4870
– A USB to serial adaptor
– The isUpdate.exe file
– The firmware to upload (4 files)

You will also need to know the COM port the usb to serial adaptor is using. In my case it is COM 7.

The update tool and the firmware can be downloaded from the Microchip RN4870 page. Click the Documents tab. You can download the data sheet and user guide from the same page.

To put the RN4870 in to programming mode we need to bring pin P2_0 low during boot. P2_0 is the bottom centre pin.

On the larger breakout board, closing the jumper connects pin P2_0 the GND.


On the smaller board, the wire is used to connect P2_0 to GND. This is a very lazy solution and not really recommended. I have killed more than one Arduino because of this technique. It is easy to short something that shouldn’t be shorted.


To update

I am updating from firmware 1.18.3 to 1.30. FW 1.30 was released on May 4th, 2018.

Only one program can connect to a COM port at a time so if you have a serial monitor open, close it. Then:
– Remove power from the module,
– Connect P2_0 to GND and
– Re-power the RN4870.
Although there is information online that the LED is solid on, for me the LED is off. Apparently, if you connect the LED the right way round it works correctly, it is solid on when the module is in programming mode. Who Knew? Me if I’d read the data sheet correctly. Thanks to Jon Raymond for pointing this out.

Open the isUpdate.exe file (Installation is not required).
– Set the COM port (mine is COM 7)
– Set the baud rate to 115200
– Set memory type/subtype to flash and Embedded Flash (or Embedded F)
– Set address to 0000


Click Connect. If the module connects you get a “Port connect -> COM7 message” (or whatever port you are using) and the programming buttons become active.

Now click the Flash Update/Browse -> Images, Browse button and select the 4 firmware files. You can select all 4 files in one go.

And then click Update. If everything is fine the update should start.


The “End of Write Memory” message indicates it’s finished and that’s it.

We can now check we have the new firmware:
– Close the isUpdate app or click the Disconnect button to release the COM port.
– Power off the RN4870
– Remove the programming wire
– Restart the module (the LED should be on)
– Open the serial monitor
– Enter command mode with “$$$” (remember no EOL characters)
– Check the firmware with the “V” command (requires the CR EOL character).

Release notes are included with all firmwares but the notes only include the changes for the latest version (no history). If, like me, you are jumping a few versions you will need to check the release notes for each firmware version to know what all the changes are.

RN4870_99_FU_13After updating, use a BLE scanner app to check the default services and characteristics.


This post will continue as I get time.

One thought on “Arduino with RN4870/1

Leave a Reply

Your email address will not be published. Required fields are marked *

four − = 2

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>