This thread can be considered an off-spring of this thread.
I want my RPi to drive the 2 5.4-6V DC motors that are provided with the Mr. Basic rover platform. I intend to do so by powering them by a separate 3xAA battery pack (provided with the Mr. Basic) and driving them using the L293D motor driver. It should allow me to drive 2 motors and be able to go forward/reverse. The RPi GPIOs will then simply act as controller signals. The setup will be similar to what is presented here.
In addition, I intend to throw in a few capacitors to stabilize current. As in the example found here, I'll be using something in the size of a 10 uF capacitor for the power source and 220nF for the motors.
Before I go ahead and order the components, I'd like to verify that I've understood things properly and that this will actually work with the RPi. Is there something I'm missing or something that can be done better/simpler?
I'd also like to be able to change the rover platform from the Mr. Basic to a bigger one later on. Is there something I should keep in mind for my setup to allow for different DC motors later on?
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
Personally I wouldn't use an L293D to drive those motors. If I remember rightly, The L293D is rated at about 600mA, with 1A peak. Your motors have a stated stall current of 1.8A, so you really need a driver which is okay with 2A at least. The L298N would be better, but the bare chip is not breadboard compatible so you would need a module like this (unless you're making your own pcb). Note that one controller can control two dc motors.
Apart from that you've got the right idea. Be very careful with your wiring, though - you don't want that 4.5-6v getting back to the Pi. The motor controller's low-level inputs should be connected to Pi outputs and there must be a common ground - that's all.
Apart from that you've got the right idea. Be very careful with your wiring, though - you don't want that 4.5-6v getting back to the Pi. The motor controller's low-level inputs should be connected to Pi outputs and there must be a common ground - that's all.
Re: Driving 2 DC motors using L293D
Good points about the amps, exartemarte. Didn't think of that.
Are there any valid alternatives to L298N for motor controllers that handle > 1.8 A?
Are there any valid alternatives to L298N for motor controllers that handle > 1.8 A?
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
There's a reasonably clear diagram here which should give you the general idea. Imagine a Pi in place of the Arduino, and ignore references to Bluetooth.
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
L293 and L298 seem to be the standard one-chip solutions for small motors. You can certainly get motor controllers for much higher voltages and currents from specialist suppliers, such as 4QD, popular in the Robot Wars community, but be warned - the prices rise faster than the amperage!cupcake wrote:Are there any valid alternatives to L298N for motor controllers that handle > 1.8 A?
If you Google something like diy motor controllers you'll find articles on how to build your own.
Re: Driving 2 DC motors using L293D
Ordered L298N. Thanks for your help!
Re: Driving 2 DC motors using L293D
Can you connect the L293D directly to a GPIO Pin? Well the datasheet tells me that it's input pins are at 5V and the GPIO is at 3,3?
How do you do that?
How do you do that?
- Gert van Loo
- Posts: 2487
- Joined: Tue Aug 02, 2011 7:27 am
- Contact: Website
Re: Driving 2 DC motors using L293D
Any 5V LOGIC input can be driven from 3V3.
The logic HIGH is defined as 2.7V which voltage can be reached with 5V or 3V3.
It is the main reason why 3V3 is so commonly used: It is the lowest supply voltage you can have and still interface with 'old' 5V logic.
In telephones and other mobile equipment you see more and more 1V8 as new I/O voltage.
The logic HIGH is defined as 2.7V which voltage can be reached with 5V or 3V3.
It is the main reason why 3V3 is so commonly used: It is the lowest supply voltage you can have and still interface with 'old' 5V logic.
In telephones and other mobile equipment you see more and more 1V8 as new I/O voltage.
Re: Driving 2 DC motors using L293D
I now got the L298N extension board that extramarte suggested earlier.
I've got it somewhat working. By that I mean that I'm able to turn on/off 2 DC motors and change their directions by changing HIGH/LOW on 4 different GPIO ports.
However, I'm noticing that the motors are running much slower when powered through the L298N board. They are significantly slower than if I just power them directly with 3xAA batteries with nothing in between.
Here are 2 photos of how I've set it up:


