Sensors and Controls with the RN487x Bluetooth Module from Microchip. Part 2 - How to configure the RN487x module

Microchip RN4870 RN4871

Information for configuring your modules and using them before each of the project descriptions that will follow in other articles.

Part 1

Using a Console Connection to Configure the RN487x

To configure the RN487x, first supply power to the module and establish a serial connection between the module and a workstation. Each of our demonstration circuits has a 3-pin ‘prog’ jumper that exposes the necessary RX, TX, and GND signals. If you are unsure of how to make this connection to your workstation, an excellent guide is [1]​.

Start a terminal emulator on your workstation. One emulator that is particularly well suited and widely available is the ‘miniterm’ utility that is included in most Python environments. In a workstation shell, it can be started like this:

python -m serial.tools.miniterm --eol LF /dev/ttyUSB0 115200

This example shows a port name (/dev/ttyUSB0) that is appropriate for a Linux system. The form of the port name will be different for other operating systems. The default baud rate for the module is 115200 and there is little reason to change it.

The RN487x module is in DATA mode by default. We need COMMAND mode. This mode is activated by typing three dollar-sign characters (‘$$$’) in the terminal emulator application. You will not see the characters in the terminal window, but the result should be a command prompt returned by the RN4871:

CMD>

Try pressing the 'd' key followed by 'Enter' key. You should see something like this as a result:

CMD>
BTA=D88039F80080
Name=RN_BLE
Connected=no
Authen=2
Features=0000
Services=00
CMD>

This is a minimal description of the module state. Notice that the command interpreter did not display the character you typed (‘d’). You should turn on 'echo' to fix this. Do this by pressing the '+' key followed by the 'Enter' key. The device should respond like this:

CMD> ECHO ON
CMD>

You are now at a point where you can complete various configuration tasks described in the rest of this project. Creating a service, for example is accomplished by simply typing a complete ‘PS’ command in one line, followed by the ‘enter’ key. Ex:

CMD> PS,59c88760536411e7b114b2f933d5fe66
AOK

Each of the project configurations also require that a multi-line script be committed to the module NVRAM. This type of multi-line command requires a bit more explanation. You begin script entry with a ‘WW’ command, followed by ‘enter’. Then type each script line. Each script line, including the last line, is also terminated with the ‘enter’ key.

Finally, you commit the script by pressing the ‘esc’ key. Ex:

CMD> ww
@CONN
|O,08,72
AOK
CMD>

Common Initialization of the Module

If you have used an RN487x module for one of the examples in this project, or if you have used the module for some entirely different purpose, and you are about to configure the module for another example, it is possible that the module has some configuration that will conflict with the next intended use.

​The following steps should be taken before every example in this project:​

  • Erase any existing script.
  • Enable script processing.
  • Erase any existing service/characteristic definition.
  • Remove any special functions from the pin we use (P1_2, index 0A).
  • Reboot the module.

Use the previous appendix section to reach the module command shell. Then use the following command sequence to accomplish the necessary initialization:

CMD> WC
AOK
CMD> SR,0040
AOK
CMD> PZ
AOK
CMD> SW,0A,00
AOK
CMD> R,1
Rebooting

Linux Setup Required for Running Example Python Scripts

Hardware

The system running these scripts will of course need hardware that supports Bluetooth Low Energy (BLE). BLE was introduced in version 4, so if your Bluetooth hardware specifies a version below this, it will probably not work for these examples.

If you want to purchase a USB adapter for a workstation in order to try these examples, I suggest any adapter that employs the ​Qualcomm CSR8510​. One instance is available for purchase ​here​.

Software

This setup has been verified for Debian 10. It should be applicable for Debian-based distributions like Ubuntu. There are two components directly accessed by these examples that are not installed by default in Debian 10;

The Python module for accessing the Bluetooth stack. This component is available through the package management system, and is named ‘python-bluez’.

The Python module specifically for Bluetooth GATT calls; ‘gattlib’. This component is available from the Python official package index (via the ‘pip’ utility).

The ‘pip’ installation of ‘gattlib’ builds an ELF library. This process requires some tools and libraries, too.

Putting all of this together, a list of packages must be requested from the system package manager, followed by a single module request to ‘pip’. A script to complete these actions has been provided ​here​. If you choose to run the script, you will need to give it ‘execute’ permissions after download.

References

  1. GATT Services

Downloads

  1. Script to complete installation gattlib component.

Next Part

JLCPCP: 2USD 2Layer 5PCBs, 5USD 4Layer 5PCBs

You may have to register before you can post comments and get full access to forum.
User Name
Free Shipping for All PCB Assembly Order