Pages: [1]   Go Down
Author Topic: Motor Driver  (Read 615 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I have a quick question. Can I connect the two L298N to  Arduino? So that we can control the 2 stepper motors or 4 dc motors.

Thanks in advance smiley
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Since the L298 uses 4 Arduino pins to control each motor it looks like you run out of pins to use, but there is the possibility of using your analog pins as digital which can get you there.  They are addressed as follows:
Digital pin 14 = Analog pin 0
D15 = A1
D16 = A2
D17 = A3
D18 = A4
D19 = A5

However presuming you'll want your vehicle to do more than just move around - it should react to sensors and maybe have some communications - that would only leave you with 3 spare pins.  There are other alternatives you can try, with a couple of minor compromises.  The controls are:
  • Enable pin.  This one you’d just tie to ON.  If you're not using this to turn off the motor control you can save a pin per motor here
  • Speed pin (PWM) – you could tie this one to HIGH to keep the thing running flat out, but I think that would be hard on the motor...so leave this one in place.
  • Two Direction pins – here’s where you can save another pin for each motor.  1 on and 1 off gives direction, both off for coast, both on for brake.  If you put a transistor inverter (a simple NOT gate) between the two, when one is on the other will be off and vice versa.  You reduce this by 1 pin...but you lose the ability to have them both 0 or both 1.  Mostly you probably won't want to have your vehicle 'coast', so it's possible you can do without 0/0 but 1/1 for a handbrake is useful.  But if you have the PWM in place, you can get control over slowing it down by just not dropping speed from 255 to 0; ie a controlled descent from 255 down to 0, maybe holding it at 1 for a while as an engine brake might work on a flat surface (hopeless if you’re trying to slow while going down a hill in that direction).  Or to brake you could set the thing on dead slow and run the front and rear motors against each other.  Not ideal longer term perhaps, but that might be good to bring your vehicle to a complete halt.  So by removing two direction control possibilities per motor you free up one more pin each (or maybe you free it up on two motors and have the other two still be able to handbrake).
So it's possible you could construct a 4WD vehicle with 4x DC motors using that L298 using 4PWM pins for speed control, has the enable hard-wired on, and just 4 other regular pins for toggling the direction forward and back - 8 pins total rather than 16.

The transistor .NOT. gate is constructed with an NPN transistor and a pair of current limiting resistors.  If you're not comfortable with adding circuitry, other alternatives might be to drive your motors in pairs, so the front and rear act on the same control and just one L298 driver (presuming the power requirement from your chosen motors isn't too much).

Hope that's given you some ideas,
Geoff
« Last Edit: March 19, 2013, 08:16:48 pm by strykeroz » Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 91
Posts: 4227
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can I connect the two L298N to  Arduino?

Quote
it looks like you run out of pins to use

But remember different Arduinos have different numbers of pins.. 14 on an Uno which Geoff presumably based his numbers on, in the absence of the OP saying what his board is, but 50+ on a Mega.




Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But remember different Arduinos have different numbers of pins.. 14 on an Uno which Geoff presumably based his numbers on, in the absence of the OP saying what his board is, but 50+ on a Mega.
Well spotted, and yes was basing that response entirely on Uno or any of its ancestors smiley
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Newbie
*
Karma: 2
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your answers, will mix somenthing ... I hope without white smoke: D
Logged

Pages: [1]   Go Up
Jump to: