User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Raspberry Pi - How to control motors...

Tue Sep 10, 2013 5:26 pm

[EDIT]
Last edited by raspberrypiguy1 on Sat Jul 12, 2014 7:36 am, edited 2 times in total.
Matt, 17 year old @Raspberry_Pi YouTube tutorial maker, programmer, electronics tinkerer, entranced by the cosmos, ISS, Physics, likes Politics, Cambridge UK

User avatar
joan
Posts: 13655
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Tue Sep 10, 2013 6:05 pm

Just a minor point about ENA/ENB. Normally you'd just place a jumper over the ENA and/or ENB pins.

Code: Select all

o         o
o o o o o o
E I I I I E
N N N N N N
A 1 2 3 4 B
The upper pin of the enable pair is set to logic high by the module circuitry. Using a jumper sets the lower pin to logic high. I'm concerned that connecting a gpio or 3.3V to the upper pin is a bit risky as you'll be feeding 5V from that pin in to the Pi.

WickedPenguin
Posts: 33
Joined: Wed Sep 04, 2013 7:11 pm

Re: Raspberry Pi - How to control motors...

Wed Sep 11, 2013 1:45 am

I am using a similar l298n board, but ENA and ENB don't have jumpers so I have just set then to high from the GPIO pin 18 and 22. Is that the right thing to do?

The stepper motor doesn't seem to step, just lock and stutter a bit.

Have you done this with a stepper motor? Not just the small stepper in the adafruit tutorials. that works fine with a darlington board.

User avatar
joan
Posts: 13655
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Wed Sep 11, 2013 7:26 am

WickedPenguin wrote:I am using a similar l298n board, but ENA and ENB don't have jumpers so I have just set then to high from the GPIO pin 18 and 22. Is that the right thing to do?

The stepper motor doesn't seem to step, just lock and stutter a bit.

Have you done this with a stepper motor? Not just the small stepper in the adafruit tutorials. that works fine with a darlington board.
Just connect gpios to the (bottom rank only) enable pins. For a stepper motor which you'll always want enabled it would be better just to connect the top pin to the bottom pin. For a DC motor set enable high to run the motor or low to stop the motor. Switching the enable on/off very fast (PWM) will vary the speed of a DC motor. You shouldn't use that technique with a stepper motor.

Your problem with the stepper motor is almost certainly that you have wired it incorrectly. Different steppers use different coloured wires for different things . There are guides on the www to use a resistance meter to identify the coils and determine the correct wiring.

arcanon
Posts: 36
Joined: Wed Nov 14, 2012 9:18 am

Re: Raspberry Pi - How to control motors...

Wed Sep 11, 2013 12:59 pm

Here is another solution with a L293 controlling 2 DC motors and that being controlled by an atmega8. The atmega is connected via SPI to the PI.
http://subgroup-ash.blogspot.de/2013/09 ... l-and.html

User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Re: Raspberry Pi - How to control motors...

Fri Sep 13, 2013 9:20 pm

joan wrote:Just a minor point about ENA/ENB. Normally you'd just place a jumper over the ENA and/or ENB pins.

Code: Select all

o         o
o o o o o o
E I I I I E
N N N N N N
A 1 2 3 4 B
The upper pin of the enable pair is set to logic high by the module circuitry. Using a jumper sets the lower pin to logic high. I'm concerned that connecting a gpio or 3.3V to the upper pin is a bit risky as you'll be feeding 5V from that pin in to the Pi.
Lots of the L298Ns don't ship with jumpers - my one didn't. I have used my particular method many times with many motors and not once has anything gone wrong. Before I make a tutorial I thoroughly check it and try it with lots of different set ups!

Thanks for bringing that to my attention though!

The Raspberry Pi Guy
Matt, 17 year old @Raspberry_Pi YouTube tutorial maker, programmer, electronics tinkerer, entranced by the cosmos, ISS, Physics, likes Politics, Cambridge UK

