Thursday, January 11, 2018

Raspberry Pi Sparkfun 7 Segment Display Clock

Originally published: September 2, 2013

I recently purchased a 7 Segment Display from Sparkfun, model COM-11629. I was interested in using my Raspberry Pi to control some external devices, and this seemed like the perfect fit. It’s controllable via I2C, SPI, and serial. So far I’m able to communicate with the device via I2C and SPI. Sparkfun provides a lot of great information on the display here. It seems to be well supported on Arduino, but I was interested in a python implementation that could run on my Raspberry Pi. You’ll need to set up a few things before you’re able to interface with the display. I’ll cover the software first.

Enable I2C and SPI on Raspberry Pi

1. First you’ll need to enable the Kernel modules that provide I2C and SPI functionality. It’s disabled by default on Rasbian (the distro I’m using). First type:

$ lsmod

If you see i2c_dev and i2c_bcm2708, you’re ready to go, if not, edit /etc/modprobe.d/raspi-blacklist.conf. Comment out (or delete) the following lines:

blacklist spi-bcm2708
blacklist i2c-bcm2708

You should then reboot and run lsmod again to verify that the drivers are loaded on boot:

Check the GPIO pinout for the PI here, so that you can see which pins on the headers I’m referring to. You should only connect one of these buses at a time. This example makes connections to 3.3v. You can however hook the display up to 5v (which will make it brighter), but you’ll need to use a Logic Level Converter to go from the Pi’s 3.3v to the display’s 5v. You can’t just connect the Pi directly to 5v, or you’ll damaging your Pi. Note: I did try to use a Logic Level Converter to connect the display at 5v, but I was unable to get it to work properly with I2c (didn’t try SPI). More investigation required. If using I2C:

RASPBERRY PI

SPARKFUN 7 SEGMENT DISPLAY

SDA

SDA

SCL

SCL

3.3v

+

GND

-

Make sure that you can see the device on the I2C bus, by default it’s address is 0x71. I’m using a rev. 1.0 Raspberry Pi Model B (256MB version), which means that the I2C is wired to bus 0. If you’re using a newer rev. 2.0 Model B (512MB version), you’ll want to use bus 1. For 256MB Pis:

Running the Clock Example

Now that your connections are checked out you run the clock example software. It’s implemented in python and uses a library (written by me) that you can use to write additional applications that use this display. Note, that this software is not a Sparkfun product and I am not responsible if it messes up your display or your Pi.

Notes

I2C at the moment seems less reliable than SPI and I occasionally get IOError exceptions when talking to it. This could be the result of my wiring setup. It’s enitrely possible I botched things horribly when soldering on the headers that allow me to plug the device into my breadboard. I’ve added retry mechanism when writing commands via I2C in order to compensate for this, but it’s probably something that I need to look into further.