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.
Reference Materials
- RN-4020-PICTAIL
- Terminal Emulator
- Windows®: Tera Term
- MAC®: CoolTerm
Smart Discover App (iOS)
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:
Procedure
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).
Determine which COM port number has been assigned.
Start TeraTerm (115200, 8, n, 1, none).
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:
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
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 shown).
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:
SUW,2A19,63 SHW,0018,63
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).
The app can also start notifications 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:
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.
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:
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.
Pressing the Back button twice disconnects the Bluetooth Low Energy (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.