BM70 Compact Demo Board User's Guide

Chapter 5. RN4870 Sensor Board

5.1 INTRODUCTION

This section demonstrates how to use the RN4870 Sensor Board with the BM-70-CDB which is loaded with RN4870 firmware. Once the RN4870 is configured to enable the Sensor Board peripherals, the sensor values can be read locally using RN4870 Universal Asynchronous Receiver/Transmitter (UART) commands or from the BLESensor smart phone app over GATT. The following is the configuration procedure:

  1. Configure Peripheral I/O port to sensors using command SW.
  2. Define a GATT service (Sensor Board) to hold the values from peripherals for a read access from a GATT client.
  3. Similarly, when a GATT client writes a value to a GATT server characteristic in a peripheral (GAP), there must be a method for the peripheral (GAP) to write the value destined for characteristic into the peripheral port.
  4. A GATT client on a Central (GAP) device is used to access the GATT characteristics in the peripheral (GAP) which is an RN4870 with Sensor Board. The GATT client for the Sensor Board is a smartphone app named BLESensorApp. It is possible to use another RN4870 as the GATT client to access the RN4870 Sensor Board peripherals.

The critical function of associating GATT characteristic with a peripheral is performed by the RN4870 scripting capability.

The RN4870 can be configured manually by following the instructions in Section 4.2 “Connecting The BM-70-CDB To A Host PC” through Section 4.5 “Creating Custom GATT Services”. Alternatively, the RN4870 can also be configured by using the PC Utility (RN4870_SensorBoard_Cfg_Cmd.exe) as described in 5.7 “Provision Utility”.

5.2 READING SENSOR BOARD PERIPHERAL IO PORTS USING UART COMMANDS

The RN4870 has digital and analog peripheral inputs and outputs. For a detailed description of the I/O interface, refer to the “RN4870/71 Bluetooth® 4.2 Low Energy Module Data Sheet” (DS50002489), and for the configuration details, refer to Section 2.4.24 and Section 2.6.5 through Section 2.6.8 of the “RN4870/71 Bluetooth® Low Energy Module User's Guide” (DS50002466). Peripheral I/O can be accessed through direct UART commands or over Bluetooth Low Energy connection by associating a GATT characteristic with a peripheral input or output.

This section details the procedure to read and write peripherals on the Sensor Board using the BM70 and the terminal emulator. The pins on the BM70 of the BM-70-CDB that are connected to the corresponding peripherals on the Sensor Board are indicated in Figure 5-1.

1

Connect the Sensor Board to the BM-70-CDB as shown in Figure 1-1.

2

Set the module to Factory default using the SF,1 command to set the peripherals to default.

  • Using Terminal Emulator, open the COM port to the RN4870 module
  • Type $ to enter Command mode
  • Enter SF,1 and verify that the module reboots after the command is entered.

3

Enter the following sequence of commands to configure RN4870 IO pins as illustrated in Figure 5-1:

  • Type $ to enter Command mode
  • Enter + to enable local echo
  • Enter SW,01,00 for ADC input port 01 used by the light sensor
  • Enter SW,02,00 for ADC input port 02 used by the potentiometer
  • Enter SW,03,00 to configure digital IO port connected to the LED
  • Enter SW,04,09 to configure digital IO trigger connected to the Push button
  • Enter R,1 to reboot the module for the settings to take effect
cdb-fig-5-1.png
Figure 5-1: RN4870 PINS USED BY SENSOR BOARD INTERFACE

4

After IO ports are configured and the module is rebooted, enter the commands shown in Figure 5-2 to read and write peripheral IO.

cdb-fig-5-2.png
Figure 5-2: COMMANDS TO READ AND WRITE SENSOR BOARD IO

5.3 CONFIGURING THE RN4870 MODULE SETTINGS

The RN4870 and the Sensor Board can be configured by entering the following commands manually. Alternatively, the configuration commands are located in Appendix F. “Sensor Board Script Text”. Each command can be copied to the clipboard via <CTRL+C> and sent to the RN4870 via TeraTerm using the <ALT+R> (Paste) command.

1

