WebIOPi.createRatioSlider(gpio, ratio) - PWM control

1,151 views
Skip to first unread message

Piotr Pawlak

unread,
Sep 15, 2015, 1:52:32 PM9/15/15
to WebIOPi
Hello everybody. I have some problem with function WebIOPI.createRatioSlider. I'm using it in my python script to control PWM but I don't have voltage on that pin (20), only when I slided to maximum I have 3,3V. On another positions voltage equals 0. Maybe somebody know what I'm doing wrong ? Below I insert screens index.html and script in python. Thanks for help :)


hal8000b

unread,
Oct 1, 2015, 12:36:02 PM10/1/15
to WebIOPi
Wrong syntax. createRatioSlider requires 2 arguments, GPIO Pin and Ratio

See this page below
http://webiopi.trouch.com/JAVASCRIPT.html


You also need to seup the pin as PWM   GPIO.PWM not GPIO.OUT
so change this line to:

def setup():
    GPIO.setFunction(PWM1,GPIO.PWM)

in your script.py


In your html page  you can change the line to
   button = webiopi().createRatioSlider(20,50);

Last number is slider initial value.
Testing this with a LED in series with a 390ohm resistor.
As the duty cycle changes, the LED brightness does too.

One last point, the voltage on the PWM pin will always be 3.3V or 0V its the amount
of on/off time that varies. Most digital meters can onlt take 3 readings/second so may not
give a true reading. At 40% PWM for example the voltage on my meter read 1.15V , but
its to slow to read the fast PWM pulses.

Hope that helps

Pete Dudash

unread,
Oct 1, 2015, 12:46:51 PM10/1/15
to WebIOPi
In addition to what hal8000b said, you could add a low pass filter (series resistor and capacitor) to the output of the PWM.  This will help filter out the digital signal to average it into a more analog signal so your meter can measure it.  The values can be picked to minimize the output ripple at a given frequency, but too much filtering will reduce the response time.  This is useful if you wanted to make your own DAC.  See this link for more info: http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/
Message has been deleted

Piotr Pawlak

unread,
Oct 3, 2015, 6:22:59 AM10/3/15
to WebIOPi
Very thanks hal8000b, I knew that I did stupid mistake. This is work correctly now :) Pete you also thanks ! :)
Reply all
Reply to author
Forward
0 new messages