0

I've got a python script that uses RPi.GPIO to exercise some solenoids connected to two Pi Zero 2Ws. Both are running 64 bit Raspberry PI OS and both are up-to-date (bookworm).

On one of them, everything works fine. On the other, it does nothing at all.

On the Pi that isn't working, manually exercising the pins with pinctrl does work just fine. The two scripts are identical. I have checked the installed versions of everything GPIO related and they're identical. The hardware is identical. config.txt is identical. cmdline.txt is identical except for the partition UUID.

The script:

import RPi.GPIO as GPIO
import time

# GPIO numbers for the chimes. 0-3 are low-high quarters, 4 is hour gong.
# These are the BCM numbers
channels = [17, 18, 27, 22, 23]

# 20 ms solenoid pulses
solenoid_time = 0.02

def do_chime(chime):
        if (chime >= len(channels)):
                return
        GPIO.output(channels[chime], GPIO.HIGH)
        time.sleep(solenoid_time)
        GPIO.output(channels[chime], GPIO.LOW)

try:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(True)
        GPIO.setup(channels, GPIO.OUT, initial=GPIO.LOW)

        for pin in range(5):
                do_chime(pin)
                time.sleep(0.5)

finally:
        GPIO.cleanup()
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.