From bfb2290634e3c5d71884063d4ea015631059cd78 Mon Sep 17 00:00:00 2001 From: Joan Date: Wed, 31 Dec 2025 13:00:47 +0100 Subject: [PATCH] Add GPIO button test script --- test_buttons.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test_buttons.py diff --git a/test_buttons.py b/test_buttons.py new file mode 100644 index 0000000..1bddabc --- /dev/null +++ b/test_buttons.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +""" +GPIO Button Test Script +Run this on the Raspberry Pi to identify which GPIO pins the buttons are on. +Press Ctrl+C to exit. +""" +import time + +try: + import RPi.GPIO as GPIO +except ImportError: + print("RPi.GPIO not found. Install with: sudo apt install python3-rpi.gpio") + exit(1) + +# Common GPIO pins to test (BCM numbering) +# Excluding pins used by the LED matrix (typically 2-27 are used by the matrix) +# These are additional GPIO pins that might be available +TEST_PINS = [4, 5, 6, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27] + +def main(): + print("=" * 50) + print("GPIO Capacitive Button Test") + print("=" * 50) + print("\nSetting up GPIO pins for input with pull-up resistors...") + print("Press buttons to see which GPIO pin responds.") + print("Press Ctrl+C to exit.\n") + + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + # Set up all test pins as inputs with pull-up + active_pins = [] + for pin in TEST_PINS: + try: + GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + active_pins.append(pin) + except Exception as e: + print(f" Pin {pin}: Could not configure ({e})") + + print(f"Testing pins: {active_pins}\n") + + # Store previous states to detect changes + prev_states = {pin: GPIO.input(pin) for pin in active_pins} + + try: + while True: + for pin in active_pins: + current = GPIO.input(pin) + if current != prev_states[pin]: + if current == GPIO.LOW: + print(f">>> Button PRESSED on GPIO {pin} <<<") + else: + print(f" Button released on GPIO {pin}") + prev_states[pin] = current + time.sleep(0.05) + except KeyboardInterrupt: + print("\n\nTest complete.") + finally: + GPIO.cleanup() + +if __name__ == "__main__": + main()