1

I just wrote the following code for the sake of this question:

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)

christmas_led = (2,3,4,5,6,7,8,9)

patterns = {1:(0,1,0,1,0,1,0,1), 2:(1,0,1,0,1,0,1,0)}

for led in christmas_led:
    GPIO.setup(led, GPIO.OUT)
    GPIO.output(led, 0)

try:
    while True:
        for i in 1,2:
            for j in range(8):
                GPIO.output(christmas_led[j], patterns[i][j])
            time.sleep(0.5)

finally:
    GPIO.cleanup()

I have used for j in range(8) loop to write to outputs one by one. To my knowledge this procedure takes place in a sequential manner. Is there a way to do to write to all outputs at the same time?

1

According to raspberry-gpio-python documentation (here) you can output to several channels at the same time by passing 2 list parameters instead of 2 integers.

Example:

To output to several channels at the same time:

chan_list = (11,12)
GPIO.output(chan_list, GPIO.LOW) # all LOW
GPIO.output(chan_list, (GPIO.HIGH,GPIO.LOW))  # first HIGH, second LOW
  • It depends on what you mean by the same time. The implementation of the examples you give sequences through the list of GPIO and outputs to each GPIO in turn. The GPIO are not written at the same instance in time (i.e. the output for all GPIO is not simultaneous). – joan Dec 30 '16 at 9:46
1

My pigpio library Python module lets you clear multiple GPIO or set multiple GPIO at the same instant.

clear_bank_1 will set multiple GPIO low.

set_bank_1 will set multiple GPIO high.

Example

To set GPIO 5, 10, 23 low.

pi.clear_bank_1( (1<<5) | (1<<10) | (1<<23) )

To set GPIO 3, 6, 7 high.

pi.set_bank_1( (1<<3) | (1<<6) | (1<<7) )

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.