1

I am trying to set a GPIO port to LOW for n seconds and set it to HIGH afterwards.

The problem is that it's not at all accurate. It varies between a small number of seconds to 2*n or even more.

GPIO.setup(7, GPIO.OUT)
GPIO.output(7, GPIO.LOW)
time.sleep(n)
GPIO.output(7, GPIO.HIGH)

I understand that I can't expect a highly accurate interval but a random number is still weird.

2

The code you have should be fine.

I'd expect the resulting sleep to be within 1% of n the majority of the time (getting more accurate for larger values of n).

If you are seeing 2 times n it suggests something like:

  1. your system is exceptionally busy
  2. or the circuit you are driving has a large amount of capacitance to overcome
  3. or some other program is affecting the outcome. E.g. if you are using GPIO 4 (pin 7) the 1-wire bus may be enabled.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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