0

So I am using a 16 channel relay that is connected to my Pi (https://www.amazon.com/dp/B0057OC66U/). I made a small program to turn all the relay LEDs on and then turn them off one by one with a 1 second interval. My problem is that the GPIO.cleanup() at the end of the program seems to be what turns the LEDs off and the GPIO.output(bcm,GPIO.LOW) seems to be ignored in the "tryblock". Basically now all the program does is turn all the relay LEDs on in the for loop and then prints up to "SIXTEEN" and finally the GPIO.cleanup() is what turns all the LEDs off at once.

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)


# init list with pin numbers


SleepTimeL = 1

pinList = [2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26, 21, 20]


for i in pinList:

    GPIO.setup(i, GPIO.OUT)

    GPIO.output(i, GPIO.HIGH)


try:

    GPIO.output(2, GPIO.LOW)

    print ("ONE")

    time.sleep(SleepTimeL)

    GPIO.output(3, GPIO.LOW)

    print ("TWO")

    time.sleep(SleepTimeL)

    GPIO.output(4, GPIO.LOW)

    print ("THREE")

    time.sleep(SleepTimeL)

    GPIO.output(17, GPIO.LOW)

    print ("FOUR")

    time.sleep(SleepTimeL)

    GPIO.output(27, GPIO.LOW)

    print ("FIVE")

    time.sleep(SleepTimeL)

    GPIO.output(22, GPIO.LOW)

    print ("SIX")

    time.sleep(SleepTimeL)

    GPIO.output(10, GPIO.LOW)

    print ("SEVEN")

    time.sleep(SleepTimeL)

    GPIO.output(9, GPIO.LOW)

    print ("EIGHT")

    time.sleep(SleepTimeL)

    GPIO.output(11, GPIO.LOW)

    print ("NINE")

    time.sleep(SleepTimeL)

    GPIO.output(5, GPIO.LOW)

    print ("TEN")

    time.sleep(SleepTimeL) 

    GPIO.output(6, GPIO.LOW)

    print ("ELEVEN")

    time.sleep(SleepTimeL)

    GPIO.output(13, GPIO.LOW)

    print ("TWELVE")

    time.sleep(SleepTimeL)

    GPIO.output(19, GPIO.LOW)

    print ("THIRTEEN")

    time.sleep(SleepTimeL)

    GPIO.output(26, GPIO.LOW)

    print ("FOURTEEN")

    time.sleep(SleepTimeL)

    GPIO.output(21, GPIO.LOW)

    print ("FIFTEEN")

    time.sleep(SleepTimeL)

    GPIO.output(20, GPIO.LOW)

    print ("SIXTEEN")

    time.sleep(SleepTimeL)



    print ("Good bye!")


except KeyboardInterrupt:

  print ("Quit")


GPIO.cleanup()
 # Reset GPIO settings


Your Answer

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

Browse other questions tagged or ask your own question.