This projects uses the on board Bluetooth module of a Raspberry Pi to control a motor
NOTE: The Raspberry Pi can be any model as long as there is a bluetooth module. I just used a Raspberry Pi 3 model B I had laying around, so thats what I linked.
This program should work cross platform but I ran this on Debian GNU/Linux 11 (bullseye) so the following steps reflect that setup process.
- Grab the latest BlueZ package link from the offical website
- Adjust the following code snippet to direct to the link copied from above
cd ~
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.66.tar.xz
tar xvf bluez-5.66.tar.xz
cd bluez-5.66
- Install all dependencies
sudo apt-get update
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
- Configure BlueZ and make sure it finishes with no errors. If there are errors then most likely there is a dependacy missing and needs to be installed
./configure --enable-library
- Make and Install BlueZ
make
sudo make install
- Enable Bluetooth service to run on boot
sudo systemctl enable bluetooth
- Enable experimental mode by adding the '--experimental' flag to the bluetooth.service file
sudo nano /lib/systemd/system/bluetooth.service
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth
[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental //Change This Line
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
- Reload and restart the system
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
- Check that everything is running with no errors and in experimental mode
systemctl status bluetooth
The following wiring will be setup based off a Raspbery Pi 3 model B and the DRV8825.
- 3.3v from Raspberry Pi to RST and SLP pin
- GND to GND
- Pin 21 to STEP
- Pin 20 to DIR
- Pin 14 to M0
- Pin 15 to M1
- Pin 18 to M2
The motor setup will be dependant on the motor but should be pretty straigt forward to set up.