PHYS 351 Scientific Instrumentation Lab Fall 2019 Final Project
Download the Arduino library from: Adafruit LIS3DH Arduino
Or clone it with:
$ git clone https://github.com/adafruit/Adafruit_LIS3DH.git
You must also use the built in Arduino Sensor library.
Documentation for this product is available at: Adafruit LIS3DH Triple Axis Accelerometer Breakout
Download the library from: Adafruit Bluefruit SPI Arduino / Adafruit Bluefruit UART Arduino
Or clone it with:
$ git clone https://github.com/adafruit/Adafruit_BluefruitLE_nRF51.git
Documentation for these products is available at: Introducing the Adafruit Bluefruit SPI / Introducing the Adafruit Bluefruit UART
To write to the UART Friend you will also need to use the Arduino SoftwareSerial Library.
IMPORTANT: To send data on the UART Friend make sure the on board switch is in UART mode and not CMD mode.
Below is the connection diagram for the Bluefruit LE UART Friend and the LIS3DH 3-Axis Accelerometer.
When using Bluetooth LE on the Raspberry Pi, if the Bluetooth icon is not visible in the top right corner of the screen restart dbus:
$ sudo service dbus restart
$ systemctl status dbus.service
and you should see something like:
● dbus.service - D-Bus System Message Bus
Loaded: loaded (/lib/systemd/system/dbus.service; static; vendor preset: enabled)
Active: active (running) since Sat 2019-11-23 12:17:20 EST; 11s ago
Docs: man:dbus-daemon(1)
Main PID: 2285 (dbus-daemon)
Tasks: 1 (limit: 4915)
Memory: 956.0K
CGroup: /system.slice/dbus.service
└─2285 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --syst
Then use Bluetoothctl to turn bluetooth on, make the Raspberry Pi discoverable and scan for, pair, and connect to a device and see its UUID and connection information if you know its Mac address:
$ bluetoothctl
[bluetoothctl]# power on
[bluetoothctl]# agent on
[bluetoothctl]# default-agent
[bluetoothctl]# discoverable on
[bluetoothctl]# scan on
[bluetoothctl]# pair <device>
[bluetoothctl]# connect <device>
[bluetoothctl]# info <device>
This is the software used for bluetooth communication on the Raspberry Pi. There is not much documentation but the source code API is available here: BlueZ Source Code.
To install Bluez software follow the direction at: Installing Bluez on the Raspberry Pi
This is the python library for Bluetooth LE communication with BlueZ which is automatically installed with BlueZ in Python 2.7 on the Raspberry Pi. To install Bluepy in Python 3+ use the following commands (after installing BlueZ):
sudo apt-get install python3-pip libglib2.0-dev
sudo pip3 install bluepy
Also see Ian Harvey's instructions for installing Bluepy.
To add a the UART Friend as a peripheral make sure to use the "random" option when specifying the Bluetooth LE Address, like so:
from bluepy import btle
p = btle.Peripheral("XX:XX:XX:XX:XX:XX","random") # Use your correct address
The UART Friend has a base UART service UUID: 6e400001-b5a3-f393-e0a9-e50e24dcca9e. This has two characteristics: TX (0x0002 for transmit) and RX (0x0003 for receive). See Bluefruit UART Service for more information.
A great book on Bluetooth programming basics with section on using BlueZ in Python and C: An Introduction to Bluetooth Programming, Albert Huang
Also take a look at this example of bluetooth data transmission between Arduino and Raspberry Pi online: http://blog.whatgeek.com.pt/2015/09/bluetooth-communication-between-raspberry-pi-and-arduino/
Although we did not use it, this has almost the full capabilities of an Arduino Uno board, but is much smaller. See the documentation at: Adafruit Pro Trinket
To add the board to the Arduino IDE use the directions at Arduino 1.6x IDE Setup
For receiving bluetooth data from an Adafruit Bluefruit LE device on the Raspberry Pi download the Adafruit Bluetooth LE Python Library using:
$ sudo pip install Adafruit-BluefruitLE
Or clone it from gitHub:
$ git clone https://github.com/adafruit/Adafruit_Python_BluefruitLE.git
$ cd Adafruit_Python_BluefruitLE
$ sudo python setup.py install
Documentation for this is available online at: Bluefruit LE Python Library
For using Bluetooth in python download and install the PyBluez library from: PyBluez and follow the instructions for installation on Linux at PyBluez Documentation.
Or download and install it with:
$ pip install PyBluez
or for use with Python 3:
$ sudo apt-get install bluetooth libbluetooth-dev
$ sudo python3.7 -m pip install pybluez
or for BLE dependencies on Linux (just compatible with Python 2):
$ sudo apt-get install libboost-python-dev
$ sudo apt-get install libbluetooth-dev
$ pip install pybluez\[ble\]
which installs the header files. You might also need to do this for these modules as well:
$ sudo apt-get install libboost-thread-dev
$ sudo apt-get install libglib2.0-dev
$ sudo apt-get install python-dev
In addition to PyBluez, python has a socket library which can also be used: http://blog.kevindoran.co/bluetooth-programming-with-python-3/
Although we have not had any success using it, you can install Blueman the BlueZ GUI application using:
$ sudo dpkg --configure bluez
$ sudo apt-get install bluez blueman
and then reboot the Raspberry Pi with:
$ sudo reboot