I have been trying to use the Python GPIO PWM to control a set of LEDs connected to my RPi. When I run the Python script, I get the following error:
Traceback (most recent call last):
File "cycle.py", line 12, in <module>
r = GPIO.PWM(f, RED)
RuntimeError: No access to /dev/mem. Try running as root!
I have tried running the script as root (both with sudo and with actually logging in as root). All of the other GPIO functions work correctly and I have tried doing an update and uninstalling/reinstalling python-rpi.gpio through apt. Here is the code I have been running.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
RED = 11
f = 100
r = GPIO.PWM(RED, f) <== Where it crashes
r.start(0)
try:
while 1:
for dc in range(0, 101, 5):
r.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, 5):
r.ChangeDutyCycle(dc)
time.sleep(0.1)
except:
pass
r.stop()
GPIO.cleanup()
It is based off of the example found here, but there could still be bugs. I have been struggling with this for quite a bit now so any help provided would be greatly appreciated. Thanks!