Bluetooth is a very low cost and flexible way to add wireless communication to your projects. However, it can also be a bit tricky to set up. In this post we show you how to set up a Raspberry Pi with a USB Bluetooth dongle so that it can communicate with an Arduino using a Bluetooth serial module.
Once the set up is complete, we’ll have a new serial port on the Raspberry Pi that can be used to communicate with the serial Bluetooth module, either using a program such as Cutecom, or using one of the many serial programming libraries such as pySerial.
This tutorial is aimed at a Raspberry Pi running Raspbian, but it should work on other popular Linux distributions such as Ubuntu. To get a USB serial port set up on Windows, a good tutorial can be found here.
- Raspberry Pi with Raspbian installed (this tutorial may also work with other distributions)
- USB Bluetooth dongle
- Arduino, or an Arduino compatible device such as a Seeeduino
- A serial Bluetooth module
Preparing the Arduino/Seeeduino for Connection
To test out the Bluetooth serial connection we’ll use a Seeeduino attached to a Bluetooth serial module. First upload the following sketch to the Seeeduino. This program listens on the serial connection for 2 numbers, and then adds them together before sending them back over the serial connection.
Connect the two devices up as shown in the diagram below. These connections will power the Bluetooth serial module from the 5V line of the Seeeduino, and connect RX => TX and TX => RX. Whilst the Bluetooth serial module is connected to the UART lines of the Seeeduino, you won’t be able to program the Seeeduino, but you can still power it with a USB cable.
Setting up the USB Bluetooth Dongle and Pairing it with the Bluetooth Serial Module
Plug the USB Bluetooth dongle into the Raspberry Pi. Then open up a command line terminal and run the following commands
sudo apt-get update sudo apt-get install bluetooth bluez-utils blueman
Get the name of your USB Bluetooth dongle by running
It should be something like ‘hci0′
Now, ensuring that the Seeeduino is powered on, run the following command to find out the address of the serial Bluetooth module.
After a short delay, this should return the addresses of nearby Bluetooth devices. The Bluetooth serial module that we sell should be called something like ‘linvor’.
Before Bluetooth devices can communicate, they need to be paired. This can be done by running the following command
sudo bluez-simple-agent hci# xx:xx:xx:xx:xx:xx
where # is the number of your device (probably hci0) and xx:xx:xx:xx:xx:xx is the address of the serial Bluetooth module. After a pause, this program should ask you for the pin code of the Bluetooth module. By default, the pin for the module we sell is 1234.
At this point, we have 2 Bluetooth devices that can communicate with each other, but we need to set up a protocol called RFCOMM so that they can communicate over a serial connection.
For more detail: Talking to a Bluetooth Serial Module with a Raspberry Pi
Current Project / Post can also be found using:
- https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1832 ycRVeTkTuWsf9lSoGbBrL9CQGGVASlP6R1OE6__a1C_OMcmqhi0AqdGbDpvJKFC0 75c32bc61ba3ccf856e84fa518756b1fac3cb429&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
- https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1836 DFYee_3-VW8Seohxmt-FoFSbSP_3YPkLmnpjs_REFDUjFRemU0RHkxn7YmCLPB5o d14ec6e21fe14c0a41807cc88b1989dfcdcd00df&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme