Could you explain why it is the best way ? Is it really better than using gpios internal pullups ?
I just wonder what is the gain with this configuration, cause if i would have to add two resistor for each button, it should be for something
dan3008 wrote:Pays your money, takes your choice
I would like to point out that this method of constantly poling the GPIO is taxing to the processor. That may not be an issue for your build, especially if you are emulating older systems/games, or if your objective is to keep the part count/cost low. A solution if this is a problem would be to "offload" the polling of the GPIO to a smaller, less capable processor, and have that one report to the Pi when it has an interrupt. An Arduino is more than capable of this, and there are examples online that can be found through a quick Google searchlunarkingdom wrote:Pi B+ 40 pin GPIO how to use buttons and how many can I use?
I am using all digital buttons for a 2 player arcade build, I have two pieces of this joystick:
http://www.digikey.com/product-detail/e ... ND/2138044
I also have 20 of these buttons:
http://www.ebay.com/itm/321440527437?_t ... EBIDX%3AIT
My B+ Pi pinout is:
Is there an easy to understand tutorial to do this? I want to make 2 players each have a joystick (4 gpio pins and a ground X 2), 4 action keys (4 gpio pins and a ground X 2), a select and a start key (2 gpio pins and a ground X 2). If I connect them to the pins I mentioned can I just start an emulator and configure the buttons by using them or will there be code to write? Am I missing anything? Your help is much appreciated, thank you.
Code: Select all
#!/usr/bin/env python2.7 import RPi.GPIO as GPIO import signal import sys import time def gpio5clicked(channel): print 'GPIO5 Clicked!' def gpio6clicked(channel): print 'GPIO6 Clicked!' def gpio13clicked(channel): print 'You pressed GPIO13 !' def signal_handler(signal, frame): print 'Quiting ...!' GPIO.cleanup() # clean up GPIO on CTRL+C exit quit() GPP1=5 GPP2=6 GPP3=13 GPIO.setmode(GPIO.BCM) GPIO.setup(GPP1, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(GPP2, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(GPP3, GPIO.IN, pull_up_down = GPIO.PUD_UP) signal.signal(signal.SIGINT, signal_handler) GPIO.add_event_detect(GPP1, GPIO.FALLING, callback=gpio5clicked, bouncetime=300) GPIO.add_event_detect(GPP2, GPIO.FALLING, callback=gpio6clicked, bouncetime=300) GPIO.add_event_detect(GPP3, GPIO.FALLING, callback=gpio13clicked, bouncetime=300) while True: time.sleep(1)