When I execute this little scripteverything works until the final call to cleanup() when I get the error messageIf I remove the "GPIO.cleanup()" line the script executes with out any problem. Using cleanup in another little scriptworks without problem. It's probably safe to use RPi.GPIO.PWM without the cleanup, but I'm curious as to what's going on since this is just part of a larger project that is using several more GPIO pins. Am I not doing something that needs to be done before finishing up a script using PWM? I'm running this on a Pi4B using a fully updated version of Bookworm with labwc.
Code:
#!/usr/bin/pythonimport RPi.GPIO as GPIOfrom time import sleepGPIO.setmode(GPIO.BCM)GPIO.setup(12, GPIO.OUT)pwm = GPIO.PWM(12, 500)pwm.start(99)sleep(2)pwm.stop()GPIO.cleanup()Code:
Exception ignored in: <function PWM.__del__ at 0x7f8d8b1da0>Traceback (most recent call last): File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 179, in __del__ File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 202, in stop File "/usr/lib/python3/dist-packages/lgpio.py", line 1084, in tx_pwmTypeError: unsupported operand type(s) for &: 'NoneType' and 'int'Code:
#!/usr/bin/pythonimport RPi.GPIO as GPIOfrom time import sleepGPIO.setmode(GPIO.BCM)GPIO.setup(12, GPIO.OUT)GPIO.output(12, GPIO.HIGH)sleep(2)GPIO.output(12, GPIO.LOW)GPIO.cleanup()Statistics: Posted by rquint — Tue Jul 22, 2025 5:31 pm