Electronic – understanding how a motor is controlled with an L293D and raspberry pi

dc motorpwmraspberry pi

See update, picture of robot below.

So today I hooked up a motor and made it spin with my raspberry pi and an L293D by reading this tutorial.

This is what the circuit looks like (larger pictures):

Controlling motor with RPi

It work's and I'm pretty happy. My end goal is to understand this and build something that can control two motors and I'm set to build a small bot 🙂

My issues:

If I'm not mistaken in this circuit, the enable pin on the L293D is getting a PWM signal for the speed of the motor it drives.

  1. From the software page I can follow what the python is doing but I don't see where it says that pin 18 on the raspberry GPIO should be enabled as PWM? The docs say that Pin 12 supports PWM ? How does this work?

  2. What if I didn't care about speed? Can I just use an regular GPIO pin for output a high on the enable of the L293D? With the Pi I'm assume that would out a 3.3v? And if I'm looking at the datasheet correct the enable pin can take upto 7v as a high? (What speed would it run on?)

  3. Also again, if I didn't care about speed control, I could hook another GPIO to the second enable and control another motor also right. And I can then control each of they're directions?


Update:

Thanks @Passerby and @JImDearden I got it to work. No PWM, but just two motors. Like @Passerby says, I need three GPIO's for each motor. One for enable/disable and two for direction.

Here is what I made 🙂 And it's wifi network controlled (with a wifi dongle attached) The cable is just a USB power cable 🙂

Pi Tri wheel robot

Best Answer

From the software page I can follow what the python is doing but I don't see where it says that pin 18 on the raspberry GPIO should be enabled as PWM? The docs say that Pin 12 supports PWM ? How does this work?

Not knowing the specifics of the RPI GPIO Library that Adafruit uses, but looking at the page you link to, it enables it with set("mode", "pwm"). As it says, The Python program first sets-up the two GPIO pins to be outputs. It then defines the same convenience function (“set”) that we used in Lesson 8, to write to the PWM Kernel Module. This is then used to set the parameters for PWM. The RPI hardware PWM is enabled through that library.

What if I didn't care about speed? Can I just use an regular GPIO pin for output a high on the enable of the L293D? With the Pi I'm assume that would out a 3.3v? And if I'm looking at the datasheet correct the enable pin can take upto 7v as a high? (What speed would it run on?)

Yes, you can do that. It would run at 100%, because you simply toggled the pin on. The voltage at the pin is not what sets the speed, but simply how fast you turn the pin off or on in a given time period that does. Like flipping a light switch on and off fast enough that it seems like the lights are only half on.

Also again, if I didn't care about speed control, I could hook another GPIO to the second enable and control another motor also right. And I can then control each of they directions?

Yes, but you would actual need three gpio to control both directions of one motor. 1 for the motor enable (on/off), and 2 for the motor 2 direction. Exactly as it is now, except without pwm.