Felix,
Thank you for the extra pair of eyes much appreciated, I got so obsessed with the PULL_UP/PULL_DOWN issue, I didn't even consider the processing order of the bitwise logic!! Many thanks.
Martyn
Felix,
Thank you for the extra pair of eyes much appreciated, I got so obsessed with the PULL_UP/PULL_DOWN issue, I didn't even consider the processing order of the bitwise logic!! Many thanks.
Martyn
Hi, I've sucessfully installed the most recent ESP32S3 build of Micropython on my M5Stack CardComputer. Due to it being a generic build, there are no specific device drivers included with the firmware; however, I've managed to get some integrated peripherals working, ie the LCD, sdCard.
The keyboard (schematic) in giving me some problems, its a pretty standard key matrix, the rows are provides using a 74hc138 3-8 line decoder, and the columns are 7 GPIOs. The outputs from the decoder are active low (datasheet), so I made the column pins inputs with pullups - doesnt work, needs pulldowns????
Reading the column pins whilst iterating through the 8 rows should allow the individual key detection, but although key presses yield a pin change it doesn't work as expected and column 2 is always high???
from time import sleep_ms
from machine import Pin
'''
M5Stack CardComputer Keyboard
74HC138 3 to 8 line decoder
Decoder Pin A2, A1, A0 ----\ Y6, Y5, Y4, Y3, Y2, Y1, Y0
GPIO Pin G11, G9, G8 ----/ G7, G6, G5, G4, G3, G15, G13
'''
class KeyBoard():
def __init__(self):
keyPins = [ ('C0', 13, Pin.IN, Pin.PULL_DOWN), ('C1', 15, Pin.IN, Pin.PULL_DOWN), ('C2', 3, Pin.IN, Pin.PULL_DOWN),
('C3', 4, Pin.IN, Pin.PULL_DOWN), ('C4', 5, Pin.IN, Pin.PULL_DOWN), ('C5', 6, Pin.IN, Pin.PULL_DOWN),
('C6', 7, Pin.IN, Pin.PULL_DOWN),
('A0', 8, Pin.OUT, None), ('A1', 9, Pin.OUT, None), ('A2', 11, Pin.OUT, None) ]
ap = dict()
for (name, pin, direction, pull) in keyPins:
self.pinMap[name] = Pin(pin, direction, pull)
def scan(self):
for row in range(0,8):
self.pinMap['A0'].value( row & 0b001 )
self.pinMap['A1'].value( row & 0b010 >> 1 )
self.pinMap['A2'].value( row & 0b100 >> 2 )
sleep_ms(250)
print(f'{row:04b}\t',end='')
for col in ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6']:
sleep_ms(0)
val = self.pinMap[col].value()
print(f'{val:01b} ', end='')
print('')
print('\n\n\n\n')
keyboard = KeyBoard()
while True:
keyboard.scan()
sleep_ms(500)
Any ideas of where I'm going wrong??