Multiplexing 4 7 Segment Displays With WiringPi And Ruby
After throwing together the WiringPi Ruby Gem, I figured it might be prudent to find something to do with it. Having previously cobbled together a 4-digit, 7 segment display, two shift registers a darlington array and a jungle of wires, transistors and resistors I decided to pop off the ATMega which I had driving it and hook up the Pi instead.
I decided to use the Pi's 5v line, adjusted via a 3.3v regulator. This lets me draw a full unrestrained ~500mA, which is my 1.3A power supply minus the current draw from the rest of the board. ( the 3v3 pin, by comparison, can only supply 50mA )
I then hooked up the Latch, Clock and Data pins for the shift registers to GPIO 17, 21 and 22 respectively. These correspond to WiringPi pins 0, 2 and 3 (yes these weird pin numbers hurt my brain, too ).
Driving the Shift register in Ruby was then trivial, even more so with the addition of a shiftOut function to my WiringPi wrapper library. shiftOut takes a Data Pin, Clock Pin and Latch Pin followed by an array of bits ( represented by a 1 or 0 in this case ) which it will push out in the order given to it. A shiftOut call looks a little like this:
WiringPi.shiftOut DATA_PIN, CLOCK_PIN, LATCH_PIN, [0,1,0,1,1,0,1,1,0]
For the sake of simplicity, I force the specified pins to output mode in the shiftOut function so be wary if you're somehow using them for a return signal.
At the moment shiftOut isn't available in the WiringPi gem, but a new version will land once I've got it working nicely as a pure C function rather than a somewhat sluggish helper in the Ruby wrapper.
You can grab the code I used in this project here: https://gist.github.com/Gadgetoid/f4bc9bdd99e72549c923
« Back to index Posted on 2012-06-25 by Philip Howard