PWM Python Probleme - Raspberry Pi Forums


hallo zusammen,

ich bin dabei eine led anzusteuern, aber das ich sie von der helligkeit dimmen kann. das stichwort pwm. wenn ich normal via:
gpio mode 1 pwm
gpio pwm 1 50

die helligkeit einstellen möchte funktioniert das ganze problemlos. nur möchte ich das ganze mit einem python programm machen und ab da gibt es schwierigkeiten. ich habe auch verschiedene codes ausprobiert von diversen seiten, hier ein beispiel:

code: select all

import rpi.gpio gpio        #this line alone caused 90 minutes of frustration  import time  gpio.setmode(gpio.board)  gpio.setup(21, gpio.out) #set pin 21 output  p = gpio.pwm(21,50)        #set pwm on pin 21 50%  p.start(0) #i don’t remember trust me, need it.  try:  while true:  in range (100):  p.changedutycycle(i)  time.sleep(0.02)         #these last 3 lines going loop , increase power 1% 100% gradually  in range(100):  p.changedutycycle(100-i)  time.sleep(0.02)         #these 3 lines loop , decrease power 100%-1% gradually  except keyboardinterrupt:  pass                   #this supposed stop program if key hit, doesn’t work us.  ctrl^c works  p.stop()  gpio.cleanup() 
link zu seite => http://raspberrypikid.wordpress.com/201 ... pberry-pi/

dann bekomme ich folgende fehlermeldung:
./pwmt.py: 1: ./pwmt.py: import: not found
./pwmt.py: 3: ./pwmt.py: import: not found
./pwmt.py: 5: ./pwmt.py: syntax error: word unexpected (expecting ")")

ich daraus verstehe ist einmal ein einfacher syntaxfehler bzw. ein falsches zeichen und das die rpi.gpio nicht gefunden wird. ich habe diese aber installiert mit "sudo aptitude install python-rpi.gpio" (eventuell leicht abgewandelt). auch python-dev etc ist installiert. ich finde den fehler nicht warum der interpreter meint die library wäre nicht da. hinzu kommt das die ja seit dem letzten update von raspbian wheezy mit dabei sein soll.
hier ein weiterer code den ich getestet habe.
=> http://www.gtkdb.de/index_31_2307.html

hier verstehe ich jedoch das damit auch kein dimmen ermöglicht werden soll. meine led blinkt nur.
in kürze ist mein ziel mit python eine led beliebig zu dimmen.
ich bedanke mich schon jetzt für alle hilfen :)

pigpio
python

chmod +x led-pwm.py
sudo pigpiod
./led-pwm.py

manually cut & paste.

code: select all

#!/usr/bin/env python  # 2014-07-04 # led-pwm.py  import time  import pigpio  led=22 # broadcom gpio numbers  pi = pigpio.pi() # connect local pi.  pi.set_mode(led, pigpio.output)  pwm = 0 inc = 1 step = 3  start_time = time.time()  while (time.time() - start_time) < 60:     print(pwm)       pi.set_pwm_dutycycle(led, pwm)     pwm += (step * inc)     if pwm > 255:       pwm = 255       inc = -1    elif pwm < 0:       pwm = 0       inc = 1     time.sleep(0.2)  pi.set_pwm_dutycycle(led, 0)  pi.stop() 


raspberrypi



Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62