User avatar
joan
Posts: 13655
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Fri Sep 13, 2013 9:26 pm

If you have a meter measure the voltage at the enable jumper pins.

dtal
Posts: 2
Joined: Sun Jan 12, 2014 3:06 pm

Re: Raspberry Pi - How to control motors...

Sun Jan 12, 2014 3:12 pm

Hi piguy,

just two questions:

1. I rebuild your circuit with the same components. After I plugged in the Batteries, the PI startet booting. After booting, I don't have access to Display, keyboard and mouse so I can't run the scripts. When I start the Pi by powersupply, it's no problem. How do I do the wiring with Batteryholder AND power supply together? (By the way: All the other PI-owners say, that I'm an idiot, because I run the PI with 4 Batteries (=6Volts) - did you ever have any problems?)

2. My L298n only has one EN-A and one EN-B - would that be any problem for the code you wrote?

Thanks!

DominusPi
Posts: 39
Joined: Mon Nov 18, 2013 5:31 pm

Re: Raspberry Pi - How to control motors...

Sun Jan 12, 2014 7:24 pm

dtal wrote:Hi piguy,

just two questions:

1. I rebuild your circuit with the same components. After I plugged in the Batteries, the PI startet booting. After booting, I don't have access to Display, keyboard and mouse so I can't run the scripts. When I start the Pi by powersupply, it's no problem. How do I do the wiring with Batteryholder AND power supply together? (By the way: All the other PI-owners say, that I'm an idiot, because I run the PI with 4 Batteries (=6Volts) - did you ever have any problems?)

2. My L298n only has one EN-A and one EN-B - would that be any problem for the code you wrote?

Thanks!
http://www.raspberrypi.org/faqs#powerReqs
-Read point 3
-Now go and change your power supply
Cheers !

dtal
Posts: 2
Joined: Sun Jan 12, 2014 3:06 pm

Re: Raspberry Pi - How to control motors...

Sun Jan 12, 2014 10:10 pm

So - if I use one of these charger packs: How do I connect it to the L298n? The 298 has pins, the charger pack has usb!?

Brens
Posts: 6
Joined: Fri Jan 31, 2014 10:19 pm
Location: Lyon, France

Re: Raspberry Pi - How to control motors...

Fri Jan 31, 2014 11:51 pm

Hi, nice "how to".
I would like to drive this kind of motor with a software PWM generated by my raspberry's GPIO :
http://www.ebay.com/itm/12V-DC-DIY-Dosi ... 2c75740b7b

So, i think your L298N board will do the job, but, one beginner's question:
Wouldn't be safer for GPIO to use a L298N board with an optocoupler?

User avatar
joan
Posts: 13655
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Sat Feb 22, 2014 2:23 pm

Each motor has one enable pin. So ENA for motor A and ENB for motor B. If your module looks like the diagram the designer has provided a logic "1" pin above each enable pin. This is purely for convenience. If you always want the motor enabled just put the jumper in place. This permanently enables the motor by setting the enable pin to logic 1.

You can control the motor speed by PWM. PWM rapidly switches a pin between off and on.

You can use PWM on the enable pin or on the IN pins. Both methods achieve the same end (controlling motor speed).

If you choose to use PWM on the enable pin rather than the IN pins you connect a gpio to the enable pin. You should never connect a gpio to the logic "1" pin.

hades1989
Posts: 16
Joined: Wed Mar 12, 2014 2:28 am

Re: Raspberry Pi - How to control motors...

Wed Mar 12, 2014 2:30 am

Hi, how should i do the wiring if i want to connect 2 motors instead of 1 to the Stepper Motor and the Pi?

hpack
Posts: 4
Joined: Sun Mar 02, 2014 2:11 am

Re: Raspberry Pi - How to control motors...

Thu Mar 13, 2014 3:34 pm

