Raspberry Pi Mood Light
Demo project to remotely control an Raspberry Pi Mood Light over Bluetooth via iOS and Android.
Overview
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.
Requirements
- Pimoroni Mood Light Kit
- iOS app requires iOS 16 as it is using a new SwiftUI Color Wheel component
Setup
-
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 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 [email protected]:~/
- Install rust on the Raspberry Pi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Configure the Raspberry Pi to support Bluetooth Low Energy with Ditto
-
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
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!
Troubleshooting
- 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)