andig2 wrote:I'm trying to get pwm working by "dimming" an LED up and down:
- Code: Select all
def pwm_dimm(io):
pin = 1 # only supported on this pin
io.pinMode(pin,io.OUTPUT)
while 1:
print "Up"
for i in range(0,1024,16):
io.pwmWrite(pin, i)
time.sleep(DELAY)
print "Down"
for i in range(1024,0,-16):
io.pwmWrite(pin, i)
time.sleep(DELAY)
This does very much not work- the LED just stays on. The pin is correctly wired as using digitalWrite I can flash the LED.
Any ideas?
I'm not a Python programmer, but I did write wiringPi

Before you use the single PWM pin on your Pi, you need to set it into PWM mode - and I don't see that in your code above - I do see you setting it to an output though. This won't work. Do whatever you need to do via the Python wrappers to set it into PWM mode. Maybe:
io.pinMode(pin,io.PWM)
?
You also need to call some sort of wiringPi setup code too, but maybe you're doing this elsewhere.
And remember that there are 2 ways to initialise wiringPi - the wiring native mode uses pin 1 (which you're using here), or the hardware bcm-gpio mode when it would be pin 18.
(and I wish I've never bothered listening to people who wanted the bcm_pin numbering mode and stuck to wiringPi numbers, but that's another story!)
-Gordon