docendo.discimus
Posts: 18
Joined: Thu Aug 02, 2012 10:07 pm

L298N

Sat Dec 22, 2012 5:30 pm

Hi,

Just bought a magician robotic chassis and wanted to use the Raspberry to control the dc motors. I've done some searching on this forum and many people that completed this kind of projects eventually used a L298N to control the motors, so I also bought:

http://www.ebay.co.uk/itm/140896496382? ... 1497.l2649

Does it connect directly to the GPIO or do I need extra electronic components to protect the raspberry?

And wich GPIOs to connect if I wanted to use Python (sample code)?


Thanks

PS1981
Posts: 445
Joined: Wed Dec 12, 2012 4:11 pm

Re: L298N

Sat Dec 22, 2012 6:01 pm

So having no data sheet for the board you bought, I want to be vary careful what I say, and deny any responsibility for anything that may go wrong!

Anyhow, loking at the board you´ll be giving it the supply voltage of say 12V for example on the VMS clamp, ground in the middle and 5v logic supply where (obviously) it says 5v, and ground to your ground.

The ENA and ENB enable the channels for each motor, you can give these a permanent 5v or you can switch them on and off by connecting to a GPIO pin. (I think that minimum 4.5V will be required, which you don´t get from the GPIO, Possibly you´ll need to provide this via an optocoupler). The same goes for the in1 to in 4 pins, where setting for example in1 high and in2 low will cause your motor to run in one direction (forwards say), and backwards if you set in1 low and in2 high. Ditto for in3 and in4 on the other motor channel. This assuming you´re using normal dc electromotors, and not say a stepper.

So, aside from a few wires, I reccomend you get your hands on a few optocoupler IC's, they´re pretty cheap. Otherwise just some wires and for example a breadboard would be a good idea.

If you have a datasheet for this then by all means consult this before believing what I´ve written. Otherwise I advise you search for the L298 datasheet in the internet.

Hope to be of some help.

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

Re: L298N

Sat Dec 22, 2012 6:30 pm

I'd look on eBay etc. to see if you can find the same module from another vendor. It may well be better documented elsewhere.

I think it'll work direct from the gpios at 3.3V logic to IN1/2/3/4 (jumper ENA/B high). It seems to have a jumper (in place) to supply the 5V logic from the motor supply. You'd remove the jumper if the motor supply was greater than, guess, 12V, in which case you'd need to supply 5V from the Pi for logic. You also need to connect the Pi ground to the units ground.

docendo.discimus
Posts: 18
Joined: Thu Aug 02, 2012 10:07 pm

Re: L298N

Sat Dec 22, 2012 6:33 pm

Thanks,

I saw a thread that said the 3V3 of the GPIO was enough to switch on the ENA. I don't know if the diods on this L298 board prevent any surge when turning off the dc motors or if I need some extra diods.

I'll look into those optocouplers. Thanks again

PS1981
Posts: 445
Joined: Wed Dec 12, 2012 4:11 pm

Re: L298N

Sat Dec 22, 2012 6:46 pm

Yes the diodes are I think mostly there so that you can reverse the motor direction. Since there is no signal going back to the controller, then you´re pi should be in little danger. Make sure the motors you use don´t pull too much current either.

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

Re: L298N

Mon Dec 24, 2012 9:12 am

The diodes are there to prevent high voltages being generated when the motor turns off. It's a bit hard to explain in my clumsy words, but when a motor/coil/solenoid switches off the magnetic field collapses, and sweeps very fast past the coil windings. This generates a voltage that can be much higher than the supply voltage of the circuit. If this is over 30-40V it might damage a small transistor.

So the diodes are to protect the L298's output transistors only. The connections to the raspi should be OK and not affected by this.

You can probably just connect the raspi directly to the L298 without needing any optocouplers, transistors, etc. and at worst it might not work, but it won't harm the raspi. (I've used the smaller L293 but only on 5V logic - other people on these forums have indicated the 3.3V from the raspi will work.)

PS1981
Posts: 445
Joined: Wed Dec 12, 2012 4:11 pm

Re: L298N

Mon Dec 24, 2012 10:07 am

Well I can´t see exactly how the diodes are set up on this board, but they are, at least sometimes used to control the direction of the voltage so that the motor channel can be used to turn in both directions. The schematics for this can be seen in the L298 datasheet.

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: L298N

Wed Dec 26, 2012 2:48 pm

Hi

Ravenous is correct; the diodes are for protection only.

The transistors steer the current and so mandate the motor direction.

If you examine the datasheet you will see that the diodes can conduct only if the voltage at the motor terminal goes above the positive supply or below ground. These voltages cannot come from the supply but would be generated by the motor as it comes to rest after supply has been removed.

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: L298N

Wed Dec 26, 2012 3:04 pm

Hi again

The L298 datasheet indicates that any control signal (i.e. L298 pins 5,7,10,12 and 6,11) less than 1V5 will be accepted as a low, and anything above 2V3 will be accepted as high. So, in principle, the GPIO pins can drive a L298. It depends on what, if anything, the board does to the incoming signals.

docendo.discimus
Posts: 18
Joined: Thu Aug 02, 2012 10:07 pm

Solution to L298N

Mon Jan 14, 2013 12:42 am

Hi,

I'm sorry for bumping this old thread, but when I was searching for similar threads on this forum I found many people with the same problem but the solution was never there. So I'm posting the final result and I hope it be usefull in the future for someone who is trying to get a L298 to work with a RPI:


I connected pins 11 and 12 to ENa and ENb of Hbridge to use PWM (that I emulated in Python). If I only needed to steer forward, just connect Ground to IN2 and IN4 so the DC motors kept moving one way. Because I wanted them to reverse also, I´ve connected pins 13 to IN1, 15 to IN2, 16 to IN4 and 18 to IN3. This HBridge I'm using accepts 2V3 as HIGH and less than 1V5 as LOW, so if I set pin 13 and 18 as HIGH and 15 and 16 as LOW the motors rotate clockwise. The opposite setting, like 13LOW and 15HIGH rotates the motorA the other way. The HBridge has protecting diods, so I didn't use any resistors between GPIO and HBridge...

I didn't connected the Raspberry Pi Ground to the L298N ground but it worked anyway. In a similar thread, someone connected the L298N 5V output to power the Pi through the microUSB.

The dc motors I used work between 3V and 6V and I'm using a 5V Battery. It seems the L298 drops a couple of volts to the motors, so it only reads 3V3 which barely moves the motors... I need to try with 7,5V battery or better dc motors :)

idem
Posts: 12
Joined: Mon Feb 18, 2013 3:23 pm

Re: L298N

Mon May 13, 2013 8:54 pm

someone got any python example ?
I got same Driver Board for L298N with on input :
VCC, GND and +5V

Thanks a lot

http://www.lo-geek.fr

Return to “Automation, sensing and robotics”