I got up this morning when my alarm went off.
I know what you’re thinking; “Why are you telling me this? Everyone sets an alarm with the intention of getting up when it goes off.”
Although it does seem a trivial part of my day to be telling you about, for me it was very exciting. Why? Because my alarm clock is no ordinary alarm clock. It’s my Raspberry Pi!
In case you were wondering, I have a Raspberry Pi 2 Model B and its mounted onto the official Raspberry Pi 7″ Touchscreen display which I’m using with a blue frame. My Pi is actually powered by an old Samsung charger and the speakers are just old PC ones. I was lucky enough to get all of these things for either my Birthday or Christmas so I can’t tell you were I got them from. I was going to add a video but it was to big to upload onto here, so you can instead use this link to view it on YouTube if you want to see it in action.
Like nearly everything else in life, my ‘PiAlarm’ didn’t work straight away. It took four days of waking up too close to lunch time for my liking and one rushed shower before setting off on holiday until I was actually awoken by my PiAlarm. To say it was frustrating waking up in the morning to see that my clock had frozen at 04:05:07 is an understatement. But despite all the times I wanted to give up and launch it out the window, I have finally successfully turned my Raspberry Pi into a touchscreen alarm clock. This is something I’ve wanted to do for months and the sense of achievement I have when getting up every morning knowing that I made my alarm is, well, it’s the reason I love computing.
Problem #1 – What on Earth am I Doing?
I knew that in order for this to work I needed to create a GUI application. I initially looked for a WYSIWYG editor as a ‘cheat’ option, but there weren’t really any that suited me. I guess that was just fate telling me not to cheat 😉 I then looked at creating a GUI application in Python. I started off by spending a day learning Python GTK, only to realise that the loop used to run the application interfered with the loop required to build a clock. It was effectively impossible to create a clock using GTK and that was a sort of wasted day of my life.
My Solution – I instead started to teach myself Tkinter, which would definitely allow me to create a clock within the code.
Problem #2 – Sound
As they are so tiny, Raspberry Pi’s don’t come with speakers. Obviously a major problem for an alarm clock.
My Solution – I hooked up my Pi to my surround sound system in my bedroom. I loved the prospect of being awoken by my surround sound!
Problem #3 – Surround Sound
Yes, the solution to my previous problem quickly became a problem in itself when I realised that I had to leave my speakers turned on all the time in order for my PiAlarm to work. Why was that an issue? Well not only did it probably waste a lot of electricity but when not in use the speakers made a humming noise. This noise was fine during the day as it was masked by the background noises of life, but at night time the only thing I could hear was the humming of the speakers and after just one night I decided I couldn’t hack it.
My Solution – This was definitely a light bulb moment. Having tried everything I possibly could to be rid of or even just reduce the humming speaker sound, I remembered I have a plug in timer, which meant I could set my speakers to turn on at the same time as my alarm. Okay, in reality setting two alarms seems counter intuitive but that’s not the point – the point is I made it 🙂
Problem #4 – Screen Timeout
I am 99.9999999999999% sure it is impossible to change the screen timeout settings on my Raspberry Pi. Although in my research people have said it does work I have tried literally EVERYTHING to no avail. This was a pain because the screen was far too bright to have on at night time, and I didn’t want to have to wait for it to turn off the display by itself as I wasn’t really sure how long that actually was now that I had changed so many settings.
My Solution – I changed the label that displayed the time in my application to a button that when pressed turned off the screen. Touching the screen again then turns it back on.
Problem #5 – Crashing
I tested my PiAlarm for 4 days and I was woken up by it on 0% of those days. It kept crashing! It would freeze on (seemingly) random times which would cause the alarm function not to work. Great.
My Solution – I tried some code which would restart the script if it froze but that didn’t work. I then thought it may have been to do with the fact that it couldn’t connect to the WiFi in that corner of my room – #WifiProblems. The Raspberry Pi has no internal clock and so gets the time from the internet. This meant that whenever turned on I had to manually input the exact time. By moving it to a place that it could connect to WiFi I hoped that it would update the time itself and would therefore prevent crashing. So I reluctantly ditched my surround sound and moved it to the opposite corner of my room. In order to do this I had to actually rearrange furniture in my bedroom, just for my little Raspberry Pi. I then connected it to some “borrowed” PC speakers. (These speakers, and all others that I tried, make even worse noises than my surround sound so I still have to use the timer).
Problem #6 – CRASHING!
By this point I was starting to lose the plot. My Raspberry Pi was still crashing and I had no idea why. Until I thought that it wasn’t crashing at random and was instead crashing when I turned the screen off.
My Solution – I changed the time button back to a label and created a separate button that turned off the screen.
Problem #7 – CCCRRAASSSHHHINNNNGGG!!!!!
My theory on the not-so-random times it crashed was pretty wrong. Once again I was not woken up by my PiAlarm. I gave up all hope. I went on holiday for four days (not because of my PiAlarm, this was previously planned 😉 ) and it was only when I came back and looked at it with a fresh view that I realised my Raspberry Pi had been giving an error every time it ran but I had just ignored it out of ignorance. Could this be the cause of all my problems? The answer is yes, but trying to find the cause of the unknown error was difficult.
My Solution – Turns out the cause of all my many problems which resulted in the redesign of both my PiAlarm and my bedroom was that I had got confused in my code and put a ‘1’ instead of ‘True’. How anticlimactic.
The first time it worked was yesterday. I actually woke up before my alarm clock went off. The first thing I did was check the clock was actually still functioning and you can imagine my delight seeing the seconds change on the screen. I then lay in my bed praying for it to work, and sure enough half an hour later my alarm finally went off. The only time I’ve ever moved out of my bed that quick in a morning is on Christmas Day and my Birthday. I was just to excited that it FINALLY worked!
Speaking of Birthdays, guess who is 16 tomorrow? Me!
Anyway, there are a few other things I’m hoping to add to my PiAlarm in the future, so keep an eye out for that.
If you have any questions or comments, you know where to find me 😉
See you next time!