RN4020 Smartphone Basic Demo

 Objective

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.

 Materials

Hardware Tools

Tool About Purchase
RN-4020-PICTAIL-50px.png
RN-4020-PICTAIL
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:

rn4020-dfu-ota-connection.png

 Procedure

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

1

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.

2

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

Jumper1.png

3

Determine which COM port number has been assigned.

SerialPort.png

4

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

TeraTerm.png

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

5

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:

rn4020-smartphone-basic-demo-ls.png

6

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

A

The module will respond with AOK when advertising has begun.

Detailed Steps – iOS Device

1

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

SmartDiscover.png

2

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.

DiscoveredList.png

3

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

ModuleConnected.png

4

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

enumerated-services.png

5

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

read-battery-service.png

6

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

SUW,2A19,63
SHW,0018,63

The first command sets the value of characteristic Battery Level to be 99 (0x63) by addressing its Universally Unique Identifier (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.

7

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

read-battery-level-characteristic.png

8

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

enable-battery-level-characteristic-notification.png

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

WC,0019,0100

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 3.3.3.3 “Client Characteristic Configuration” of “Bluetooth Core Specification v4.1”, for details.

9

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

SUW,2A19,32
SHW,0018,32

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:
battery-level-notification-update.png

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.

battery-level-notification-success.png

10

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

back-button-twice.png

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

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
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.