it returns all 0's when nothing is pressed all 1's all 0's or a mixture depending on which keys are pressedAnd here's the code with updated comments, but focused only on the first 8 bits:Code:
# Code for shift-register based keypad# Raspberry Pi Pico connected to keypad PCB# via JP1 (14-pin IDC header). Keypad is# constructed from nine '165 shift registers# in series, therefore 72 bits to shift out.# Connect Pico pin 36 (3V3 OUT) to JP1 pin 14 (VCC)# Connect Pico pin 38 (GND) to JP1 pin 1 (GND)# Connect Pico pin 1 (GP0) to JP1 pin 4 (DATA)# Connect Pico pin 4 (GP2) to JP1 pin 6 (CLK)# Connect Pico pin 5 (GP3) to JP1 pin 8 (~PL)# Import libraries we needfrom machine import Pin# GPIOs connected to keypad PCB dataPIN = 0 latchPIN = 3 # Active lowclockPIN = 2 # Shift data on rising edge# Set up pin objects# Pull-up not needed on data pin because it is driven externallydata=Pin(dataPIN, Pin.IN)# Include initial pin states herelatch=Pin(latchPIN, Pin.OUT, value=1)clock=Pin(clockPIN, Pin.OUT, value=0)# Shift out registers from the PCB and show the valuelatch.value(0) # Latch pins into registerlatch.value(1)# For testing look at the first 8 bitsfor i in range(8): print("D%s %s"%(7-i,data.value())) # Bits are shifted out MSb (bit 7) first clock.value(1) # Clock out next bit clock.value(0)
Statistics: Posted by tom2 — Sun May 19, 2024 12:17 am