hades1989 wrote:Hi, how should i do the wiring if i want to connect 2 motors instead of 1 to the Stepper Motor and the Pi?
Hi,
I am assuming you want to connect two DC motors through the L298N to the Pi's GPIO pins.
You would wire up everything just as it was done in the tutorial, just that you do it twice. What I mean, is you keep everything the same, but you enable ENB (assuming you have already wired up ENA) through a GPIO pin, and the other two pins (the ones that actually control the motors) which connect to two other GPIO pins.
In the code, you would not only control two GPIO pins (which is used for one motor), but instead four GPIO pins (two for each motor).

hpack
Posts: 4
Joined: Sun Mar 02, 2014 2:11 am

Re: Raspberry Pi - How to control motors...

Thu Mar 13, 2014 3:43 pm

Hey Guys,

So I have been successfully controlling two DC motors through the L298N H-Bridge, until recently. Right from the start, I noticed that my Pi's SOC (to be honest, the whole board itself) was getting very hot. And when I say hot, I mean when you touch the board, you only can keep it there for a second before you burn your finger.
I was using a 9V power supply, so I suspected this might be the problem. However, when I switched it out for 4 double A's, it only got hotter.
I tried to ignore this, but soon after my Pi stopped responding, and is now, to my believe, burned out.
Does anyone have any reasons to why this happened? I checked the video's wiring many times, so I doubt it has anything to do with the wiring. I would like to keep on using this H-Bridge, for there aren't that many out there which have been documented specifically for the RPI.

Thanks

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Thu Mar 13, 2014 3:50 pm

Do you have separate power going to the 298 and motors? If not, I suspect you might be drawing too much current from the raspi's regulator or power connections. (I'm assuming here the motors are drawing a lot of current from the raspi itself and either its regulator has overheated, or the polyfuse thing has shut down.)

On the other hand if you do have separate power/battery connections going to the L298, then I don't see why else the raspi would be overheating...

User avatar
joan
Posts: 13655
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Thu Mar 13, 2014 3:56 pm

hpack wrote:Hey Guys,

So I have been successfully controlling two DC motors through the L298N H-Bridge, until recently. Right from the start, I noticed that my Pi's SOC (to be honest, the whole board itself) was getting very hot. And when I say hot, I mean when you touch the board, you only can keep it there for a second before you burn your finger.
I was using a 9V power supply, so I suspected this might be the problem. However, when I switched it out for 4 double A's, it only got hotter.
I tried to ignore this, but soon after my Pi stopped responding, and is now, to my believe, burned out.
Does anyone have any reasons to why this happened? I checked the video's wiring many times, so I doubt it has anything to do with the wiring. I would like to keep on using this H-Bridge, for there aren't that many out there which have been documented specifically for the RPI.

Thanks
What were you powering with 9V?

What connections did you have between the Pi and the L298N module?

PiGraham
Posts: 3406
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Raspberry Pi - How to control motors...

Thu Mar 13, 2014 4:38 pm

hpack wrote:Hey Guys,

So I have been successfully controlling two DC motors through the L298N H-Bridge, until recently. Right from the start, I noticed that my Pi's SOC (to be honest, the whole board itself) was getting very hot. And when I say hot, I mean when you touch the board, you only can keep it there for a second before you burn your finger.
Here's a tip. If things get unusually hot there's probably something wrong. Turn it off!

hades1989
Posts: 16
Joined: Wed Mar 12, 2014 2:28 am

Re: Raspberry Pi - How to control motors...

Tue Mar 18, 2014 4:01 am