Here's a link to the L298N board with close-up photos.
In short:
- Battery pack connected to L298N ports labeled "+12V" and "GND"
- I've left port "+5V" unused and "5V enable" is left as is
- One DC motor connected to OUT1/2 and the other to OUT3/4
- ENA and ENB are left as-is (will control these with PWM later)
- IN1-4 are connected to 4 RPi GPIOs
- RPi ground is connected to battery pack and L298N grounds
I'm no expert on this and the confusion of the 5V enable stuff on the ebay link is confusing me.
Anyone see what I may be doing wrong?
I've got it somewhat working. By that I mean that I'm able to turn on/off 2 DC motors and change their directions by changing HIGH/LOW on 4 different GPIO ports.
However, I'm noticing that the motors are running much slower when powered through the L298N board. They are significantly slower than if I just power them directly with 3xAA batteries with nothing in between.
Here are 2 photos of how I've set it up:


Here's a link to the L298N board with close-up photos.
In short:
- Battery pack connected to L298N ports labeled "+12V" and "GND"
- I've left port "+5V" unused and "5V enable" is left as is
- One DC motor connected to OUT1/2 and the other to OUT3/4
- ENA and ENB are left as-is (will control these with PWM later)
- IN1-4 are connected to 4 RPi GPIOs
- RPi ground is connected to battery pack and L298N grounds
I'm no expert on this and the confusion of the 5V enable stuff on the ebay link is confusing me.
Anyone see what I may be doing wrong?
- Grumpy Mike
- Posts: 944
- Joined: Sat Sep 10, 2011 7:49 pm
- Location: Manchester (England England)
- Contact: Website
Re: Driving 2 DC motors using L293D
Yes they will be.cupcake wrote:However, I'm noticing that the motors are running much slower when powered through the L298N board. They are significantly slower than if I just power them directly with 3xAA batteries with nothing in between.
Using 3 AA batteries will give you 3 X 1.5 = 4.5V.
There is a voltage loss in the switching transistors of that chip of about 2V so in effect you will only be driving the motor with 2.5V.
The answer is to feed the chip with a higher voltage.
Re: Driving 2 DC motors using L293D
Interesting. I thought I measured the voltage on the motors when fed through the L298N and that I got pretty much the same results (i.e. around 4.5V). I didn't know the L298N would leak that much.Using 3 AA batteries will give you 3 X 1.5 = 4.5V.
There is a voltage loss in the switching transistors of that chip of about 2V so in effect you will only be driving the motor with 2.5V.
The answer is to feed the chip with a higher voltage.
But thanks for the response. I'll try that.
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
It's not leakage, exactly.cupcake wrote:I didn't know the L298N would leak that much.
If you use a resistor or a transistor to limit or control the current through a device there will be a voltage drop across the resistor or transistor (which will get warm - that's why the chip on your controller has a heatsink). In an h-bridge motor controller there will be two transistors in series with the motor (which two depends on direction), and the voltage drop is typically 1.5 - 2v.
If you were using, say, 48v motors (which is not practicable on a small robot) then the drop wouldn't matter too much, but with 4.5 - 6v motors it clearly does.
When I use 6v motors with pwm I use a 9v supply (or 8.4v with rechargeables). If you're not using pwm, just switching the motors on and off and reversing direction, then 7.5 volts would be kinder to your motors.
Re: Driving 2 DC motors using L293D
Follow-up question:
The L298N allows me to control the speed of each separate motor using PWM. However, the RPi only allows one of the GPIOs to be used for PWM (GPIO 18). I see in the wiki that there may be plans to add a second PWM GPIO, but AFAIK there's only one available now.
So I can use the single PWM GPIO to control the speed of both motors at the same time. However, for turning, I'll have to make a full stop on one of the motors and run the other motor to have the rover rotate around its own axis. In other words: It can't move forward and turn at the same time.
Is there any way to control the speed of the two motors separately with only one PWM?
The L298N allows me to control the speed of each separate motor using PWM. However, the RPi only allows one of the GPIOs to be used for PWM (GPIO 18). I see in the wiki that there may be plans to add a second PWM GPIO, but AFAIK there's only one available now.
So I can use the single PWM GPIO to control the speed of both motors at the same time. However, for turning, I'll have to make a full stop on one of the motors and run the other motor to have the rover rotate around its own axis. In other words: It can't move forward and turn at the same time.
Is there any way to control the speed of the two motors separately with only one PWM?
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
The short answer is no. The long answer is possibly, but it's complicated and messy and it would be simpler to use an additional microcontroller (Arduino, etc) to provide the pwm.cupcake wrote:Is there any way to control the speed of the two motors separately with only one PWM?
However, you probably wouldn't have much joy trying to steer by driving the two sides at different rates anyway, nor by stopping one side and driving the other, so you might as well just stick with the Pi. Either of those techniques works with a three-wheel configuration (two driving wheels and a castor) but not with four wheels. With four-wheel drive on a small robot you can drive forward or reverse, or turn on the spot by driving forward on one side and reverse on the other, and that's about it.

You can vary the speed of course, using pwm, but if you try to drive one side more slowly the other side will just drag it along. The little beastie above travels in an almost straight line even when only one side is driven. To make it do anything else I have to put one side into reverse.
Re: Driving 2 DC motors using L293D
hello you shoul use my motor controller ù_ù
http://nvhs.wordpress.com/project/catsp ... ontroller/
you can make it whit a relay board ù_ù
http://nvhs.wordpress.com/project/catsp ... ontroller/
you can make it whit a relay board ù_ù
Re: Driving 2 DC motors using L293D
hello you shoul use my motor controller ù_ù
http://nvhs.wordpress.com/project/catsp ... ontroller/

you can make it whit a relay board ù_ù
http://nvhs.wordpress.com/project/catsp ... ontroller/

you can make it whit a relay board ù_ù
Re: Driving 2 DC motors using L293D
helo thise is my robot from with l9110 motor controller an java client
http://nvhs.wordpress.com/project/catspberry-2/

http://nvhs.wordpress.com/project/catspberry-2/

- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
Nice project. I would be interested to know how your camera link to the pc works.
Re: Driving 2 DC motors using L293D
Hi all, hi cupcake,
I got the same board with L298N.
Have you solved your problem?
Have you some python code?
Thanks for all
http://www.lo-geek.fr
I got the same board with L298N.
Have you solved your problem?
Have you some python code?
Thanks for all
http://www.lo-geek.fr
Re: Driving 2 DC motors using L293D
RE: the pwm question.
the RPi.GPIO module for python now supports software pwm.
I have used it successfully to blink/fade an led on a regular GPIO pin (not the pwm designated one)
I just started working with a L293D today. Have written the program, but have yet to wire up the breadboard.
Will get to that maybe tomorrow or the day after and let you know.
I will post my code when I get it working.
the RPi.GPIO module for python now supports software pwm.
I have used it successfully to blink/fade an led on a regular GPIO pin (not the pwm designated one)
I just started working with a L293D today. Have written the program, but have yet to wire up the breadboard.
Will get to that maybe tomorrow or the day after and let you know.
I will post my code when I get it working.
-
- Posts: 6
- Joined: Fri Dec 20, 2013 2:32 am
Re: Driving 2 DC motors using L293D
How do you use the L298N H-Bridge to control two motors from one PWM pin on RPi ????exartemarte wrote:The short answer is no. The long answer is possibly, but it's complicated and messy and it would be simpler to use an additional microcontroller (Arduino, etc) to provide the pwm.cupcake wrote:Is there any way to control the speed of the two motors separately with only one PWM?
However, you probably wouldn't have much joy trying to steer by driving the two sides at different rates anyway, nor by stopping one side and driving the other, so you might as well just stick with the Pi. Either of those techniques works with a three-wheel configuration (two driving wheels and a castor) but not with four wheels. With four-wheel drive on a small robot you can drive forward or reverse, or turn on the spot by driving forward on one side and reverse on the other, and that's about it.
You can vary the speed of course, using pwm, but if you try to drive one side more slowly the other side will just drag it along. The little beastie above travels in an almost straight line even when only one side is driven. To make it do anything else I have to put one side into reverse.
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
I probably wouldn't - see below. The little buggy in the picture is using an Arduino Nano, with multiple pwm's, and an L293D. What I had in mind when I answered the question above was just to combine the enable inputs for the two motors and connect them both to the one available PWM o/p on the Pi. I haven't actually done this, but I can't see why it shouldn't work. In principle both motors will run at the same speed: in reality they're unlikely to be perfectly matched so there will a slight difference.LaWFuLEviL wrote: How do you use the L298N H-Bridge to control two motors from one PWM pin on RPi ????
Nowadays, if I needed to control two motors from the Pi without additional hardware (apart from the motor driver) I'd try Joan's pigpio. I used it to control multiple servos and it was fine.
I am currently playing with a PI/Arduino combo (using spi, but that could change), which I hope will serve for most of my robotics projects.
-
- Posts: 6
- Joined: Fri Dec 20, 2013 2:32 am
Re: Driving 2 DC motors using L293D
I came across this post which shows L293D with two motors and one PWM : http://roverpi.blogspot.com/2013/07/con ... -with.htmlexartemarte wrote:I probably wouldn't - see below. The little buggy in the picture is using an Arduino Nano, with multiple pwm's, and an L293D. What I had in mind when I answered the question above was just to combine the enable inputs for the two motors and connect them both to the one available PWM o/p on the Pi. I haven't actually done this, but I can't see why it shouldn't work. In principle both motors will run at the same speed: in reality they're unlikely to be perfectly matched so there will a slight difference.LaWFuLEviL wrote: How do you use the L298N H-Bridge to control two motors from one PWM pin on RPi ????
Nowadays, if I needed to control two motors from the Pi without additional hardware (apart from the motor driver) I'd try Joan's pigpio. I used it to control multiple servos and it was fine.
I am currently playing with a PI/Arduino combo (using spi, but that could change), which I hope will serve for most of my robotics projects.
- exartemarte
- Posts: 376
- Joined: Sat Mar 03, 2012 3:51 pm
- Location: Middle England
- Contact: Website
Re: Driving 2 DC motors using L293D
Yes, that's the sort of thing I was suggesting.LaWFuLEviL wrote:I came across this post which shows L293D with two motors and one PWM : http://roverpi.blogspot.com/2013/07/con ... -with.html
- mikronauts
- Posts: 2821
- Joined: Sat Jan 05, 2013 7:28 pm
- Contact: Website
Re: Driving 2 DC motors using L293D
WiringPi also has a soft PWM that can control multiple pins; I used it last week with a L293D - it would also work with the L298
exartemarte wrote:I probably wouldn't - see below. The little buggy in the picture is using an Arduino Nano, with multiple pwm's, and an L293D. What I had in mind when I answered the question above was just to combine the enable inputs for the two motors and connect them both to the one available PWM o/p on the Pi. I haven't actually done this, but I can't see why it shouldn't work. In principle both motors will run at the same speed: in reality they're unlikely to be perfectly matched so there will a slight difference.LaWFuLEviL wrote: How do you use the L298N H-Bridge to control two motors from one PWM pin on RPi ????
Nowadays, if I needed to control two motors from the Pi without additional hardware (apart from the motor driver) I'd try Joan's pigpio. I used it to control multiple servos and it was fine.
I am currently playing with a PI/Arduino combo (using spi, but that could change), which I hope will serve for most of my robotics projects.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi