Raspberry Pi: Building an LED Digital Clock

As I mentioned in a previous post, I really enjoyed reading Programming Raspberry Pi: Getting Started with Python. One of the chapters in the book teaches you how to build an LED digital clock. It took some futzing around, but I finally got it done :)

The first problem I had was that I didn't know how to solder. My buddy Chris Dudte gave me a kit to learn. I watched a bunch of YouTube videos with the kids in my Raspberry Pi class, and then we put the circuit board together. Problem solved.

The next two problems I encountered were with the author's library for talking to the smbus for controlling the LEDs, i2c7segment. One of the problems resulted in my saying quite a few less than charitable words under my breath. The Python code kept giving me the error message "IOError: [Errno 5] Input/output error".

I finally figured it out. On line 42 of i2c7segment.py, the code is hardcoded to use smbus.SMBus(0). However, sometimes you need to use smbus.SMBus(1). You can run "sudo i2cdetect -y 0" and "sudo i2cdetect -y 1" to figure out which bus to use. You should see "70" in one of these two. The hardest part of figuring out this problem was that I thought the software must be correct, and that I must have wired it or soldered it wrong. My guess is that this might be a Raspberry Pi model A vs. model B thing.

To hack around the problem, I edited i2c7segment.py to use bus number 1. A better approach would be to allow the calling code to pass a bus number or to try to autoselect it; however, I didn't bother.

Anyway, I'm super excited that I got the project done, especially considering this is the first time I've ever done something like this. Special thanks to my buddy Chris Dudte for all his support and for giving me a Raspberry Pi in the first place!


Sam Rushing said…
Congrats, nice job!

I've been thinking for a while about building a 'digital pendulum' clock. A silly thing, really: it would consist of an electromagnetic escapement controlled by something like a Pi. Of course, the clock on board the Pi would be orders of magnitude more accurate; but I like the idea of a meter-long pendulum and an LED display, nothing else.
Shannon Behrens said…
That'd be neat!
Mehmet said…
Really good toy to show how programming and the digital world works. I used a lcd display to show my son this but later I saw it was a bit hard, an led display like this would be much easier. Great :)!