Testando comandos Bluetooth AT

Testing Bluetooth AT commands

Bluetooth is a popular wireless technology standard designed for exchanging data over short distances. Bluetooth is so common that it is now part of smartphones and present in many embedded devices. Many wearable devices also use Bluetooth to pair with their accessories or co-devices. The Bluetooth interface uses UHF radio waves in the 2.4 GHz to 2.485 GHz ISM band. It was invented by telecommunications provider Ericsson in 1994 and developed by the Bluetooth Special Interest Group. A Bluetooth connection has a range of 10M to 100M.
Making embedded devices Bluetooth-enabled is a popular trend. The HC-05 Bluetooth module is a commonly used and widely available Bluetooth module that can be added to an embedded project to make it Bluetooth enabled. The module can function as both Master and Slave. The module connects to a microcontroller via serial communication. It is basically a 2.4GHz radio transceiver with 3Mbps modulation enhanced V2.0+ data rate. The module can operate in two modes –
1. Automatic connection working mode
2. Request response working mode
In automatic working mode, the module can work in any of the three functions – Master, Slave and Loopback. In this mode, the module follows the standard path to establish connection and exchange data. In request response mode, the user can set control parameters by sending AT commands. To enter AT mode, the 34th pin of the module needs to be connected to the power supply.
The modules have six commonly used pins, in addition to which there are programmable input/output pins and pins for communication via UART, SPI, USB and synchronous PCM. The 34th pin is a programmable input/output pin designated as the key pin.
To configure the module in AT mode, the key pin of the module needs to be connected to the microcontroller. It must initially be set to logic LOW and, once the module is turned on, it must be set to logic HIGH to enter AT mode. If the switch pin is initially logic HIGH, the baud rate for serial communication with the module will be set to 38,400 bits per second, even before the module is ready to enter the request response work mode. The desired baud rate for module initialization is 9600 bits per second and is set to the value when the switch pin is set HIGH after module power.
In this project, Arduino Pro Mini is used to pass AT commands to the Bluetooth module. The Arduino board connects to the Bluetooth module and virtual serial port of a desktop computer. AT commands are passed from a hyperterminal application to the Arduino Pro Mini. The Arduino board writes these commands to the Bluetooth module. Responses from the Bluetooth module are read serially and passed on to the hyperterminal application on the desktop.
The Arduino sketch simply creates and opens two serial communication ports for exchanging data between the Bluetooth module and the desktop computer. Arduino code is written in the Arduino IDE and written to the board using the AVR Dude.

Required components –

1. Arduino ProMini
2. HC-05 Bluetooth Module
3. Desktop or Laptop Computer
4. USB cable

Required software tools –

1. ArduinoIDE
2. Any Hyper Terminal Desktop application such as Arduino Serial Monitor

Circuit Connections –

Sistema de automação residencial baseado na Internet
Figure 1: Arduino-based Bluetooth AT command test project prototype
The Arduino Pro Mini manages the exchange of data between the serial application on the desktop computer and the Bluetooth module. The circuit is assembled as follows –
Power supply – The circuit is powered by a battery that directly powers the Arduino board and the Bluetooth module.
HC-05 Bluetooth Module – The HC-05 Bluetooth module is a serial port protocol module. Operates on the 2.4 GHz ISM band with V2.0 + EDR (Enhanced Data Rate). It can work in Master and Slave modes. The Bluetooth module has six pins – Enable, VCC, Ground, Transmit Data (TxD), Receive Data (RxD) and State. The Enable and State pins are unused and therefore not connected to the circuit. The VCC and Ground pins are connected to common VCC and Ground. The TxD and RxD pins of the module are connected to pins 10 and 11 of the Arduino Pro Mini respectively. These connections are summarized in the table below –
Tabela listando conexões de circuito entre o módulo Bluetooth HC-05 e o Arduino Pro Mini
Fig. 2: Table listing the circuit connections between the HC-05 Bluetooth module and the Arduino Pro Mini
In addition to these connections, the 34th pin of the module is connected to pin 9 of the Arduino Pro Mini.
Desktop Computer – The computer is connected to the Arduino board via a USB cable and transfers serial data to the board via virtual serial communication using a hyperterminal application.

