Posted in

Station 1 updated

Last day of the summer, supposed to have a different season in the next days. Anyways.

I recently read about shift registers and purchased a pack of SN74HC595N chips and some 7-segment displays to play with. I made the usual circuit, pi pico, SN74HC595N, 7 segment display, resistors and lots and lots of cables.

I liked the looks of the display, so I build it on a perf board and connected to Station 1 to indicate station activity instead of the simple LED.

Station 1 mounting made a little more fancy.

The back side of the main board. Now Station 1, has main board and display board!

Added a horizontal beam and a Π shaped metal bracket to hang the main board. The idea was to be able to unmount with out tools and take to the lab (kitchen’s table) to work with it, but broke it with the screw for the display board. Still easier to unscrew since it is facing in the front and not the narrow space on the left.

The 7-segment display code to display 0-9 and a-f is this small class. Just for reference, took me some time to “draw” the digits.

import digitalio

class SevenSegDisplay:
    
    def __init__(self, latchPinNum, clockPinNum, dataPinNum):
        self.latchPinNum = latchPinNum
        self.clockPinNum = clockPinNum
        self.dataPinNum = dataPinNum
        
        self.latchPin = digitalio.DigitalInOut(self.latchPinNum)
        self.latchPin.direction = digitalio.Direction.OUTPUT

        self.clockPin = digitalio.DigitalInOut(self.clockPinNum)
        self.clockPin.direction = digitalio.Direction.OUTPUT

        self.dataPin = digitalio.DigitalInOut(self.dataPinNum)
        self.dataPin.direction = digitalio.Direction.OUTPUT

    
    def shift_update(self, bits):
      #put latch down to start data sending
      self.clockPin.value = False
      self.latchPin.value = False
      
      #load data in reverse order
      for i in range(7, -1, -1):
        self.clockPin.value = False
        self.dataPin.value = int(bits[i])==1
        #print(int(bits[i])==1)
        self.clockPin.value = True

      #put latch up to store data on register
      self.clockPin.value = False
      self.latchPin.value = True

    def show(self, digit, dp=False):
        #          Pabcdefg
        digits = {
            "0" : "10000001",
            "1" : "11001111",
            "2" : "10010010",
            "3" : "10000110",
            "4" : "11001100",
            "5" : "10100100",
            "6" : "10100000",
            "7" : "10001111",
            "8" : "10000000",
            "9" : "10001100",
            "a" : "10001000",
            "b" : "11100000",
            "c" : "10110001",
            "d" : "11000010",
            "e" : "10110000",
            "f" : "10111000",
        }
        bits = digits.get(digit,"")
        if len(bits)==0:
            bits = "11111111"
        if dp:
            _bits = list(bits)
            _bits[0]= "0"
            bits = "".join(_bits)
            
        self.shift_update(bits)