I would like to control a servo and a dc motor. I want to control the dc motor's speed by using pwm with a frequency >= 1000 Hz. The servo on the other hand expects a pwm frequency of only 50 Hz. So my idea is to control the dc motor using the hardware pwm capabalities of the pi and the servo motor using software pwm.

In particular, I use wiringPi (through Pi4J) for hardware pwm (I do not use the hw pwm methods provided by pi4j for this as they do not allow for setting the pwm frequency but I use P4J as a wrapper to access wiringPi).

I use ServoBlaster for the software pwm.

Both methods (hw and sw pwm) do work as expected when I use them alone. However, when I try to use both in a single java programm the software pwm via ServoBlaster won't work anymore. Of course I checked that hw pwm and sw pwm do not use the same pin.

Does anyone know if ServoBlaster and wiringPi do influence each other?

  • 1
    servoblaster uses hardware timed PWM (you need hardware timing for servos, software timing introduces jitter). It sounds like you are using software timing for the DC motor as I think wiringPi only supports hardware timed PWM on GPIO18 (pin 12). It may make little difference to your question but which GPIO are you using for the servo and which GPIO are you using for the DC motor speed control? – joan Jul 16 '16 at 15:16
  • I've never used either library but on a 40-pin pi you should have access to two independent hardware PWM channels, each of which has two possible pins. That's probably the best strategy so have a look at your options and pick the one which allows for this. As a random guess, it could be that one library's initialization routine screws the other one up. – goldilocks Jul 16 '16 at 18:00
  • 1
    @goldilocks ServoBlaster and wiringPi can work together fine. If ServoBlaster is using the PWM peripheral for timing that can be mucked up by wiringPi if it uses hardware PWM. There are other potential problems but we need to know which GPIO are being used. – joan Jul 16 '16 at 19:20
  • @Joan: I am using GPIO17 (pin 11) for controlling the servo via servoblaster and GPIO13 (pin 33) for controlling the dc motor via wiringPi. But you gave the decisive hint anyway: i didn't realize that although servoblaster provides software pwm it does so by using parts of the hardware pwm periphal by default. So apparantly there was indeed some hardware conflict. But since I have told servoblaster to use pcm instead of pwm for the hardware timing, everything works fine now! – user49541 Jul 17 '16 at 10:08
  • @user49541 Good that it's working. One minor comment. I draw the distinction between hardware timed PWM and software timed PWM. All PWM is software controlled. Hardware timed PWM is best, and probably essential for any serious servo/ESC and LED work. Both types are probably fine for motor control where the software timed jitter would be masked out by the motor inertia. – joan Jul 17 '16 at 11:29

Your Answer

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

Browse other questions tagged or ask your own question.