At the first part of the code(Initializing relays) the GPIO output works as expected, but at the second part it doesn’t works, I have break my head for the last four hours trying to find out what is happening here…
The updateGPIOstatuses method is executed as a thread:
_thread.start_new_thread(updateGPIOstatuses,(gpioCheckerInterval,pins,))
The actual behaviour is: The second part of this code doesn’t turn on the relay from the relay board… But at the first part it does the job.
Any idea?
def updateGPIOstatuses(gpioCheckerInterval,gpioConfig):
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
gpioConfig=[19]
#First part
print('Initializing relays')
for i in gpioConfig:
print('Relay '+str(i)+' on..')
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(i, GPIO.LOW)
time.sleep(0.5)
print('Relay '+str(i)+' off..')
print('Initialization done')
#Second part
while True:
#statuses=dbQuery('2','')
statuses={'gpio8': 0, 'gpio7': 0, 'gpio10': 0, 'gpio4': 0, 'gpio2': 0, 'gpio1': 1, 'device': '1', 'gpio5': 0, 'gpio3': 0, 'gpio9': 0, 'gpio6': 0}
time.sleep(0.5)
after=''
print(' ')
j=1
for i in gpioConfig:
newState=statuses['gpio'+str(j)]
j+=1
if newState==1:
print(1)
GPIO.output(i, GPIO.HIGH)
time.sleep(0.5)
else:
print(0)
GPIO.output(i, GPIO.LOW)
time.sleep(0.5)
time.sleep(gpioCheckerInterval)
EXTRA: I forget to mention, the relay phisical state changes in the first part, but not in the second one, if I check the pin state at the second part after changing the pin value I get the correct value, but it doesn’t correspond to the phisical state of the current relay.
In resume, seems like the pin is correctly settled but the relay doesn’t, and as I said, only in the second part.
-
1Your code is really confusing. You are passing in gpioConfig then setting it to [19] is that your intention? – CoderMike 1 hour ago
-
1Does HIGH or LOW turn your relay on? – CoderMike 1 hour ago
-
1setting it to 19 just for this example, normally it is passed from outside, I just want to test with one pin – Martin Ocando Corleone 36 mins ago
-
1Yes, HIGH or LOW toggles the relay in the first part but not in the second one – Martin Ocando Corleone 36 mins ago
-
1I added an extra info – Martin Ocando Corleone 32 mins ago
Categories: Uncategorized