I'm trying to figure out a fail-safe way to provide an output on GPIO pin of the Pi that would not be vulnerable to my (possibly) buggy code crashes. Is there a surefire way to do so?

Scenario: I need to put GPIO pin to HIGH for up to 30 seconds, while I observe sensor data to make a determination of what happens. If I observe desired conditions are met earlier, I need to pull pin LOW. But if my code crashes, I don't want the pin to remain HIGH for an hour or a day while I figure out that my code crashed.

Short of building a separate circuit (something like 555 timer), is there a way to do this with SoC instructions that would continue in a case of a crash?

PS: Just to clarify, the kind of crash I'm talking about is not Raspberry Pi crash, it's my application crash. Pi will continue idling, while my python process terminates unexpectedly.

  • 3
    use a watchdog timer
    – jsotola
    Commented Jan 12, 2020 at 22:21

1 Answer 1


pigpio will probably let you do what you want using waves.

The following command line example uses pigs to set GPIO 4 high for 7 seconds.

pigs m 4 w                    # set GPIO 4 to mode output
pigs wvag 16 0 7000000 0 16 0 # wave to switch GPIO 4 high for 7 seconds, then off
pigs wvcre                    # create wave (should return wave 0)

pigs wvtx 0                   # transmit wave 0

You can do the same using the pigpio Python module. Even if the script crashes the GPIO will be switched off at the conclusion of the wave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.