I'm running some testing using Python on a Raspberry Pi. Hardware is a series of SPDT relays connected to a darlington array (ULN2803) which is connected to the GPIO of a raspberry Pi B.
If I set a GPIO pin high, the corresponding relay pulls. If I set it low, it releases. I can use a loop to set all GPIO:s high, and all relays pulls, except the last one(?). But if I run time.sleep()
after the loop has set all pins high, they all get set low automagicly.
Check the code below; When it runs, it iterates through eight GPIO:s, setting one high at a time, and sleeps for 200ms between each. This works, but the last one does not get activated. After that, it sleeps for 1s, which causes all pins to go low. And then it starts iterating through them again, backwards, turning them off. As soon as its starting backwards, on first iteration, all go high again. Why is that? It does not occur within a loop, just between them. It is like when the sleep() is run outside the loop, everything reverts to how it was before the program was started.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
iopins = [4,7,8,9,10,11,17,18]
try:
for x in iopins:
GPIO.setup(x, GPIO.OUT)
GPIO.output(x,0)
while True:
for x in iopins: #turn on.
time.sleep(0.2)
GPIO.output(x, GPIO.HIGH)
time.sleep(1) #<-- causes all GPIOs to pull low...
for y in reversed(iopins): #Turning off.
GPIO.output(y, GPIO.LOW) #<--here all GPIOs pulls high upon first iteration
time.sleep(0.2)
finally:
GPIO.cleanup()
Another strange thing is that if the array IOPINS only contain one entity it does not work.