Connect the BM-70-CDB to the host PC USB port:

  • Using Terminal Emulator, open the COM port to the RN4870
  • Type $ to enter Command mode
  • Enter + to turn on local echo
  • Enter WP to stop any running script
  • Enter WC to clear any previous script
  • Enter PZ to clear any previous user defined GATT service
  • Enter SF,1 to set the module into factory default and verify that the module reboots after the command is entered.
  • Type $ to re-enter Command mode
  • Enter + to turn on local echo.

2

Configure Module Features

  • Enter S-,RN4870 to serialize Bluetooth name
  • Enter SS,80 to enable Device Information Profile
  • Enter SR,4040 to enable scripting start on PWR_ON event and disable com- mand prompt.
  • Enter SW,01,00 for ADC input port 01 used by the light sensor
  • Enter SW,02,00 for ADC input port 02 used by the potentiometer
  • Enter SW,03,00 to configure digital IO port connected to the LED
  • Enter SW,04,09 to configure digital IO trigger connected to the Push button
  • Enter R,1 to reboot the module
  • Type $ to re-enter Command mode
  • Enter + to turn on local echo
  • Enter command D to display settings as show in Figure 5-3. Command GW is used to return to the current IO configuration.
cdb-fig-5-3.png
Figure 5-3: RN4870 MODULE SETTINGS CONFIGURATION

5.4 SENSOR BOARD GATT SERVICE

The data from the RN4870 peripheral I/O are stored in the characteristics of a custom GATT service accessed by the Sensor Board BLE Client App. To create the Sensor Board GATT Service and characteristics, enter the following commands while in Command mode:

1

PS,AD11CF40063F11E5BE3E0002A5D5C51B to create a 128-bit UUID to identify the GATT Service.

2

PC,BF3FBD80063F11E59E690002A5D5C501,10,02 to declare a two-byte characteristic with notify property enabled. This characteristic stores the value of the ADC channel used for light sensor.

3

PC,BF3FBD80063F11E59E690002A5D5C502,10,02 to declare a two-byte characteristic with notify property enabled. This characteristic stores the value of ADC channel used for potentiometer.

4

PC,BF3FBD80063F11E59E690002A5D5C503,18,14 to declare a 20-byte characteristic used to manage both the Push button state (virtual LED in App) and the LED blink rate on the Sensor Board. Both notify and write properties are enabled for this characteristic.

5

PC,BF3FBD80063F11E59E690002A5D5C504,10,02 to declare a two-byte characteristic with notify property enabled. This characteristic stores the value of the ADC channel used for the RN4870 internal temperature sensor.

6

PC,BF3FBD80063F11E59E690002A5D5C505,10,02 to declare a two-byte characteristic with notify property enabled. This characteristic stores the value of the ADC channel used for the RN4870 internal battery voltage sensor.

7

Command R,1 to reboot the RN4870 module.

8

Command $ to enter Command mode.

9

Command + to enable local echo.

10

Command LS (list services) to display Sensor Board GATT Service as shown in Figure 5-4.

cdb-fig-5-4.png
Figure 5-4: SENSOR BOARD GATT SERVICE DECLARED IN RN4870

Figure 5-4 illustrates that a custom GATT service has been created in the RN4870. A 16-bit handle is assigned to each characteristic where each characteristic has a value handle and a property handle. The characteristic value and the properties are accessed by a short and more efficient 16-bit handle instead of the 128-bit UUID value. For example, two handles 0072 and 0073 are associated with the GATT characteristic BF3FBD80063F11E59E690002A5D5C501. A GATT client, such as a smartphone App, uses 0072 to read/write characteristic values, while 0073 is used to enable/dis- able the notify property.

The next step is to transfer the sensor values from the peripheral I/O into the GATT characteristics. This is done with the RN4870 scripting feature as described in Section 5.5 “Transferring Sensor Data Into GATT Service Using Scripting”.

5.5 TRANSFERRING SENSOR DATA INTO GATT SERVICE USING SCRIPTING

For more information about the Sensor Board GATT service, refer to Section 5.4 “Sensor Board GATT Service”. To populate the characteristics with data from the Sensor Board peripherals, and conversely transfer values received from the GAP client into peripheral IO channels, the RN4870 scripting feature is used. For more details on the scripting capabilities, refer to the “RN4870/71 Bluetooth® Low Energy Module User's Guide” (DS50002466).

