Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
606 B
0
Indexable
Never
import RPi.GPIO as GPIO

def list_active_gpios():
    GPIO.setmode(GPIO.BCM)  # Set pin numbering to Broadcom scheme
    active_gpios = []
    for pin in range(2, 28):  # GPIO pins typically range from 2 to 27 on Raspberry Pi
        try:
            GPIO.setup(pin, GPIO.IN)
            GPIO.input(pin)
            active_gpios.append(pin)
        except RuntimeError:
            continue
    GPIO.cleanup()  # Clean up GPIO to return to a clean state
    return active_gpios

if __name__ == "__main__":
    active_gpios = list_active_gpios()
    print("Active GPIOs:", active_gpios)

Leave a Comment