not logged in | [Login]
The Bluetooth module HC05 is available in the Micro Python Store.
The physical pins of the UART buses are:
UART(4) is on XA: (TX, RX) = (X1, X2) = (PA0, PA1)
UART(1) is on XB: (TX, RX) = (X9, X10) = (PB6, PB7)
UART(6) is on YA: (TX, RX) = (Y1, Y2) = (PC6, PC7)
UART(3) is on YB: (TX, RX) = (Y9, Y10) = (PB10, PB11)
UART(2) is on: (TX, RX) = (X3, X4) = (PA2, PA3)
Connect the module to the pyboard as shown in the table below. Note: Connect the TX pin from the HC05 to the RX pin on the pyboard, and the RX pin from the HC05 to the TX pin on the pyboard.
pyb | hc05 |
---|---|
3V3 | VCC |
GND | GND |
RX | TX |
TX | RX |
No custom modules are required, use the UART module:
from pyb import UART
uart = UART(1, 9600) # init with given baudrate
uart.init(9600, bits=8, stop=1, parity=None) # init with given parameters
Then use the following to send the REPL to the UART you created above
pyb.repl_uart(uart)
Install some useful command line tools:
sudo apt-get install bluez-tools bluez-utils
Bluetooth - Set up new device - choose the device - Pin options '1234' - Next. Get the modules MAC address:
hcitool scan
Add the serial port by editing the file: /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind no;
device MAC address of your module;
channel 1;
comment "Serial Port";
}
Then connect it with:
sudo rfcomm connect 0
Watch it with:
screen /dev/rfcomm0
I had issues with the above running ubuntu 14.04, so I followed the following slightly different set of instructions which only needs the command line. This information was taken from: here
Determine the MAC address of your bluetooth module by using hcitool
2006 >hcitool scan
Scanning ...
00:14:01:21:27:67 HC-05
Determine the MAC address of your bluetooth adapter on the host, using bt-adapter
:
2005 >bt-adapter -l
Available adapters:
ubuntu-0 (58:91:CF:54:4A:EC)
Edit /etc/bluetooth/rfcomm.conf
#
# RFCOMM configuration file.
#
rfcomm0 {
# Automatically bind the device at startup
bind yes;
# Bluetooth address of the device
device 00:14:01:21:27:67;
# RFCOMM channel for the connection
channel 1;
# Description of the connection
comment "HC-05 module";
}
Create (or append to) the picodes file (this uses the MAC address of your host, from the bt-adapter
command above for cd, and the MAC address of your HC05 for the echo).
cd /var/lib/bluetooth/58:91:CF:54:4A:EC
sudo su -c "echo '00:14:01:21:27:67 1234' >> pincodes"
1234 is the default PIN that your HC05 comes with.
Restart the bluetooth service:
sudo /etc/init.d/bluetooth restart
Add your user to the dialout group:
sudo adduser dhylands dialout
logout and log back in. Check that your user belongs to the dialout group by using the id
command.
Now you should have /dev/rfcomm0 which is the host side serial port for talking to the HC-05.
Last edited by Bingyu Zhou, 2017-06-03 12:32:42