- 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:
- send count via BLE modules #0
- count ++
- send count via BLE modules #1
- count ++
- and loop
From the output of the program, we can see
- It is continuously scanning devices
- It is able to communicate with Connection 0 & Connection 1.
- All notifications are from handler 37.