Uncategorized

gpio thread

Asked 
Viewed 8 times
1

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.

Categories: Uncategorized

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.