RN4020 Smartphone Basic Demo


This page outlines a step-by-step procedure which demonstrates how the RN4020 module can interface with a smartphone or tablet device using the standard Battery Service.


Hardware Tools

Tool About Purchase
RN4020 Bluetooth Low Energy PICtail™/PICtail Plus

Software Tools

This lab requires the following software tools:

 Connection Diagram

A host is required to enter commands that configure the module to be a Peripheral device, enable the standard Device Information and Battery Services and begin advertising for connections. The following connections are required at a minimum:



Detailed Steps – RN4020 Device Under Test (DUT) – RN-4020-PICTail Card


Ensure that the minimum signal connections as shown in the diagram above are connected. If you are using the RN4020 PICTail, they are already connected.


Connect the RN-4020-PICTail to the PC via supplied USB cable (make sure jumper JP1 is in the OFF position).



Determine which COM port number has been assigned.



Start TeraTerm (115200, 8, n, 1, none)


and enter the following:

+                // echo on
SF,2             // perform complete factory reset
SS,C0000000     // enable support of the Device Information and Battery services
SR,00000000     // set the RN4020 module as a peripheral
R,1             // reboot to apply settings


After the RN4020 module has powered up and “CMD” is displayed on the terminal emulator, issue the “LS” command to display the current services that the RN4020 module enumerates and supports in the server role. The output of the LS command will be as follows:


0x180A is the Bluetooth® SIG assigned ID for the GATT Device Information Service.

0x180F is the Bluetooth® SIG assigned ID for the GATT Battery Information Service.


In Tera Term, enter the “A” command to start advertisement.


The module will respond with "AOK" when advertising has begun.

Detailed Steps – iOS Device


On your iOS device, go to the App Store, search for "Bluetooth Smart Discover" and install it.



Launch the app and enable your Bluetooth interface (if required). The app will then begin scanning for devices. Once finished, select your device from the list shown.



The Module will output "Connected" when a connection is made. Also, the module's PIO1 (CONNECTION) pin will go high (GREEN LED on the PICTail Card).



The app will then enumerate and list the services (and characteristics) exposed by the RN4020 (i.e. the Device Information and Battery Services, respectively, will be seen)



Selecting the Battery Service will display one characteristic ("Battery Level"), as well as the characteristic's property: readable and notification can be started.



Return to the terminal emulator to control the RN4020 directly to set the Battery Level to 99% using either of the following two commands:


The first command sets the value of characteristic Battery Level to be 99 (0x63) by addressing its UUID 0x2A19. The second command sets the value of characteristic Battery Level to be 99 (0x63) by addressing its handle 0x0018. The match between handle and UUID can be found by command “LS”. The handle value for each characteristic stays the same for the same set of server service settings. As long as the supported server services are not changed by command “SS”, the handles of the characteristics stay the same.


Returning to the app, read the battery level characteristic by pressing the "read" identifier shown on the screen. The returned value will show 63 in hexadecimal (and 99% in decimal on the main services enumeration screen - not shown).



The app can also start notification on the Battery Level characteristic by moving the slider switch to the right as shown.


On the RN4020 side, a notification will output to the terminal application display as follows:


This output means the application tried to write the two byte value, 0x0001 (little endian over air makes it 0100), to the configuration handle of the Battery Level characteristic with the UUID 0x2A19 in the Battery Service with the UUID 0x180F, effectively enabling notification for this characteristic. Refer to Table 3.11: “Client Characteristic Configuration bit field definition” in Volume 3, Part G, Section “Client Characteristic Configuration” of “Bluetooth Core Specification v4.1”, for details.


Return to the terminal emulator and Update the battery level to 50% on the RN4020 module by entering either of the following two commands:


After issuing either of the two commands, you will see that the battery level characteristic value in the app automatically updates to 0x32 (50 decimal) as shown:

This is because with an active notification, any update to the value of a characteristic on the server side will be notified to the client side.

On the module, when a server characteristic value is set, if notification/indication has been supported and started on such characteristic, in addition to the “AOK” message returned after issuing the “SHW” or “SUW” command, a second “AOK” message will be returned by the module if the transmission of notification/indication is successful; otherwise, message “NFail” will be sent.



Pressing the "Back" button twice disconnects the BLE connection between the app and the RN4020 module.


In TeraTerm, press "A" to begin advertising again, and repeat the connection process with the app.

20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.