I'm working on a project that needs three (or more) PWM pins to work. But unlike Arduino, the Raspberry PI B+ has just one PWM pin. I've searched for solutions and I found that I can use the WiringPi to emulate PWM using software. Is this the best solution? Anybody has a better one?

  • What specifically are the three PWM pins for? – goldilocks Jan 18 '16 at 12:53
  • Acceleration control and Servo. – bodruk Jan 18 '16 at 12:54
  • 1
    There's also pigpio that can do software PWM, see raspberrypi.stackexchange.com/questions/41140/… Sorry, Joan, I didn't see your answer while posting this comment. Anyway the linked Q&A is related - to whom it may concern. – Ghanima Jan 18 '16 at 15:04

The Raspberry Pi B+ has two accessible dedicated hardware PWM channels.

Hardware timed PWM is available on all the accessible GPIO.

See my pigpio library.

  • Is this a good solution for servos and acceleration control? – bodruk Jan 18 '16 at 13:13
  • 1
    Yes to servos. What do you mean by acceleration control? If you mean varying a DC motor speed then yes. – joan Jan 18 '16 at 13:21
  • Is this lib similar to WiringPi? – bodruk Jan 18 '16 at 13:41
  • Not really. The library is written in C. That's the only thing in common. – joan Jan 18 '16 at 14:23

Studying the WiringPI library I found that I can easily handle the PWN on any pin:

# GPIO port numbers  
import wiringpi2 as wiringpi  
wiringpi.pinMode(25, 0) # sets GPIO 25 to input  
wiringpi.pinMode(24, 1) # sets GPIO 24 to output  
wiringpi.pinMode(18, 2) # sets GPIO 18 to PWM mode 
  • I'm not sure if wiringPi can drive both the dedicated PWM channels. wiringPi PWM on arbitary GPIO will be software timed, servos in particular may have problems with jitter. – joan Jan 19 '16 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.