Demo project to remotely control an Raspberry Pi Mood Light over Bluetooth via iOS and Android.
In this demo, we are using the Unicorn HAT or Unicorn HAT Mini with the Pimoroni Mood Light Kit which is powered by a Raspbery Pi Zero WH.
There are two companion apps - one for iOS and Android - which offer the ability to control the mood light via Ditto's P2P data sync. The mood light itself is powered by a Rust application which listens for data change events from the companion apps and then changes the light color. The Rust app uses pyo3 to call the python libraries from Pimoroni to control the Unicorn HAT.
- Pimoroni Mood Light Kit
- 32 bit Raspberry Pi OS
- iOS app requires iOS 16 as it is using a new SwiftUI Color Wheel component
- Python shared library installed
-
Request an offline license token through the Portal and replace "YOUR_OFFLINE_TOKEN" with that value in all apps (iOS, Android, and moodlight-rs).
-
Install Raspberry Pi OS (32 bit) and follow the Unicorn HAT or Unicorn HAT Mini getting started guide to install the required firmware for the light.
-
Copy
moodlight-rs
to the Raspberry Pi.
scp -r moodlight-rs pi@raspberrypi.local:~/
- Install rust on the Raspberry Pi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
// Typical requirements needed for BLE
sudo apt-get install libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev docutils-common
- Compile
moodlight-rs
manually on the Raspberry Pi:
cd moodlight-rs
// If cross-compiling to original RPi-Zero-W
rustup target add arm-unknown-linux-gnueabihf
// Install the Python shared library
sudo apt install python3-dev python3-venv python3-pip
[PYO3_CROSS_LIB_DIR=/usr/lib] DITTOFFI_SEARCH_PATH=./ LIBDITTO_STATIC=0 cargo build [--target arm-unknown-linux-gnueabihf]
- Run
moodlight-rs
:
// Pass --mini argument if Unicorn pHAT Mini
// Add additional RGB values to set initial light color
sudo LD_LIBRARY_PATH=./ ./target/debug/moodlight-rs [--mini true] [-- 0 0 0]
- Run iOS or Android apps on a companion device to control the light!
- Ensure you're using a high-quality SD card.
- If Rust installation fails, you may need to increase the swap size on your Raspberry Pi. (see this issue)