Demo project to sync color changes to an Raspberry Pi Mood Light via iOS/Android

Raspberry Pi Mood Light

Demo project to remotely control an Raspberry Pi Mood Light over Bluetooth via iOS and Android.

? Watch the video

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

Setup

  1. Request an offline license token through the Portal and replace “YOUR_OFFLINE_TOKEN” with that value in all apps (iOS, Android, and moodlight-rs).

  2. Install Raspberry Pi OS and follow the Unicorn HAT or Unicorn HAT Mini getting started guide to install the required firmware for the light.

  3. Copy moodlight-rs to the Raspberry Pi.

scp -r moodlight-rs pi@raspberrypi.local:~/
  1. Install rust on the Raspberry Pi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Configure the Raspberry Pi to support Bluetooth Low Energy with Ditto

  2. 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]
  1. 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]
  1. 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)

GitHub

View Github