Raspberry Pi SenseHat Night Clock

Lorna Mitchell
Dec 28, 2019 · 2 min read

I recently upgraded my smartwatch and the new model needs charging daily (whether that’s really an upgrade is a separate discussion!) so I drop it on the charger by my bed overnight. As a result, I can’t tell the time if I wake up in the night which is only annoying because I don’t know if it’s midnight or if the alarm is going to go off in ten minutes! So I made myself a colourful fuzzy time clock with a raspberry pi and a SenseHat that were lying around in my office.

(note: it’s quite hard to photograph neopixels, I tried)

sensehat showing green in the centre and white lights around the sides
sensehat showing green in the centre and white lights around the sides
sensehat showing yellow in the centre and white lights around the sides
sensehat showing yellow in the centre and white lights around the sides
sensehat showing orange in the centre and white lights around the sides
sensehat showing orange in the centre and white lights around the sides

The basic idea is that the colour in the middle changes with the hour, and the white lights around the outside indicate sort of approximate areas on the clock. This way, I avoid staring at the clock reading 03:32 but can still tell that it is time to go back to sleep!

The code is python; run the script python3 clock.py and the script will check the time on the pi, set the lights and exit. To keep the clock running, try setting up a cron job that does this every minute:

* * * * * /usr/bin/python ~/night-clock/clock.py

It’s much simpler than trying to keep a long-running process going.

Pro-tip: Neopixels are really bright — much too bright to have anywhere near you in the dark! Look for a variable called on that serves as the basic light level (everything else works off that setting). The max is 255 but I'm working off about 80 and even that is plenty bright enough :)

The code is on GitHub: https://github.com/lornajane/sensehat-night-clock and you’re more than welcome to try it, amend it, let me know how you go!


Originally published at LornaJane.

Lorna Mitchell

Written by

Developer Advocate at IBM. Technology addict, open source fanatic and incurable blogger (see http://lornajane.net)

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