How the project works –

The project device receives the AT commands entered by the user of the hyperterminal application. Commands are read serially by virtual serial communication and passed to the Bluetooth module. The Bluetooth module responds to AT commands and the responses are again read serially and transferred to the desktop application.
The HC-05 Bluetooth module supports the following AT commands –
Y.No Command Response Parameter
1 AT THE OK
two AT+RESET OK
3 AT+VERSION? +VERSION: OK Parameter: firmware version
4 AT+ORGL OK
5 AT+END? +ADDR: OK Parameter: Bluetooth module address
6 AT+NAME= OK Parameter: Bluetooth module name (Default: HC-05)
AT+NAME? +NAME: OK (/FAIL) Parameter: Bluetooth module name (Default: HC-05)
7 AT+RNAME? 1. +NAME: OK 2. FAIL Param1,Param 2: the address of the Bluetooth device
8 AT+ROLE= OK Parameter: 0- Slave 1-Master 2-Slave-Loop
AT+ PAPER? +ROLL: OK Parameter: 0- Slave 1-Master 2-Slave-Loop
9 AT+CLASS= OK Parameter: Device Class
AT+ CLASS? 1. +CLASS: OK 2. FAIL Parameter: Device Class
10 AT+IAC= 1. OK 2. FAIL Parameter: GIAC (Default: 9e8b33)
AT+IAC +IAC: OK Parameter: GIAC (Default: 9e8b33)
11 AT+INQM= , , 1. OK 2. FAIL Parameter: 0——inquiry_mode_standard 1——inquiry_mode_rssi Param2: Maximum number of Bluetooth devices to respond to Param3: Timeout (1-48: 1.28s to 61.44s)
AT+INQM? +INQM: , , OK Parameter: 0——inquiry_mode_standard 1——inquiry_mode_rssi Param2: Maximum number of Bluetooth devices to respond to Param3: Timeout (1-48: 1.28s to 61.44s)
12 AT+PSWD= OK Parameter: PIN code (default 1234)
AT+PSWD? +PSWD: OK Parameter: PIN code (default 1234)
13 AT+UART= , , OK Param1: Baud Param2: Stop bit Param3: Parity
AT+UART? +UART= , , OK Param1: Baud Param2: Stop bit Param3: Parity
14 AT+CMODE= OK Parameter: 0 – connects fixed address 1 – connects any

address 2 – slave loop

AT+ CMODE? + CMODE: OK Parameter: 0 – connects fixed address 1 – connects any address 2 – slave-Loop
15 AT+BIND= OK Parameter: Fixed address (default 00:00:00:00:00:00)
AT+ CONNECT? + TURN ON: OK Parameter: Fixed address (default 00:00:00:00:00:00)
16 AT+POLAR= OK Param1: 0- PIO8 low trigger LED 1- PIO8 high trigger

Param2 LED: 0- PIO9 low drive LED 1- PIO9 high drive LED

AT+POLAR? + POLAR= , OK Param1: 0- PIO8 low drive LED 1- PIO8 high drive LED Param2: 0- PIO9 low drive LED 1- PIO9 high drive LED
17 AT+PIO= , OK Param1: PIO number Param2: PIO level 0- low 1- high
18 AT+IPSCAN= , , , OK Param1: Query time interval

Param2: query duration Param3: paging interval Param4: call duration

AT+IPSCAN? +IPSCAN: , , , OK Param1: query time interval Param2: query duration Param3: paging interval Param4: call duration
19 AT+SNIFF= , , , OK Param1: Maximum time Param2: Minimum time Param3: Retry time Param4: Timeout
AT+ SNIFF? +SNIFF: , , , OK Param1: Maximum time Param2: Minimum time Param3: Retry time Param4: Timeout
20 AT+SENM= , 1. OK 2. FAIL Parameter1:

0——sec_mode0+off

1——sec_mode1+ non_secure

2——sec_mode2_ service

3—— ink sec_mode3_l

4——sec_mode_unknown

Parameter2:

0——hci_enc_mod e_off

1——hci_enc_mod e_pt_to_pt

