1

I'm trying to change the brightness of a led (as simulator for a motor) by means of PWM on a GPIO pin of my raspberry pi (3B). But whenever i try to run my code, it gives the error

'RPi.GPIO.PWM' Object has no attribute 'changeDutyCycle'

However, this is proven wrong by both the documentation and this code that gets an iteratable list of all methods of an object. I copy-pasted the method to be sure to have no spelling errors, but it still doesn't work.

The code i use is:

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
p = GPIO.PWM(3, 50)
p.start(5)
time.sleep(0.5)
p.changeDutyCycle(95)
time.sleep(0.5)

The code crashes on line 9 (The second last line). The code above is only the relevant piece of the code so the resource cleanup is omitted.

I'm wondering what the error is caused by. Is it something i'm doing wrong in python, or should I look for the cause in one of my Raspberry Pi configurations?

Edit 1

Traceback, as kindly requested by jojo:

Traceback (most recent call last):
File "~/Documents/test.py", line 9, in <module>
p.changeDutyCycle(95)
AttributeError: 'RPi.GPIO.PWM' object has no attribute 'changeDutyCycle'
j-i-l
  • 10,281
  • 3
  • 53
  • 70
  • well, now you could google something like "RPi changeDutyCycle" and you would find sites talking about **C**hangeDutyCycle... so, just maybe... it was the small *c*... – j-i-l May 01 '17 at 11:24
  • The answer was first given in the comments. Please consider accepting the commutiny wiki answer as the correct one. One should not get credit from copying an answer form the comments to the answer bar. And no one gets credit in a community wiki answer. – j-i-l May 01 '17 at 11:34

1 Answers1

0

original answer from comments:

The function uses capital c, so p.ChangeDutyCycle(95) should do the trick.

j-i-l
  • 10,281
  • 3
  • 53
  • 70