# [SCRAPEBOARD] is an arcade game in development by [@diskmem] & [@snakesandrews] # # It requires custom hardware to play but can be tested in keyboard mode without # the hardware. For more information on setting up and running the game, see # README.md, or for the game in general, visit . # # Full open source code is available at . # # This is a utility script for testing if the GPIO interface of a Raspberry Pi is working # with the four input wires, which correspond to the four metal floor pads in the standard # Scrapeboard build. import time, itertools import RPi.GPIO as GPIO # These represent the game pads and the GPIO pins they're connected to LNW, LNE, LSE, LSW = range(4) pins = { LNW: 17, LNE: 27, LSE: 22, LSW: 23 } def connection2(pin_a, pin_b): """ Set `pin_a` to output a low signal, and set every other pin to pullup. If `pin_b` reads a low signal even though it's set to pullup, that means `pin_a` is connected to it, so return `True`. @param pin_a Pin which will be set to output LOW @param pin_b Pin which will be read @return `True` if a low signal is sent from `pin_a` to `pin_b`, `False` otherwise """ for pin_id, pin in pins.items(): if pin == pin_a: # Set pin_a to output LOW GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW) else: # Set all other pins to input pullup GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pin_b can now be tested to see if if reads the LOW signal from pin_a return GPIO.input(pin_b) == GPIO.LOW def connection(pin_a, pin_b): """ Tests low signals connect from both A to B and from B to A @param pin_a Test if this pin is connected to `pin_b` @param pin_b Test if this pin is connected to `pin_a` @return `True` if `pin_a` and `pin_b` are connected, `False` otherwise """ return connection2(pin_a, pin_b) and connection2(pin_b, pin_a) def connections(): """ Look at all six possible connections between the four pins and print a message if one is found connected. """ for pin_id_a, pin_id_b in itertools.combinations(pins, 2): if connection(pins[pin_id_a], pins[pin_id_b]): print(f"{pin_id_a} ({pins[pin_id_a]}) <-> {pin_id_b} ({pins[pin_id_b]})") if __name__ == "__main__": # Use GPIO numbering GPIO.setmode(GPIO.BCM) # Set all pins to pullup for pin_id, pin in pins.items(): GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: # Try all connections once each frame connections() time.sleep(0.1)