I am going to test the connection of a serial Bluetooth module to my Mac laptop. Serial data will be provided to the module through a Teensy 2 used as a USB-to-Serial adapter.
Soldering the module on a breakout board
The difficulty is to correctly align all the module pins to the breakout pads. The module is so light that it can moves just because of the solder surface tension.
Two rows of header are added to fit in a prototyping breadboard.
Teensy 2 USB-to-Serial profile
I use the USBtoSerial project from LUFA 101122.
I already covered how to compile this project for the original Teensy in this previous post (Testing the LUFA USB Serial with GPS data). I apply the following modifications to the makefile:
MCU = atmega32u4 F_CPU = 16000000
Here is the binary: Teensy2-USBtoSerial.hex
To connect to the virtual serial port on a Mac:
$> sudo cu –s 9600 –l /dev/cu.usbmodemXXXX
A quick loopback test (direct wire from TX to RX) confirms that the profile is correctly working.
Useful to exit cu: ~.
Connections between the Teensy 2 and the BT module
The TX pin of the BT module is connected to the RX pin of the Teensy 2, and the RX pin on the TX pin.
My Teensy 2 board has been patched with a 3.3V regulator (see Converting the Teensy2 to 3.3V). I will use it to power the BT module.
The TX pin of the BT module is connected to the RX pin of the Teensy, and the RX pin on the TX pin.
Two leds are connected on PIO8 and PIO9 to display the status of the BT link.
The PIO11 pin is used to select the boot mode:
- High => Command/Response mode where you can issue AT command to setup the module.
- Low => Slave or master automatic operation.
Module configuration
I connect the PIO11 pin to the 3.3V rail. In this mode, the baud rate is 38400.
I open a cu session in the terminal and communicate with the BT module over its serial interface:
$>sudo cu –s 38400 –l /dev/cu.usbmodemXXXX Connected. AT OK OK OK OK
The module sends the OK response repeatedly. Sending Ctrl-C can stop it. Then you can enter another commands.
AT+VERSION? +VERSION:2.0-20100601 OK AT+NAME? +NAME:HC-05 OK AT+ADDR? +ADDR:11:3:252009 OK AT+UART? +UART:9600,0,0 OK
We can see that the module is currently configured for 9600 bauds operations with 1 stop bit, no parity.
I speedup the baudrate to 115200 bauds.
AT+UART=115200,0,0 OK AT+UART? +UART:115200,0,0 OK
I also change the role to slave-loop. In this mode, the module sends back all data it receives over the BT link. It is useful to check that the module can correctly receive and send data over the BT link before connecting it to your system.
AT+ROLE=2 OK AT+ROLE? +ROLE:2 OK
Now I power up the module with the PIO11 connected to GND to boot in autoconnect mode.
Pairing with a Mac
The connection of Bluetooth devices is handled by the System Preferences/Bluetooth panel.
The connection fails because the default passkey of the module is 1234. It can be changed with the AT+PSWD command.
The module is now successfully paired with the Mac but currently not connected.
It is recognized as a virtual serial port and corresponding devices are automatically created in the /dev directory:
$> ls /dev/*HC* /dev/cu.HC-05-DevB /dev/tty.HC-05-DevB
Slave-loop connection
I can now connect to the BT device and use it as a classic serial interface. In slave-loop mode, the characters are echoed back to the terminal.
$> sudo cu –s 115200 –l /dev/cu.HC-05-DevB Connected. ABCDEFGHIJKLM
The status of the bluetooth connection is reflected in the System Preferences panel.
Slave mode
I switch to the command/response mode and change back the role to slave:
AT+ROLE=0 OK AT+ROLE? +ROLE:0 OK
In this mode, the BT module acts as a full duplex serial interface. The data received over the BT link are forwarded to the its TX pin, while the RX pin incoming data are sent over the BT link.
So to test the connection I open two cu sessions. One is connected to the BT module, the other one to the Teensy 2 serial emulation. As the 2 devices serial pins are connected together, I am able to send characters on one session and receive them on the other sessions.
The first window displays the connection to the Teensy 2. The second window displays the connection to the BT module.










Hi, I have the same BT module, but I’m having trouble to enter command mode.
I connect the PIO11 to 3,3 and turn on the power, the led blinks slowly but I can’t find the BT module through the computer.
If i dont connect the PIO11 i can connect to de module and receive data.
Can you help me pls?
I’m going crazy :S
Thanks in advance
Hi,
the command mode is only accessible when there is no bluetooth connection active. That is, connect PIO11 to +3.3 V, reset (switch off/on) and the you can enter command mode via the RxDT/TxD pins. Commands via BT are not possible. In command mode no BT connection is possible.
Hope that helps
Bernie
@Bernie
Thanks for the quick answer!
@Romeu
Like Bernie said, in the command mode you control the BT module using its serial port.
In my test, it is done through from my laptop through the Teensy2 USB-to-Serial connection.
Great Bernie and Chief.Now it makes more sense
Now I’m trying to use arduino to send the comands
Hi I’m trying too… but I see response only for AT+NAME? and AT+VERSION?…
((
The eco test and the bluetooth trasmission is OK
Do you think there is any logical reason for this?
Thank you
I’have a problem…
It works good but response ONLY for AT+NAME and AT+VERSION…
All the oters command not give me mothing…
Have you any idea ?
Thank you
Hi Alessandro,
It seems strange to only have the NAME and VERSION working… Maybe a limitation of the firmware of your module ?
What responses do you get for the NAME and VERSION commands ?
Regards,
Mathieu
Hi Mathieu and thank you for the response….
When i send
AT the response is OK
AT+NAME response is OKsetname
AT+VERSION response is OKlinvorV1.5
for the other command… nothing !!!
If you have any suggest…
Best Regards
Alessandro
Hi Alessandro,
My firmware version (2.0-20100601) does not match yours. Sorry I can not be of much help.
BR
Mathieu
Refer to : http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry
Note: below commands can be used with the module but only with software version Linvor v1.5.
Command Description
Options
Response
AT+VERSION Returns the software version of the module
OKlinvorV1.5
AT+BAUDx Sets the baud rate of the module
The command AT+BAUD8 sets the
baud rate to 115200
1 >> 1200
2 >> 2400
3 >> 4800
4 >> 9600 (Default)
5 >> 19200
6 >> 38400
7 >> 57600
8 >> 115200
9 >> 230400
OK115200
AT+NAMEOpenPilot Sets the name of the module
Any name can be specified up to 20 characters
OKsetname
AT+PINxxxx Sets the pairing password of the device Any 4 digit number can be used, the default
pincode is 1234
OKsetPIN
AT+PN Sets the parity of the module
AT+PN >> No parity check
OK None
Hi Sombat,
Thanks for the additional information!
BR
Mathieu
@The Chief SHeep.
I too am in the same boat as you. I got my board from deal extreme. Great little board. But I need to change the baudrate.. Which apparently in my version of the firmware is not possible. Did you ever get it working?
Scratch that! I got it. Copy and paste your commands into Coolterm or putty. In coolterm I leave it in raw mode. It works! AT+BAUD7 will set it to 57600. You have to disconnect rightaway now and re-connect to issue any other commands at your new rate.
I Have one of these units, i can Hyper Terminal it at the default BAUD rate.. but when i change it makes no difference when i have PIO11 held high.. i can see anything at the new BAUD rate of 9600.. i also (in any ROLE) cannot pickup the Bluetooth unit with an iPhone (with PIO11 low in normal mode) HELP!!? – i think there is a little confusion that commands can only be sent to the unit when the PIO11 line is High.. and Low the Module is in Normal operating mode..
Sorry correction to the above.. “i CANT see anything at the new BAUD rate of 9600″ is the BAUD rate you specify only applicable when running in Normal mode (PIO11 low) ? .. i just find it very strange how i cannot detect the Module with an iPhone running under any MODE.. is there some config im missing?
I’ve read elsewhere that these unit’s AT commands need to be terminated with “Newline” ie. CR LF
Many terminal programs default is just Return (CR).
I am waiting for my module to arrive via the slow boat from China.
Cheers