In a previous post (see HERE) I used an Arduino to drive a 4-digit, 7-segment LED display to count down from 9999 seconds to zero. Just a few days ago, Alex Eames of RasPi.TV blogged (see HERE) to say that he managed to drive one of these displays with a Raspberry Pi and make it into a real-time clock. In fact, he also offered a kit of parts to carry this out, so I bought one (only £12 including postage). Here's the kit:
I thought this was interesting because other real time clocks I have built, have had a small circuit board powered by a separate button battery to keep the clock going even when the main board is switched off. (See HERE.) I wondered how you could do this even with a Raspberry Pi as, like the Arduino, it doesn't have a built in clock either.
The secret is that the Raspberry Pi is on-line and the Python language's time library is capable of reading the time at regular intervals from the internet, using the time.ctime() function. This had been previously reported just about a year ago by bertwert (see HERE).
The details of Alex's kit can be found in his blog, referenced above, so I'll not repeat them here.
Common CathodeHere is the kit assembled and connected to my Raspi B+:
Note that the Pi has a WiFi dongle and is connected to my wireless network. You can see the LED Display unit mounted on the mini-breadboard, and the 8x 100 Ω resistors, all supplied by Alex.
Here's a video:
And here's my version of Alex's code which was derived from that of bertwert:
You can see from lines 38 to 51 that the time.ctime() command is repeatedly executed, reading the time from the internet, in the form ‘Sat Nov 21 17:11:05 2015’.
This is parsed to extract just the hour (17) and the minutes (11) and display these four digits. The decimal point for the second digit (digit 1) is used to separate the minutes from the seconds and to flash every second.
The code loops, for each digit, each of its segments, and depending on whether the num dictionary specifies that segment to be 0 or 1 ie off or on, switches that segment on for 5 milliseconds. This happens very fast, so each segment to go on, actually flashes on for 5 milliseconds in each loop. This time.sleep(0.005) command is repeatedly executed until the time read from the internet changes (for example another second is updated). So the LEDs are actually flashing repeatedly. This is a form of Pulse Width Modulation, and the eye-brain system of an observer doesn't notice the flashes, but observes the segment of the digit as a steady light of constant brightness, even though the brightness of the flashes is much higher. This has been described before as Persistence of Vision (POV).
Alex of course, goes on (see HERE) to make a count-down ticker, but still dizzy with excitement, I remembered that I had a spare 4-digit 7-segment LED Display so I dug it out. It is of a different type, COMMON ANODE, as opposed to the COMMON CATHODE one above supplied by Alex.
So I started wondering how I could wire up my spare LED display, and realised that there was more to it than just a simple swap-over. Before I risked blowing anything up, I consulted Alex.
Here is the internal circuit diagram for the COMMON CATHODE oue:
The diodes are arranged so that for each digit, DIG.1, DIG.2, DIG.3 and DIG.4, the cathodes are all connected together (to pin 12 for DIG.1, pin 9 for DIG.2 etc). Using wiring paths in this way, ie the same wires doing different things depending on the software logic, is known as multiplexing.
Here is the wiring diagram for the Common Cathode display:
The COMMON ANODE one looks like this:
Notice that the diodes are pointing from anodes which are common for each digit's 7 segments and decimal point, DP1, DP2, DP3 and DP4. Also notice that there is a colon (L1 and L2) and an apostrophe (L3), but they aren't used here.
Here's my COMMON ANODE display connected to my Raspberry Pi 2:
You can just about see my black mini-breadboard with the resistors (this time 8x 680 Ω).
Here's a video:
Here's the code for the COMMON ANODE setup:
Notice that a few changes have been made, mostly changing 0's to 1's and 1's to 0's. You'll see on Alex's post that I asked him for advice in doing this part, and he kindly responded and put me on the right track. Thanks again Alex!
Here's the wiring diagram for the Common Anode Display:
And here is the Common Anode Display wired through the RasPiO Duino. The Duino doesn't have anything to do with the 4-digit, 7-segment LED Display, but in fact it is running a sketch which is driving a darkness-enabled mood lamp (see the mood lamp made HERE previously):
Here's a video of this circuit working:
PB233854 from Vimeo.
The next step I want to make is to drive the LED Display with the Duino, which hopefully will be getting the time information from the internet via the Raspberry Pi. Watch this space!