A Bluetooth RN-42 Demoboard for experimentation

By on April 16, 2013

 

We wanted to create a basic tool to experiment with the RN-42 Bluetooth module so we created obviously a Demoboard.

0628_11

 

The RN-42 Hardware module

7100-FT1018M

The RN-42 is a Bluetooth 2.1, Class 2 module with a PCB integrated antenna with a communication capability of about 3 Mbps. The version with the integrated antenna has a theoretical transmission range of about 15/20 meters.

 

The module supports both SPP (Serial Port Profile) and HID (Human Interface Device) operation mode and implements an effective mechanism for reducing consumption . In the best conditions this consumes about 26uA although under normal operations this increases a little bit. In the SPP mode, baud rate for slave devices is 240Kbps (300 Kbps for the master): more than enough for most of the applications bluetooth comes handy.

 

RN-42 has a simple UART hardware and software interface that can be used for connection to any microcontroller for embedded systems. Also by integrating an internal Bluetooth software stack, it does not require connection to particularly powerful MCUs.

 

Software Form RN-42

From the software point of view, the module is managed through appropriate commands sent through the UART interface. 

Once switched on, the module starts in Data configuration; to enter the Command setup mode you first need to send $ $ $ characters. To exit it send the same  characters, but followed by <cr>. 

The module can operate in six different bluetooth modes, selected by the SM command:

 

  1. Slave Mode (SM command, 0): the default mode in which the module is still waiting for connection requests it can accept or reject (cannot initiate connections on its own initiative);

 

  1. Master Mode (SM command, 1): the module can initiate connections on its own but cannot be localized by other devices;

 

  1. Trigger Master Mode (SM command, 2): whenever a character is received on the local UART, it automatically connects to a slave who had been previously paired. The connection remains active for a programmable interval between 1 and 255 seconds

 

  1. Auto-connect (Master Mode) (SM command, 3): at power up, the module automatically connects to a slave that has been previously paired. The connection remains active all the time while the module is powered; in the case the communication is lost the module automatically attempts to reconnect to the same slave;

 

  1. Auto-connect (DTR Mode) (SM command, 4): similar to the previous mode except that you can start and close the connection by pin PIO6.

 

  1. Auto-connect ANY Mode (SM command, 5): similar to the previous mode, except that every time PIO6 changes status is a new slave pairing procedure is started.

 

Bluetooth Demoboard

0628_Schema

To experiment with RN-42 you just need to create an RS232 connection between a PC and the card, open a serial terminal (Windows’ HyperTerminal will do) and apply a standard configuration to the serial port (9600 bps, no parity, 8 data bits, 1 stop bit and no flow control). 

Typing the commands characters in the terminal those will be sent to the module and then you can verify the execution of the same. 

Figura_02

In figure we show the RN-42 response to two of the basic commands ($ $ $  and <cr>). As mentioned above these commands allow you to switch from data mode to the command mode and vice versa (the module responds with CMD and END respectively.)

Figura_03

In figure we show the RN-42 answer to the D and E reading configuration command.

Based on this starting point you can try to send all supported commands and verify how the various responses received change the module behavior.

0628_Silk

 

Slave RN-42 with Android Connection

As a first example of an application of the new module, we’ll show you how to configure the RN-42 in slave mode and how to make a bluetooth connection with android software. With regards to the hardware we use the bluetooth demoboard plus a RN-42 sockets, on the smartphone side we use BluetoothChat software   - a bluetooth demo software supplied with the standard development environment for Android.

 Figura_04

In figure we show the example of source software in the development environment. The only change to be made ​​in the source is in the BluetoothChatService.java file where MY_UUID variable that shall be set to 00001101-0000-1000-8000-00805F9B34FB (note that his variable indicates the type of Bluetooth device to connect with: the original source code sets this to generic phones while our software will be configured for embedded devices.)

 

At this point we setup the RN- 42 module as a slave bluetooth device; from the terminal we send the appropriate commands sequence:

 

  • “$ $ $” (command mode selection)

  • “SF, 1 <cr>” (software reset)

  • “SM, 0 <cr>” (set to slave mode),

  • “SN, RN-42 Bluetooth <cr>” (setting bluetooth name)

  • “SP, 1234 <cr>” (setting Bluetooth PIN)

  • “R, 1 <cr>” (reboot)

 

Figura_05

 Figura_06

At this point in time we run the smartphone software and, by using the “Connect to device” menu item we can select the device to connect with. After successfully connecting, the text field at the bottom of the  page, can be used to send the characters to the bluetooth module (and then displayed on the screen via serial terminal software). 

Figura_08

Figura_09

 

Conversely, by typing commands on the serial terminal, those will be sent by the RN-42 module to the smartphone and then displayed. 

 

RN-42 as Master and finding Slave

After showing how it is possible to use the RN-42 Bluetooth as a slave and manage communication requests from the outside we now look at the opposite situation. In this configuration the module is the master and can be used to detect the presence of nearby Bluetooth slaves

 

The operation that allows a master to scan the radio channel is called “Inquiry Scan” and corresponds to the “I<,time>,<COD>” command string on RN-42.

 

Let’s start the example by programming the RN-42 module as a master device, thanks to the sequence:

 

  • “$ $ $” (command mode selection)

  • “SF, 1 <cr>” (software reset)

  • “SM, 1 <cr>” (set to master mode),

  • “SN, RN-42 Bluetooth <cr>” (setting bluetooth name)

  • “SP, 1234 <cr>” (setting Bluetooth PIN)

  • “R, 1 <cr>” (reboot)

 Figura_12

Then, again from the serial terminal, select again the Command Mode ($ $ $) and send the string “I<cr>” to request scanning. As you can see, three bluetooth slaves were detected in our coverage area, an LG-P500 (smartphones) belonging 5A020C code class, an L6-imode (phone) from the 500204 code class Finally, the one named Giovanni (our neighbor’s phone, now you’re famous!) belonging to code class 5A020C.

As you can imagine, Master mode can be used to create for example an RFID detection system with activation and deactivation of certain functions depending on the devices.

 

 

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.