RN4020 Smartphone Basic Demo

Last modified by Microchip on 2023/11/09 09:03


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

Reference Materials

Back to Top

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:

Connection Diagram

Back to Top


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 the supplied USB cable (make sure jumper JP1 is in the OFF position).

Board view showing JP1 off

Determine which COM port number has been assigned.

Device Manager showing which COM port has been assigned

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

TeraTerm showing serial port setup

Enter the following:

+                // echo on
SF,2             // perform a 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:

TeraTerm showing displaying the current services

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


The module will respond with AOK when advertising has begun.

Back to Top

Detailed Steps – iOS Device

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

iOS  "Bluetooth Smart Discover" icon

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.

Smart Discover app list of available devices

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).

TeraTerm window showing "Connected".  Board view of PIO1 pin will going high (GREEN LED)

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 shown).

App showing list of services (and characteristics)

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

Battery Service  displaying "Battery Level" characteristic

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 the characteristic Battery Level to be 99 (0x63) by addressing its Universally Unique Identifier (UUID) 0x2A19. The second command sets the value of the characteristic Battery Level to be 99 (0x63) by addressing its handle 0x0018. The match between the 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).

Screen showing battery level characteristic

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

Battery Level characteristic shown by moving the slider switch to the right

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


This output means the application tried to write the 2-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:

App automatically updates to 0x32 (50 decimal)

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.

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

AOK message returned by the module

Pressing the Back button twice disconnects the Bluetooth Low Energy (BLE) connection between the app and the RN4020 module.

Back button twice disconnects the Bluetooth Low Energy (BLE) connection

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

Back to Top