The worlds most over-engineered lamp

Joel Collins
Aug 10, 2016 · 5 min read

Having purchased a Raspberry Pi, I had a really hard time figuring out what to do with it. I had a 3 month summer break, unemployed before starting my PhD, and I needed a project to last that time. I had, over the weeks leading up, had a few ideas about using various NeoPixel LED rings and strips to construct fantastical wall-mounted clocks and system status displays, but these were all verging on impractically expensive and over-complicated.

Ultimately, I decided to start simple and purchased the Unicorn HAT by Pimoroni. This is as close to a ‘plug-and-play’ solution to Pi lighting as you can get. The device fits directly on to the GPIO pins and includes an amazing and incredibly simple-to-use Python library.

The first few days were spent on simple things just getting used to how the device works. Best practices and such. Eventually though, I had my plan.


There are many alarm clocks that add the extra functionality of a lamp that gets brighter in the hour or so leading up to your wake-up call. They tend to be bizarrely expensive however. So this was my starting point. A simple Pi-powered LED lamp that functions as a gradual alarm.

After some planning, I had decided that it should also have additional basic lamp functionality. I wanted a thermal lamp, where the user can enter a lamp temperature (black-body) and the Pi will calculate the RGB values and light the room accordingly. Similarly, it should have the option to select a hue and, again, calculate the RGB values. While writing the code for these simple modes, a couple of other simple variations were also added.

Finally, a graphic equalizer was included. Here, the Pi acts as an audio pass-through device. You connect any audio output to the Pi’s audio input, and connect the Pi’s audio output to your speakers. There is no delay in the audio, and the Pi can read the input and generate a graphic equalizer from it.

At this point, the entire project was still command-line based though. This is hardly ideal for what is essentially supposed to be a piece of furniture, and so the over-engineering began. It needed a web UI.


The idea for the UI is reasonably simple. There are two parts to the project:

The first script contains all the code to run the lamp modes on Python threads. Since the functions are running on threads, the command line is open to change parameters in real time. Starting another mode will stop anything currently running. Similarly, the alarm clock will override any currently running mode, but then starting a mode after the alarm sequence has already begun will then override the alarm. On top of this, I added a simple function to fade the brightness of any running mode down over a given time.

The second script uses the Flask module for Python to set up a local web server, running a small GUI based on a slightly modified JQuery Mobile. Any user on the local network can access the Pi and control what the lamp does.

In the end, this is how the system ended up working:

Left: Web GUI running on an Android device. Right: Raspberry Pi and Unicorn HAT inactive.

Here you can see the inactive Pi on the right, and the web app running on Chrome on Android. The options are all collapsed, but expanding them opens up the various options for each mode.

Hue Lamp

Possibly the simplest mode is the hue-based lamp. This allows the user to select a colour, and just holds the lamp on that colour at the global brightness.

Thermal Lamp

The thermal lamp lets you specify a temperature, as mentioned earlier, and also adds some simple presets that jump to a specific value based on some common use-cases.

Candle

Candle mode

This really is a simple mode, hardly worth showing. It has no options, and results in a warm, slightly flickering light designed to imitate a candle.

Hue Tardis

Tardis mode

This was a very early demo that never got removed from the final code. It’s identical to the normal hue lamp, but fades in and out at a user-specified speed.

Rainbow

Rainbow has two modes. The first simply uses the a Pimoroni example script to, in their words, “poop rainbows”.

Pimoroni rainbow mode

The second mode fades through the full available spectrum, again at a user-defined speed.

Spectrum rainbow mode

ALSA Equalizer

Classic equalizer mode

Finally, the ALSA equalizer takes the audio from the pass-through, and generates a graphic EQ from this. There are now 8 colour schemes for this, as I keep adding them whenever I fancy something new, but above is a demo of the “classic” style. I’ve had to zoom in a lot for this to keep the exposure in check, so apologies for that.

Update: I have written up a small document going through the code used for this EQ mode. The code is not standalone, but it may be a helpful reference still. The document can be found here.


These demonstrations were taken some time in December 2015, and while I haven’t had much time (or need) to significantly work on this, a few things have been added here and there. These are mainly extra modes for the graphic EQ, and streamlining the code.

Currently, the Pi sits mounted to the back of my PC display, acting as both a nice border-light for the screen and is also bright enough to easily illuminate the room as a lamp would.

It is generally connected as a permanent pass-through between my monitor audio output and my speakers, and works great as an EQ.

Honestly, this is the first electronics project like this that I haven’t dismantled shortly after completing. It gets used on a regular basis many times a day (as this is now the only lamp I own) and is a nice go-to project when I need something to do, as it is so extensible.

I cannot recommend the Unicorn HAT enough. The simplicity of the device and its Python library made this whole project easy in all the right places. Any complexity was my own choice, and getting the LEDs to respond as I wanted was never a difficulty.

In fact, I’m so taken by the device that my Pimoroni Mote kit has been ordered and should be arriving any day now. I think they will be living inside my PC case, acting as system status meters…

Joel Collins

Written by

Physics PhD student in photonics. I also make music, graphics and electronics sometimes.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade