User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

pigpio for pwm

Wed Apr 26, 2017 2:32 pm

Hello,
I'm using Joan's great pigpio library to read two DHT sensors on a Pi to register in- and outside temperature of my greenhouse. The next step is to add some PWM outputs to operate a couple of fans. I've looked through the functions and I'm sure this is perfectly possible. (And of course I'm not considering to connect the fan directly to the IO port. :lol: )
The question I have is whether there is an off the shelf executable (or source C-file) to perform this function like the DHTXX code I'm using for the sensors? Something where you enter the GPIO port number and the desired PWM ratio on the command line and off it goes until you change the setting.
Unfortunately I'm not that much of a C-adept and I don't feel like tinkering with this for too long. It is a standard function that I'm sure others have implemented already. Any hints are welcome!

/Leo

User avatar
joan
Posts: 14069
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: pigpio for pwm

Wed Apr 26, 2017 2:41 pm

I guess you are using the pigpio daemon. Have a look at the servo pulse example at http://abyz.co.uk/rpi/pigpio/examples.h ... rvo_demo_D.

For PWM all you need to do is use set_PWM_dutycycle() rather than the set_servo_pulsewidth() call.

You can experiment from the command line.

pigs p 4 0 # GPIO 4 PWM off
pigs p 4 128 # GPIO 4 PWM half on
pigs p 4 255 # GPIO 4 PWM fully on

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: pigpio for pwm

Wed Apr 26, 2017 4:42 pm

Hi Joan,

Thnx for your fast reply, I will give that a try.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: pigpio for pwm

Sun May 07, 2017 8:05 am

Meanwhile the setup has been tested succesfully and I can confirm that PWM works.

Thnx Joan!

Return to “C/C++”