Want your own grandfather or cuckoo sounding clock run on each hour? Stay tuned. I've been using Instructables for so long long now, so I decided to give something back. Introducing my Raspberry Pi Big Ben Clock.
This is a small little project I did out of a bit of boredom because I had a 'silent' Raspberry Pi behind my TV who's only job was to play mp3s on demand (maybe an Instructable for another day).
The Raspberry Pi Big Ben Clock is basically an audio simulation of a grandfather or cuckoo clock using some edited mp3's I got off the internet, some Bash scripting and crontab. It is called Big Ben because the audio files I decided to use was from the Great Bell in London, England.
You can use any audio of your choice, but this fairly simple Instructable will help you to put it all together.
Step 1: Requirements
This Instructable will be very easy for those who owns and/or are familiar with the Raspberry Pi. You will obviously need one, pre-installed with the very popular Raspbian operating system. I used Wheezy, but the steps will be the same with Jessy.
You will also need to be connected to the internet to be able to do the latest update,
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
get the necessary additional software like MPlayer
sudo apt-get install mplayer
and to get the time accurately. (Usually done automatically if your location settings are correct.)
I use a B model Raspberry Pi, with which you can run audio through the HDMI cable, but I preferred using the audio jack instead (configurable through Raspi-config or the GUI).
Step 2: Do the Coding
I only used simple Bash scripting, the mp3s and crontab for this project. I firstly created a big-ben directory in a known location to hold the Bash script and the mp3s. For explanation, I will use /home/pi/big-ben. To get started, you can download mine below - originally from the UK Parliament website.
From a freshly booted Raspbian terminal (i.e. the default working directory, which should be /home/pi) do/copy the following steps to create the directory and copy the mp3 files to it:
To create the script do the following:
and copy this code to it:
# Triggered through crontab every 30 minutes minute=$(date +"%M") if [[ $minute == 30 ]] then mplayer "/home/pi/big-ben/FOPGM68INC0CAI9.mp3" elif [[ $minute == 00 ]] then mplayer "/home/pi/big-ben/F3CWOPJINC0CAI4.mp3" hour=$(date +"%I") x=0 while [ $x -lt $hour ] do mplayer "/home/pi/big-ben/FOPGM68INC0CAI9.mp3" let x=x+1 done fi
Remember to exit & save (Ctrl + x, y Enter)
Now to activate this script through crontab, use
and paste the following code to the bottom of the cron file:
0,30 * * * * bash /home/pi/big-ben/clock.sh
Remember again to exit & save (Ctrl + x, y Enter)
Step 3: Conclusion
That's about it! Sit back and wait for the magic to happen if the clock strikes.
You can go back and look a bit deeper into what I did and make your own changes. I for example added Bash to prevent this clock script running in the evenings. You can also use cron for that. Also go and try your own sounds.