We wanted to try banning phones from the bedroom (you should try, I recommend it!). Clearly, a suitable hardware replacing the alarm clock app was needed. Having thought about building my own alarm clock for a while, I quickly determined it was not a viable option to just go buy one – there simply did not exist a model with all the features I had thought of and now needed to have, like for example:
- Weekly schedule (no alarm on weekends)
- Smarter snooze (configurable and longer)
- Integrated with wakeup-lights and the rest of the appartment
- Configurable from other devices
- Programmable/extendable with future ideas
For the first prototype, I used some parts I had laying around:
- Raspberry Pi A+ with USB wifi dongle
- 1.8″ TFT display (check Ebay for “HY-1.8 SPI”)
- Some prototyping board, connectors and pushbuttons
- Small speakers with 3.5 mm jack
The first step was to connect the display. The one at hand communicated over SPI, which all Pi’s support, and hooking it up was not too difficult. Then, however, I spend quite some time trying to make the Pi recognize it as a screen rather than handling the SPI commands to it directly in my code. (Doing that would mean the interface could be a webpage for example, which would make it easier to develop.)
Using an SPI TFT as a monitor had been achieved already and made quite a buzz on Hackaday back in 2012 or so, but unfortunately it was not so easy to reproduce. At the time of building this in late 2016, most documentation I could find was still from 2012-2013 and talked about compiling the kernel from scratch and a frame buffer driver called fbtft. But, once I found its official Github repository, the first thing in the readme was (and still is) a message from early 2015 saying the driver has moved into Linux staging and that development there has ceased:
123 2015-01-19The FBTFT drivers are now in the Linux kernel staging tree [...]Development in this github repo has ceased.
I could not find any signs if fbtft is now actually part of Raspbian nor any comprehensible documentation on how to set it up so I ran out of patience and decided to go with direct SPI control for the first version, meaning less fancy graphics for now. For direct SPI, finding examples was a little easier and by learning from the code on w8bh.net, I finally got something working.
The Pi now runs a fairly simple Python script, listening to the buttons and updating the display every minute, playing an mp3 file at increasing volume if it is wakeup time. The display shows current time and the time of the alarm (which only runs monday – friday). Two of the buttons are used to move the alarm time back or forth in 15 minute intervals. This can be used to change the alarm, snooze or skip it in the morning. The third button stops the alarm and the fourth toggles the Philips Hue lights in the bedroom on/off. The Hue lights are actually controlled via MQTT, from a Node Red server running on a separate Raspberry Pi, acting as a hub for this and some other “smart home” features which might be a topic for a future post.
All-in-all we are pretty happy with this first version, it has been in live use for four months now without any major malfunctions and basically it just needs an enclosure. It does lack some obvious features, like adding an alarm on the weekend and actually moving the time the wakeup-light starts along with the alarm time. Also, when I make a new version, probably I will add another button for starting the coffee maker as well. 😁