Help Center
  • FAQ
    browse most common questions
  • Live Chat
    talk with our online service
  • Email
    contact your dedicated sales:
  • Call Us
    9:00 - 18:00, Mon.- Fri. (GMT+8)
0

Bluetooth RN-42 Demoboard

Published on 2/18/2017 9:04:50 AM

Description

<style>.e_editor{font:14px/24px Arial,'microsoft yahei','Times New Roman','b8bf53';}.e_editor div,e_editor p,e_editor td,e_editor th,e_editor li{font-weight:inherit;font-size:inherit;font-style:inherit;font-family:inherit;}.e_editor ul{margin:-10px 0 20px;}.e_editor li{padding:5px 0;}.e_table{width:96%;border-collapse:collapse;empty-cells:show;}.e_table th,.e_table td{padding:5px;border:2px solid #eee;}.e_img{padding:10px 0;text-align:center;}.e_p{line-height:20px;padding:0 0 20px;text-indent:0em;}</style> <div class="e_editor"> <div class="e_p"> We wanted to create a basic tool to experiment with the RN-42 Bluetooth module so we created obviously a Demoboard. </div> <strong>The RN-42 Hardware module</strong> <div class="e_p"> 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. </div> <div class="e_p"> 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. </div> <div class="e_p"> 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. </div> <strong>Software Form RN-42</strong> <div class="e_p"> From the software point of view, the module is managed through appropriate commands sent through the UART interface.<b> <b></b></b> </div> <div class="e_p"> 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 &lt;cr&gt;.<b> <b></b></b> </div> <div class="e_p"> The module can operate in six different bluetooth modes, selected by the SM command: </div> <ol> <li> <div class="e_p"> 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); </div> </li> </ol> <ol> <li> <div class="e_p"> Master Mode (SM command, 1): the module can initiate connections on its own but cannot be localized by other devices; </div> </li> </ol> <ol> <li> <div class="e_p"> 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 </div> </li> </ol> <ol> <li> <div class="e_p"> 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; </div> </li> </ol> <ol> <li> <div class="e_p"> Auto-connect (DTR Mode) (SM command, 4): similar to the previous mode except that you can start and close the connection by pin PIO6. </div> </li> </ol> <ol> <li> <div class="e_p"> 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. </div> </li> </ol> <strong>Bluetooth Demoboard</strong> <div class="e_p"> 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).<b> <b></b></b> </div> <div class="e_p"> Typing the commands characters in the terminal those will be sent to the module and then you can verify the execution of the same. </div> <div class="e_p"> In figure we show the RN-42 response to two of the basic commands ($ $ $ and &lt;cr&gt;). 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.) </div> <div class="e_p"> In figure we show the RN-42 answer to the D and E reading configuration command. </div> <div class="e_p"> Based on this starting point you can try to send all supported commands and verify how the various responses received change the module behavior. </div> <strong>Slave RN-42 with Android Connection</strong> <div class="e_p"> 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. </div> <div class="e_p"> 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.) </div> <div class="e_p"> At this point we setup the RN- 42 module as a slave bluetooth device; from the terminal we send the appropriate commands sequence: </div> <ul> <li> <div class="e_p"> “$ $ $” (command mode selection) </div> </li> <li> <div class="e_p"> “SF, 1 &lt;cr&gt;” (software reset) </div> </li> <li> <div class="e_p"> “SM, 0 &lt;cr&gt;” (set to slave mode), </div> </li> <li> <div class="e_p"> “SN, RN-42 Bluetooth &lt;cr&gt;” (setting bluetooth name) </div> </li> <li> <div class="e_p"> “SP, 1234 &lt;cr&gt;” (setting Bluetooth PIN) </div> </li> <li> <div class="e_p"> “R, 1 &lt;cr&gt;” (reboot) </div> </li> </ul> <div class="e_p"> 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). </div> <div class="e_p"> Conversely, by typing commands on the serial terminal, those will be sent by the RN-42 module to the smartphone and then displayed. </div> <strong>RN-42 as Master and finding Slave</strong> <div class="e_p"> 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 </div> <div class="e_p"> The operation that allows a master to scan the radio channel is called “Inquiry Scan” and corresponds to the “I&lt;,time&gt;,&lt;COD&gt;” command string on RN-42. </div> <div class="e_p"> Let’s start the example by programming the RN-42 module as a master device, thanks to the sequence: </div> <ul> <li> <div class="e_p"> “$ $ $” (command mode selection) </div> </li> <li> <div class="e_p"> “SF, 1 &lt;cr&gt;” (software reset) </div> </li> <li> <div class="e_p"> “SM, 1 &lt;cr&gt;” (set to master mode), </div> </li> <li> <div class="e_p"> “SN, RN-42 Bluetooth &lt;cr&gt;” (setting bluetooth name) </div> </li> <li> <div class="e_p"> “SP, 1234 &lt;cr&gt;” (setting Bluetooth PIN) </div> </li> <li> <div class="e_p"> “R, 1 &lt;cr&gt;” (reboot) </div> </li> </ul> <div class="e_p"> Then, again from the serial terminal, select again the Command Mode ($ $ $) and send the string “I&lt;cr&gt;” 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. </div> <div class="e_p"> 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. </div> </div>

184

comment

All comments

STEFAN

5735

0

184

Go to Order My Own PCB

Rules about cashback: 1. Valid time: ALLPCB cashback activity will end on April 1st. 2. Capped amount: The capped amount of cashback for each account is $5,000. Each order can get a maximum of $2,000 cashback. That means every author can get $5,000 max. 3. Cashback range: The cashback activity only covers the corresponding PCB order. The order amount for other combined payment products will be invalid. 4. Clicking your own promotional link will be invalid. The same email address, shipping address, contact information, and phone number are all recognized as the same account. 5. ALLPCB has the final interpretation right of the cashback activity.

ALLPCB will donate 2% to the author for this promotion link.

Other Projects

Home / Industrial Automation low Cost with Arduino an ESP01

2460

0

314

Alternate Text josemarjr