The script that drives peripheral values to and from the GATT service is written into the Non-Volatile Memory (NVM) of the RN4870 via the UART.

First, put the module into Script Entry mode. The script is a series of text commands separated by carriage returns. The actual script is displayed in Appendix F. “Sensor Board Script Text”. It can be copied to the clipboard and pasted in UART using Tera Term. Similarly, the PC Utility can load it into RN4870.

To load the Sensor Board script manually, perform the following steps:

1

Connect the BM-70-CDB to the host PC USB port

  • Using Terminal Emulator, open the COM port to the RN4870 module
  • Type $ to enter Command mode
  • Enter + to turn on ECHO.

2

Enter Script Entry mode

  • Enter command WW to put the RN4870 into Script Entry mode. This command does not return an AOK response.
  • Copy the script text from F.2 “Sensor Board Script” into the clipboard using <Ctrl+C>.
  • Enter the script in TeraTerm using the <Alt+R> (Paste) command. A dialog window showing the script text from the clipboard is displayed as shown in Figure 5-5.
  • Press OK to load the script into the RN4870.
  • After the script is entered into the RN4870, exit Script Entry mode by pressing the <ESC> key. An AOK response is sent to the terminal. The script entry is shown in Figure 5-6.
  • Enter command R,1 to reboot the RN4870. After reboot, the Sensor Board is ready to use. The script event handlers can be seen on the TeraTerm display as shown in Figure 5-7.
cdb-fig-5-5.png
Figure 5-5: SENSOR BOARD SCRIPT DISPLAYED FROM CLIPBOARD
cdb-fig-5-6.png
Figure 5-6: COMPLETED SENSOR BOARD SCRIPT
cdb-fig-5-7.png
Figure 5-7: SCRIPT EVENT HANDLERS

5.6 BLESENSORAPP SMARTPHONE APP

The RN4870 Sensor Board is a BLE Peripheral that advertises a GATT service to BLE Central devices. In this demonstration, the BLE Central device is a smartphone application named BLESensorApp. It is available to download for iOS and Android platforms via iTunes App Store, and Google Play Store, respectively. Search for the “Microchip BLESensorApp”, and download the App matching the icon in Figure 5-8.

cdb-fig-5-8.png
Figure 5-8: BLESENSORAPP ICON

The BLESensorApp requires the Sensor Board to be configured as described in Section 5.3-5.5.

1

Ensure that the Sensor Board is attached to the BM-70-CDB as shown in Figure 1-1.

2

Verify the Switch 2 in SW2 is in position 2: Application mode.

3

Power the BM-70-CDB via USB

  • Connect the BM-70-CDB to power up
  • Verify that LD2 blinks blue with long interval.

4

Launch the BLESensorApp from the smartphone. In this example, the iOS version is used as shown in Figure 5-9.

5

The BLESensorApp attempts to connect to the first RN4870 Sensor Board it discovers. Once connected, the main user interface of the BLESensorApp is displayed. This auto connection is only possible when location access permission is enabled for BLESensorApp.

cdb-fig-5-9.png
Figure 5-9: BLESENSORAPP

6

If location access permission is not enabled then BLESensorApp displays the list of available RN4870 Sensor Boards in the vicinity. The connection can be initiated by clicking the desired device as shown in Figure 5-9.

cdb-fig-5-10.png
Figure 5-10: BLE DATA FLOW FROM SENSOR BOARD PERIPHERAL IO TO BLESENSORAPP

Figure 5-10 illustrates the data flow between the RN4870 Sensor Peripheral IO and the smartphone app. The data streaming from the Sensor Board to the App is performed by GATT Notifications. The script polls the sensor values, such as Switch, Light Meter, and writes the values into the appropriate GATT Characteristic. If the value changes, a GATT Notification is sent to the BLESensorApp where the App updates the Graphical User Interface (GUI).

