I wanted to use my 4x4 numpad with my Raspberry Pi 3B+ and followed the instructions of this YouTube tutorial: https://www.youtube.com/watch?v=yYnX5QodqQ4 but I got the following error:
RuntimeError: You must setup() the GPIO channel first
This is my Python code:
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
MATRIX = [ [1,2,3,'A'],
[4,5,6,'B'],
[7,8,9,'C'],
['*',0,'#','D'] ]
ROW = [7,11,13,15]
COL = [12,16,18,22]
for j in range(4):
GPIO.setup(COL[j], GPIO.OUT)
GPIO.output(COL[j], 1)
for i in range(4):
GPIO.setup(ROW[1], GPIO.IN, pull_up_down = GPIO.PUD_UP)
try:
while(True):
for j in range(4):
GPIO.output(COL[j],0)
for i in range(4):
if GPIO.input(ROW[i]) == 0:
print MATRIX[i][j]
while(GPIO.input(ROW[i]) == 0):
pass
GPIO.output(COL[j],1)
except KeyboardInterrupt:
GPIO.cleanup()
I tried to change GPIO.setmode(GPIO.BOARD)
to GPIO.setmode(GPIO.BCM)
and to remove GPIO.cleanup()
but nothing worked. Does anyone have an idea how to solve this problem?
Thanks in advance!