hpack wrote:
hades1989 wrote:Hi, how should i do the wiring if i want to connect 2 motors instead of 1 to the Stepper Motor and the Pi?
Hi,
I am assuming you want to connect two DC motors through the L298N to the Pi's GPIO pins.
You would wire up everything just as it was done in the tutorial, just that you do it twice. What I mean, is you keep everything the same, but you enable ENB (assuming you have already wired up ENA) through a GPIO pin, and the other two pins (the ones that actually control the motors) which connect to two other GPIO pins.
In the code, you would not only control two GPIO pins (which is used for one motor), but instead four GPIO pins (two for each motor).
Thanks, im able to control 2 motors now, another question, say, i want to add an ultrasonic sensor to the pi, so is basically:
Raspberry Pi + Sonar HC-SR04 + L298 Driver

but im running out of GPIO pins, each dc motor needs 4 GPIO pins, 2 dc motors occupied 8 GPIO pins, any idea of how to reduce the usage GPIO pins for dc motor so i got at least 2 spare pins for my ultrasonic sensor ?

Thanks.

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: Raspberry Pi - How to control motors...

Tue Mar 18, 2014 4:22 am

but im running out of GPIO pins
You have 17 GPIO pins, plus 4 more if you solder in the 2nd header for a Rev 2 board.
17 gives you 4 motors with 1 spare pin. Or 2 motors and 9 spare pins... way more than you need for an ultrasonic sensor.

Shouldn't a DC motor with an H-bridge only require 2 GPIO pins? You can just jumper ENA from VCC; you don't need a GPIO to enable it. I can't even figure out where your 4th pin would be used for a DC motor.

Duane Degn
Posts: 55
Joined: Thu Jul 10, 2014 6:30 am
Location: Idaho, USA

Re: Raspberry Pi - How to control motors...

Thu Jul 10, 2014 9:01 pm

TheRaspberryPiGuy,

I can't figure out why you leave your destructive video up.

Several people in this forum have pointed out the error where you connect 5V to a GPIO pin. This has been brought to your attention in the comments of the video. I emailed you about this problem where you said "I understand your concern".

If you understand my concern, why are you still showing people how to fry their Pi?

You video gets hundreds of views a day. How many Raspberry Pi boards does your video contribute to the death of each day?

It will only take a few seconds to mark it private and then you can take your time fixing it if you like. As the video is now, it does much more harm than good.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Fri Jul 11, 2014 3:13 pm

Have you tried mailing him? It's on this page...

User avatar
mikronauts
Posts: 2669
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Raspberry Pi - How to control motors...

Fri Jul 11, 2014 3:23 pm

Feeding 5V to a Pi GPIO, without at least current limiting it, is a really bad thing... that can easily damage a Pi.

I can see wanting to see if a 5V supply is on, by feeding it to a GPIO, but the proper way to do that is to use a voltage divider:

+5V ---> 2k4 resistor ---> GPIO ---> 4k7 resistor ---> Vss

Please fix your video.
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

Duane Degn
Posts: 55
Joined: Thu Jul 10, 2014 6:30 am
Location: Idaho, USA

Re: Raspberry Pi - How to control motors...

Fri Jul 11, 2014 4:40 pm

Ravenous wrote:Have you tried mailing him? It's on this page...
Yes, as I mentioned in my post, the first time I emailed him he said "I understand your concern about my video" and then went on to tell me about a new view he was working on.

His reply to my first email was quick. In the second email I said:
If you "understand my concern" why haven't you fixed or removed the video? My concern is people are frying their RPi boards from following the example of your video.

The longer the video remains in its current state the more Raspberry Pi boards (and possible other microcontrollers) will be destroyed.

I can't understand your lack of action on this very serious matter.
He has not replied to my second email.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Raspberry Pi - How to control motors...

Fri Jul 11, 2014 4:45 pm

Duane Degn wrote:
Ravenous wrote:Have you tried mailing him? It's on this page...
Yes, as I mentioned in my post, the first time I emailed him he said "I understand your concern about my video" and then went on to tell me about a new view he was working on.
Ah I'm sorry, I hadn't realised you mailed him first. I should read more carefully :)

Well I assume he's getting advertising revenue for the video, and changing it might break existing links...

Return to “Automation, sensing and robotics”