For a update to a small robot I am doing, I am controlling a robot using the Pi. This works very well but I would like to add more precise control, using PWM on the H bridge that controls the motors, similar to what is described here. My problem is that the Pi only seems to have one available (GPIO hardware) PWM output, so I can't easily variably control more than one motor in one direction.

I do already know of the following additional options

  • software-based PWM (examples: [ 1] [2])
  • additional hardware that can do multiple PWM outputs (example)

Which may be easier, but I think one other way I could use it is to get the Pi's solitary GPIO PWM output to output a signal (which can be used to half power the motors when needed), and then use SOMETHING to send the signal to the relevant H bridge inputs when needed: enter image description here
This would be part of a circuit that would also does other stuff - e.g. alternatively supplies a full signal to the motor controller input(s) so the motors go at full speed

My question, is what would be the best way to control where the signal goes from the Pi?. NPN transistors etc will likely mess up the signal, and most relay are overkill for this sort of need thing.

Using a Raspberry Pi 1 B (probably will upgrade to Pi 2 when have enough time/money), with L293D chips (the same as in that Adafruit article) to control two sets of motors.

1 Answer 1


Recent Pis (40 pin expansion header) have two harware PWM channels.

In addition my pigpio library can generate hardware timed PWM on all the GPIO on the expansion header. Hardware timed PWM does not suffer from the jitter inherent in software timed PWM and is suitable for servos and LEDs as well as the rather less demanding motor speed control.

  • Thank you, I thought there would be a better alternative :) I'll try it now
    – Wilf
    Nov 10, 2015 at 22:52
  • Err is it best to install from github version or the abyz.com version?
    – Wilf
    Nov 22, 2015 at 16:43
  • 1
    For the library it doesn't make any difference. They should both be version 41 currently. The github archive include some examples but there are far more examples on the abyz site.
    – joan
    Nov 22, 2015 at 17:14

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.