Close

Wiring - two steps forward, one step backward

A project log for Thumb Term

Battery powered Linux-terminal handheld with front and rear inputs, 4.3" DSI LCD, a Pi 3A+, and GPIO breakout. WIP.

dan-a8ksh4Dan (a8ksh4) 07/19/2023 at 01:080 Comments

I just finished wiring up the keyboard and 5-way switches and wrote a bit of micropython code to test them.  None of the 5-way switches are working, but all of the front keyboard buttons seem to work!  I'm not sure, but I must have wired the diodes backward on the 5-way switches...  Maybe I can fix this in software?  I might need to re-make them.

Here's the test code I'm using to matrix scan rows/cols and print which buttons are pressed on the console

from machine import ADC, Pin
import time

ROWS = (2, 3, 4, 5, 17, 16)
COLS = (6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

cols = [Pin(n, Pin.OUT, value=0) for n in COLS]
rows = [Pin(n, Pin.IN, Pin.PULL_DOWN) for n in ROWS]
all_buttons = [(c, r) for r in rows for c in cols]

def getValues():
    out = []
    for n, (c, r) in enumerate(all_buttons):
        c.on()
        if r.value():
            out.append(n)
        c.off()
    return out

while True:
    print(getValues())
    time.sleep(1)

Discussions