Johhny Blue Posted September 11, 2016 Share Posted September 11, 2016 Hi Everyone. I have been looking for a way to connect this keypad directly to my Orange Pi PC+ directly through gpio without resistors. https://www.adafruit.com/product/1332 I also need software (hopefully either bash or python) to read a key press and then either run a script or perform a command. If anyone here done this or even connected 1 switch to gpio (without resistors), could you please post the solution or a link to follow. Thanks. V Link to comment Share on other sites More sharing options...
martinayotte Posted September 11, 2016 Share Posted September 11, 2016 You can simply use GPIO internal pullups by enabling them. By using orangepi_PC_gpio_pyH3 ( https://github.com/duxingkei33/orangepi_PC_gpio_pyH3), python code will look like : from pyA20.gpio import gpio from pyA20.gpio import port gpio.setcfg(port.PA1, gpio.INPUT) gpio.pullup(port.PA1, gpio.PULLUP) if gpio.input(PA1) > 0: print "not pressed" else: print "pressed" 2 Link to comment Share on other sites More sharing options...
Johhny Blue Posted September 12, 2016 Author Share Posted September 12, 2016 Thanks Man. It is simple once you see it like you have written it. On some other example I can see import RPi.GPIO as GPIO Is it as simple as swapping RPi.GPIO to pyA20.gpio and matching the correct pins? V. Link to comment Share on other sites More sharing options...
Johhny Blue Posted September 12, 2016 Author Share Posted September 12, 2016 I have this python matrix keypad working on my rpi and hope someone can help me convert it to pyA20. Thanks again. #!/usr/bin/env python import RPi.GPIO as GPIO import time import os from time import sleep GPIO.setmode(GPIO.BOARD) MATRIX= [[1,2,3], [4,5,6], [7,8,9], ["u",0,"d"] ] ROW=[7,11,13,15] COL=[12,16,18] for j in range(3): GPIO.setup(COL[j],GPIO.OUT) GPIO.output(COL[j],1) for i in range(4): GPIO.setup(ROW[i],GPIO.IN,pull_up_down = GPIO.PUD_UP) try: while(True): for j in range(3): GPIO.output(COL[j],0) for i in range(4): if GPIO.input(ROW[i]) == 0: print MATRIX [i][j] print "/usr/local/bin/" + str(MATRIX [i][j])+".sh" a = str("/usr/local/bin/" + str(MATRIX [i][j])+".sh") print a os.system (a) sleep(0.2); time.sleep(0.2) while (GPIO.input(ROW[i])==0): pass GPIO.output(COL[j],1) except KeyboardInterrupt: GPIO.cleanup() Link to comment Share on other sites More sharing options...
martinayotte Posted September 12, 2016 Share Posted September 12, 2016 Should be pretty straight forward ... Only setup() needs to be changed to setcfg() along with separate pullup() call since setcfg() doesn't have the third argument. Link to comment Share on other sites More sharing options...
Recommended Posts