Skip to content

GPIO pins fail to connect on first try on RaspberryPi #10

Description

@rwdavis513

When initializing the pins on Raspbian, there appears to be a timing issue between the /sys/class/gpio/export and the write to /sys/class/gpio/direction

periphery/gpio.py

After running the code the first time the pin is added to the /sys/class/gpio/gpio{pin_number} list and therefore it works on the second try.

It looks like it could be addressed by adding a wait time if it fails. Here's a wrapper which addresses the issue:

for _ in range(number_of_attempts): try: gpio_pin = GPIO(pin, direction) break except GPIOError as e: if _+1 == number_of_attempts: raise e time.sleep(0.05) return gpio_pin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions