Communication between Raspberry Pi and multiple Arduinos via Bluetooth Low Power (BLE)


  • Arduino (s)
  • cc2541 – BLE module(s) for Arduino
  • Raspberry Pi
  • Bluetooth 4.0 USB dongle for raspberry pi



Arduino Code can be seen in:


The main thread of the program keeps scanning the existing unconnected Bluetooth devices using the Scanner object.

If the devices have address existing in the bt_arrs array, we start a connection with it by initiating the Peripheral object and add it into the connections array.

To avoid the searching being blocked by the communication of each connection, every connection will be handled by a separate ConnectionHandler Thread.

Within the connection thread, the communications between the Pi and the Arduino(s)  are handled by using waitForNotification and writeCharacteristic function of the bluepy library.

Why do we write data to handler 37?:

By looking at the documentation of the BLE module, we know that both data sending from and to the BLE module are stored in the same places (20 Bytes). Therefore by observing the data sent from the BLE module, we know the data should be written to Handler 37.

The output below is showing 1 Arduino with 2 BLE modules and the Arduino is doing:

  1. send count via BLE modules #0
  2. count ++
  3. send count via BLE modules #1
  4. count ++
  5. and loop


From the output of the program, we can see

  1. It is continuously scanning devices
  2. It is able to communicate with Connection 0 & Connection 1.
  3. All notifications are from handler 37.


  1. Hello Anthony, thank you for posting this project! I’m currently trying to make my raspberry Pi to communicate with some iBeacons (and change some parameters, such as Minor, Major,etc.).
    To starting understand how the communication works, I tried to run the code of this project in my raspberry, after installing bluepy, and I’m getting the following error:

    pi@raspberrypi:~ $ sudo python
    Connected: 0
    Traceback (most recent call last):
    File “”, line 33, in
    devices = scanner.scan(2)
    File “/home/pi/Desktop/bluepy/”, line 631, in scan
    File “/home/pi/Desktop/bluepy/”, line 568, in start
    File “/home/pi/Desktop/bluepy/”, line 210, in _startHelper
    File “/usr/lib/python2.7/”, line 710, in __init__
    errread, errwrite)
    File “/usr/lib/python2.7/”, line 1335, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory

    Do you have any clue about what could be causing this error?
    Thank you.


    1. I have not tested on a Pi 3b.
      I wrote this post when I was doing a course project, at the end, I was able to connect 4 Arduino from a Pi 2.


    1. Hi Reevid. Sure you can send messages from the Pi to the Arduinos with connection.writeCharacteristic. Note that, I have used a multi-threading approach, the connection(one Ardiuno) variable actually comes from a list of connections (many Ardiuno).


  2. Hello. I wonder if you can help me. I have a code using bluepy.btle. The device that sends information through a serial / bluetooth module (at-09) masters sensor data at a speed of 9600 bits / s to my computer that is able to receive this information and save it to a file. Until then, OK! The problem is that since the amount of data is too large, a baud rate of 9600 bits / s generates a bottleneck in data transmission, and it takes a long time for the whole file to be sent. So I made the device that sends the information through the serial / bluetooth module send information at a higher speed, at 38400 bits / s. The problem is that the method that receives the information via bluetooth (handleNotification (self, cHandle, data)) can not keep up with, and generates a kind of “sub-sampling” of the data, so that not all of them arrive correctly. In this way, I believe that this problem can occur because of the following problem: The buffer of the receiving method is populated quickly, and in this way, the values ​​are being overwritten before going to main memory. Would you know how to solve this, if that’s the case, if you ever had a problem or know how to solve it? I did not find anything about this problem in the forums. Thank you so much.

    Liked by 1 person

    1. Hi, I got your point. Unfortunately, I have only worked on small data. I haven’t tested on the speed. I have done some tricks (start string, end string) to avoid messing up messages from different devices.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s