Waking up with an RPi – pt.1: introduction

I don’t like waking up. I need easing into the day, slowly and carefully, especially in Winter. My wife is the same, which is why she bought a ‘dawn clock’. This is an alarm clock with a light that fades up slowly, over the course of 90 minutes, before sounding the alarm. It’s a fine device and we still use it, but I thought “I could do better than that”.

What I did, eventually, is shown below – a Raspberry Pi-powered dawn clock. But that wasn’t my first attempt.

One of the things we miss most in Winter is waking up to the sound of birdsong. We’re in the Normandy countryside with trees all around. One Summer morning, my wife went out early and recorded the birds’ dawn chorus. And I thought, wouldn’t it be great to wake up to that each morning?

And so I took an Arduino Uno and coupled it with the Adafruit Wave Shield andReal Time Clock (RTC). I added a 16×2 character LCD panel that displays the time and temperature (thanks to a simple sensor). The Arduino switches on a series of bright white LEDs, one every five minutes. Eight are switched one via a shift register but the first two fade up slowly thanks to PWM directly from Arduino pins. Half-an-hour before wake-up time, the clock starts playing the birdsong recorded in our orchard. At wake-up time, the clock plays a song chosen randomly from the files loaded on to the Wave Shield’s SD card. The whole thing is shoved, rather crudely, into a plastic food container. But it works and has been waking us up, gently, for about the past 18 months.

I knew I could still do better, though.

The Arduino-based project had some issues. First, changing the clock time, or altering the alarm time, involved editing the C code, which in turn meant plugging the clock into the computer. Clumsy.

Second, loading new songs on to the card meant shutting down the clock, digging out the SD card and sticking that into my computer. Also clumsy.

In addition, the Wave files for the shield have to be carefully prepared, which meant taking existing MP3 files and editing them in Audacity. Time consuming.

And there was no way to add any extra functionality. Like most things that come from Adafruit, the Wave Shield is a very fine product. But it does consume a lot of the Uno’s program space. I’d had to cheat every byte I could out of the code to get it to run.

And then I got a Raspberry Pi…

And so was born the Speculatrix Dawn Clock Mk.II. Here’s a quick run-down of the specs and functions:

  • 20×4 LCD panel displaying time, date, temperature, barometric pressure, alarm time, alarm song played and other stuff.
  • PIR sensor to detect movement.
  • I2C barometric temperature and pressure sensor.
  • Light level sensor.
  • 64 LEDs driven via I2C port expanders.
  • Wifi-enabled.
  • Stereo sound via a USB sound card, amplifier board and two speakers. Ability to play standard MP3 files.
  • Web server for settings, information.

And here’s a description of how it works:

  • One hour before alarm time, the first LED is switched on. Subsequent LEDs are switched on at the rate of one each minute. To simulate dawn, the first 8 LEDs are red, the next 8 are yellow, the next 8 alternate red & yellow, the next 8 alternate yellow & white, the remaining 32 are all white.
  • 30 minutes before alarm time, the bird song starts playing, slowly fading up over the course of a couple of minutes.
  • At alarm time, the lights ripple, the remaining 4 LEDs switch on, the LCD backlight comes on, birdsong stops and a song, chosen at random from a folder of MP3 files, plays. The LCD displays the name (where available) or filename of the chosen song.
  • When the song stops, there’s a slight pause and then the clock starts playing the radio – BBC Radio 3 streamed via the Internet.
  • 45mins after alarm time, the lights ripple & go off, the radio stops & the LCD backlight goes off.
  • If the motion sensor is selected, if the ambient light level falls below a certain threshold and the PIR motion sensor detects movement, the LEDs come on for 30secs. This only happens up until a certain cut-off time (we have this set to 22:30), so that you don’t have the lights coming on in the middle of the night should a cat decide to join us in the bedroom.
  • In addition to displaying the current temperature and barometric readings, the clock logs these readings (at user-configurable intervals) to a MySQL database. Graphs for recent readings (24hrs for temps, 48hrs for pressures) are available via the clock’s web server. The web server also shows highest and lowest temps for the past 36 hours and which song played that morning.
  • The clock is configurable via the web server.

The whole thing is housed in an old SAD lightbox. My wife & I are both affected by SAD and so have bought a number of lightboxes over the years. This one had an annoyingly buzzy transformer, so we rarely used it. I’d long eyed it as a potential project box. So I just ripped out all of its components.

You can already see that the Mk.II has a lot more functionality. So how was this achieved? More information in the next part.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.