2——hci_enc_mod e_pt_to_pt_and_b cast

AT+SENM? +SENM: , OK Parameter1:

0——sec_mode0+off

1——sec_mode1+ non_secure

2——sec_mode2_ service

3—— ink sec_mode3_l

4——sec_mode_unknown

Parameter2:

0——hci_enc_mod e_off

1——hci_enc_mod e_pt_to_pt

2——hci_enc_mod e_pt_to_pt_and_b cast

21 AT+PMSAD= OK Parameter: Authenticated device address
22 AT+ RMAAD OK
23 AT+FSAD= 1. OK 2. FAIL Parameter: Device address
24 AT+ADCN? +ADCN: OK Parameter: Device Count
25 AT+MRAD? +MRAD: OK Parameter: Address of the newly authenticated device
26 AT+ STATUS? + STATUS: OK Parameter: “INITIALIZED” “READY” “STOPABLE” “PAIRED” “QUERY” “CONNECTING” “CONNECTED” “DISCONNECTED” “NUKNOW”
27 AT+INIT 1. OK 2. FAIL
28 AT+INQ +INQ: , , …. OK Param1:Address Param2: Device Class Param3: RSSI Signal Strength
29 AT+INQC OK
30 AT+PAR= , 1. OK 2. FAIL Param1:Device address Param2:Timeout
31 AT+LINK= 1. OK 2. FAIL Parameter: Device address
32 AT+DISCO 1. +DISC:SUCCESS OK 2. +DISC:LINK_LOSS OK 3. +DISC:NO_SLC OK 4. +DISC:TIMEOUT OK 5. +DISC:ERROR OK Parameter: Device address

33 AT+ENSNIFF= OK Parameter: Device address
34 AT+ EXSNIFF = OK Parameter: Device address

Fig. 3: Table listing the AT commands of the HC-05 Bluetooth Module and their response

During testing of the Bluetooth module, the following commands were passed for which the response given in the table below was received.
Tabela listando codificação de cores para terminais do servo motor
Fig. 4: Circuit diagram of Arduino-based Bluetooth AT command test project
These responses were observed in the Hyper Terminal application. If responses are not received in the desktop application, the circuit connections must be checked and the transmission rate must be verified. During testing, it was observed that the baud rate initially needs to be set to 9,600 bits per second, but later needs to be set to 38,400 bits per second to execute AT commands.
Check out the Arduino code to learn how the Arduino board manages serial data between the desktop and the Bluetooth module.

Programming guide –

To enable virtual serial communication, SoftwareSerial.h needs to be imported. A Software serial type object is instantiated and mapped to pins 10 and 11 of the Arduino.
#include
SoftwareSerial mySerial(10, 11); //RX,TX
The setup function is called and the baud rate for communicating with the PC is set to 9600 bits per second. Pin 9 which is connected to the 34th pin of the Bluetooth Module is configured for digital output and set to logic HIGH using the pinMode and digitalWrite methods. Some initial messages are sent serially to the hyperterminal application and the software serial port baud rate is set to 38,400 bits per second for communication with the Bluetooth module.
empty configuration {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println(“Engineers Workshop:”);
Serial.println(“Enter AT commands:”);
mySerial.begin(38400);
}
The loop function is called in which the response from the Bluetooth module is checked and, if available, is written to the serial port. Likewise, if any desktop AT commands are available, they will be read and written to the Bluetooth module.
Note: Get the full code in the code section.
This completes the Arduino sketch for the Bluetooth module test project. Take a computer, assemble the circuit, start a hyperterminal application and get your hands dirty. It's time to test.

Project source code

###

 //Program to
 #include
 SoftwareSerial mySerial(10, 11); // RX, TX
 void setup {
 Serial.begin(9600);
 pinMode(9,OUTPUT); digitalWrite(9,HIGH);
 Serial.println("Engineers Garage:");
 Serial.println("Enter AT commands:");
 mySerial.begin(38400);
 }
 void loop
 {
 if (mySerial.available )
 Serial.write(mySerial.read );
 if (Serial.available )
 mySerial.write(Serial.read );
 }



###

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.