Dancing Lights with Raspberry PI

Posted on September 07, 2019


It has been a long time since last time I posted a blog. I recently joined Google and work on Google Analytics. Feel welcome to send me a resume if you are interested in joining us or joining Alphabet.

When I am decorating my new apartment, I feel like the wall is so empty and I didn’t get enough light from IKEA’s lamp. So I decided to build a light with a light strip which can control with my Raspberry Pi. 

I brought the strip (WS2812B) on Amazon and this post is super-useful on setting up the strip. The plan is very intuitive: PC->sound->monitor->raspberrypi->LED strip. The most difficult part will be how to (1) monitoring volume of the PC and (2) how the PC communicates with raspberrypi with at least lagging as possible.

Monitoring volume:

This part is actually fun. I am a python-abusing user when developing my own job since I can code fast and find a lot of auxiliary packages. If you are using Linux or MacOS, it should be pretty easy to monitor the volume with python because the python environment is kind of native with the *nix system. However, since I am dealing with the Windows10 here, I have to find a workaround.

To build a Windows-system-related monitor (and communicator) software, well I would use Delphi 7 back in 2013 since I was good at that, the currently best platform is to use Window’s dev platform like WPF or win-form (deprecated). With WPF, you can add NAudio reference in your C# project and it can get all audio information you need from the system side.

Communication between RaspberryPI and PC:

I proposed three solutions here for you to choose from:

  1. Via an Ethernet cable
  2. Via Bluetooth
  3. Via the router

The first and second solution will need another investment (a cable or a bluetooth adaptor for a desktop). I thought the third solution will have a severe lagging time due to the unstable WIFI signal. However, it works acceptably as you saw in the video. And if you go with Bluetooth, you have to write a Bluetooth communication interface, which, based on my experience, it’s pretty hard to find some sample codes with the WPF(C#). If you go with (1) or (3), a simple socket will solve the issue.

Future works:

The pipeline can be improved in several aspects:

  • Communication speed
  • Display effects
    • Luminous intensity
    • Animation (Speed, Transition way)
    • Color
  • Display information
    • Volume
    • Frequency
    • Repetition
    • Non-audio information (message, whether, reminder, clock...)

Currently, my PC-side program analyzes the volume and have a threshold to decide whether to light up or not. And the strip has a rainbow color rotation based on the time and a trailing effect. You can do a FFT and choose the color based on the frequency of the audio slice. Believe me, it worths your money if you already have a dusty RaspberryPI.