Using pi4j and wiring pi configuring hardware pwm pins for driving servo motors. Also using freetts (speech to text) library for speech. My speaker is actually connected to amplifier to 3.5 mm jack (configured as mono).

I need both servo and audio work. Individually they both work fine. But I have a strange issue of whenever pwm output for pin is provisioned by my code, audio hangs forever thereafter.

Even omxplayer is hanging and need ctrl+c to terminate. Only reboot solves the problem.

I tried different options like choosing one of 4 pwm pins, connecting a bluetooth speaker instead of 3.5 jack, resetting the pin mode to (input or output) once servo moved.

I never tried hdmi audio and that is not an option for me right now.

Please help me how to resolve this. I am still learning so any pointers are great. Thanks!!

1 Answer 1


The PWM GPIO are used to generate the audio for the 3.5 mm jack (and presumably for Bluetooth). This usage is incompatible with them being used to drive servos at the same time.

There are a number of solutions:-

  • buy a hardware PWM generator and use that to drive the servos. E.g. a PCA9685 based module which connects via I2C.
  • use one of the software modules which use DMA to generate suitable (stable) pulses to the servos. They allow the use of any spare GPIO. E.g. servoblaster or (my) pigpio.
  • That answer clarifies. Will try them. But all four 4 pwms are unusable if i drive servo? even if i want to have only mono audio? Also why audio hangs even if program re configured them as normal io pins? Or that program is terminated. ?
    – RaspiFan
    Dec 1, 2018 at 12:58
  • There are two PWM channels (each channel is available on two GPIO). There is only one PWM clock shared by both channels. The clock is probably the conflict - servos will want 50 Hz or so, audio will want 15kHz or so. As to why it hangs I don't know, it's not something I have tried.
    – joan
    Dec 1, 2018 at 13:06
  • Servoblaster in pcm mode works great and solved my problem.!!
    – RaspiFan
    Dec 2, 2018 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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