As I mentioned in my previous blog post, Pi Pico with 7-segment display, I decided to try using a 74LS47 chip to handle the logic of converting a number in code into a 7-segment digit.
Newark Canada sells these chips. I think the 2 types might give different "fonts" - the one I have doesn't have the extra tail on the 6 and 9, for example... I'm not 100% sure, but I think I saw a little detail saying it's a chip-variation thing rather than a chip-pin-selection.
Here's one: https://canada.newark.com/texas-instruments/sn74ls47n/logic-bcd-7-seg-decod-drvr-16dip/dp/37AJ1160?st=74ls47
Texas Instruments has the spec sheet on their website: https://www.ti.com/lit/ds/symlink/sn5447a.pdf
But really, these things have been around for so long that a quick online search will give you all the information you need very quickly.
So I won't bother repeating all those details :D
In a nutshell, the 7 wires that were originally going from the Pi Pico to the 7-segment display are now going from the corresponding pins on the 74ls47 chip to the display, and the Pi Pico now only has to use 4 wires to display a digit, plus 1 wire to blank the display if desired.
This means that the hardware portion of this project has just gotten a little more complicated - an extra chip and 5 extra wires to figure out.
However, the big gains are in the software: the code can now quite easily convert a digit into the 4 bits that the 74LS47 expects, and we save a lot of extra table effort. But it does require some extra math for that conversion.
# # Basic 7-segment display test # from machine import Pin import time # For my 7-segment display, the common wire connects to VCC # -> Note that this means we have to turn a pin "off" to light the segment LED, and "on" to turn it off # The 3.3v pin 36, combined with 220R resistors light the segments well enough # You can test the display by using a small 3.3v button battery (CR2032 seems cheap and plentiful) # Hopefully the display you have will have a model number you can look up to find the pinout. # We are using a 74LS47 decoder chip to run the 7 segment display # That means the Pi Pico only needs to send a binary number to the decoder chip to show a digit. # Define the segment GPIO connections # hook up the wires to the decoder chip as per the defined constants below # Use a current limiting resistor for each segment (you'll need 7!) between the decoder chip and the display. # The resistors are also necessary to keep a constant brightness on the display INPUT_A_PIN = 12 INPUT_B_PIN = 13 INPUT_C_PIN = 14 INPUT_D_PIN = 15 BLANK_DISPLAY_PIN = 16 # I'm not using the 2 dots for this example, but they would simply add another GPIO pin each. # The dots would need to be directly controlled, same as without the decoder chip. def setup(): # Define each segment global INPUT_A, INPUT_B, INPUT_C, INPUT_D, BLANK_DISPLAY INPUT_A = Pin(INPUT_A_PIN, Pin.OUT) INPUT_B = Pin(INPUT_B_PIN, Pin.OUT) INPUT_C = Pin(INPUT_C_PIN, Pin.OUT) INPUT_D = Pin(INPUT_D_PIN, Pin.OUT) BLANK_DISPLAY = Pin(BLANK_DISPLAY_PIN, Pin.OUT) def getBits(digit): #if digit > 9 or digit < 0 # return [] #error - blank array d = digit bit1 = d % 2 d = d // 2 bit2 = d % 2 d = d // 2 bit3 = d % 2 d = d // 2 bit4 = d % 2 return [bit1, bit2, bit3, bit4] def displayDigit(digit): # A is the least significant digit (aka, 1) bits = getBits(digit) INPUT_A.off() INPUT_B.off() INPUT_C.off() INPUT_D.off() if bits[0] > 0: INPUT_A.on() if bits[1] > 0: INPUT_B.on() if bits[2] > 0: INPUT_C.on() if bits[3] > 0: INPUT_D.on() BLANK_DISPLAY.on() def displayOff(): BLANK_DISPLAY.off() # Start main code setup() while True: for digit in range(10): displayDigit(digit) time.sleep(0.5) displayOff() time.sleep(1)
I probably could have named that "BLANK_DISPLAY" pin a bit better - turning it "on" turns on the display, it doesn't blank it... so maybe "ACTIVATE_DISPLAY" would have been more clear? On the other hand, that's what they call the corresponding pin on the 74ls47 chip. I kind of think the chip might already also include a blank character allowance... like if you set all bits to 1 it might do that... I didn't play with it a whole lot.
Here is a little video of it running through the digits. Note that the digits look different than in my previous example, and I don't think there's a way to adjust the "font" without getting a different version of that chip.
For my preference, and given the power of the Pi Pico, I prefer to just do the work in code and use the few extra GPIO pins - the Pi Pico has plenty of extra pins for this project, and I find the extra hardware is harder for me to deal with than the extra code, and the extra chip would ultimately also require a larger project case if I were to build it into a proper looking project.
I also prefer the straight-forward direct control rather than doing what is essentially bitwise math. That also allows me to control the digit font and gives me the extra benefit of expanding to include alphabetical characters if desired. But I've been a software guy for my entire life, so my bias will be towards using software wherever possible! Your mileage may vary, so do what feels best for you
For my next step, that chip will be leaving the show, and I'll go back to the direct control way of my previous blog post - and I'll see about expanding this to a clock display with 4x 7-segment displays plus whatever extra that clock display has.
Stay tuned!
-Nico
Next: Testing the Clock Display (manually, no microcontroller needed)