BLE data can also be transferred from the BLESensorApp to the RN4870, and later processed by the script to write a received value into the Peripheral output channel. In the Sensor Board demo, slider control is used on the App to select a blink rate value. The value is written to GATT characteristic in the RN4870. The sensor script monitors the Characteristic for incoming data then extracts the value which is subsequently written to the Pulse With Modulation (PWM) output peripheral to control the LED blink rate.

For more information on the BLE GATT data transfers, refer to Appendix E. “Bluetooth Low Energy Primer”.

5.7 PROVISION UTILITY

The RN4870 Provision Utility can be used to provision/configure the RN4870 Bluetooth Low Energy (BLE) module from a Windows Host PC using a wired connection over Universal Asynchronous Receiver/Transmitter (UART) interface. The RN4870 Provision Utility is used to program the RN4870 with the configuration and script to work with the Sensor Board and the BLESensorAPP.

The utility comes with a few prebuilt provision options that can be selected using the Provision File drop-down menu. Alternatively, a custom configuration XML file can be imported into the utility to provision the RN4870 module.

Detailed instructions for provisioning the RN4870 module and creating custom configuration XML file are provided in the RN4870 Provision Utility Help files. Examples of the Provision XML file are in the Examples folder.

Download the RN4870 Provision Utility from www.microchip.com/RN4870. Extract the contents into a separate folder on the host PC. The contents of the extracted folder include the RN4870 Provision Utility executable, the RN4870 Provision Utility Help files and the example configuration XML files. This utility requires the MCP2200 USB/UART CDC drivers. The driver is also available from the web page. Install the driver if needed.

While the provisioning is in progress, the RN4870 must not be disconnected and the process should not be interrupted. If the provisioning process is interrupted, the RN4870 module may not be configured as desired.

To configure a RN4870 with a Sensor Board plugged in, perform the following steps:

1

Ensure that the Sensor Board is attached to the RN4870 (BM-70-CDB) as shown in Figure 1-1.

2

Verify the Switch 2 in SW2 is in position 2: Application mode.

3

Connect the RN4870 to the host PC using the micro USB cable and verify that LD2 blinks blue with a long interval.

4

Wait for the RN4870 board to successfully enumerate as a Serial Port device.

5

After the RN4870 board enumerates as a Serial Port device, open the Device Manager on the Windows PC and note down the COM port number assigned to the RN4870 board under 'Ports'.

6

Run the RN4870 Provision Utility (RN4870ProvisionUtility.exe) on the Windows PC. Refer to Figure 5-11.

cdb-fig-5-11.png
Figure 5-11: CONFIGURATION UTILITY MAIN WINDOW

7

Ensure that the RN4870 board is still connected to the Windows PC and successfully enumerated. Click Scan button to scan for all the UART COM ports available on the Windows PC.

Ensure that the COM port on which the RN4870 board is enumerated is not opened by another application like a Serial Terminal application.

8

Click the drop-down menu of the UART COM Port and select the correct COM port that is assigned to the RN4870 board to be provisioned. Refer to Figure 5-12.

cdb-fig-5-12.png
Figure 5-12: CONFIGURATION UTILITY: SELECT COM PORT

9

A set of prebuilt provision options for the RN4870 module are provided. Choose the RN4870_Sensors_Demo_1.xml XML file from the Provision File
drop-down menu as shown in Figure 5-13.

Use only a valid BLE Provision XML (.xml) file.

cdb-fig-5-13.png
Figure 5-13: CONFIGURATION UTILITY: SELECT XML FILE

10

With the RN4870 board still connected, the COM port and the RN4870_Sen- sors_Demo_1.xml file selected, click Provision button to start the RN4870 provisioning process. The progress bar shows the progress of the provisioning process. Refer to Figure 5-14.

cdb-fig-5-14.png
Figure 5-14: CONFIGURATION UTILITY: CONFIGURING MODULE

11

After the provisioning process is completed, an information dialog window pops up to inform about the successful provisioning of the RN4870 module. Refer to Figure 5-15.

cdb-fig-5-15.png
Figure 5-15: CONFIGURATION UTILITY: PROVISIONING SUCCESSFUL

After the provisioning is successful, the RN4870 automatically reboots and retains the provisioned configuration.

© 2017 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.