After seeing TheRaspberryPiGuy's video titled "Raspberry Pi - How to control motors...
" and seeing the Pi's I/O pin being connected to a 5V pin, I decided to make my own tutorial video. The TRPG's video has likely contributed to many burned out Raspberry Pi computers. Even 5V microcontrollers would likely be damaged if used the way the video suggests.
First off (as I say in the video) the L298N quad half bridge is a really poor choice as an h-bridge. Several people I consider robot experts (Gordon McComb
and Russell Cameron
) have mentioned their dislike of the chip on several occasions.
There are lots of better h-bridges than the L298N. Parallax sells the MC33926 dual h-bridge board
made by Pololu which would be a much better alternative to the L298N.
The main (only?) advantage the L298N boards have is they are dirt cheap
on ebay. You could probably purchase ten or more L298N boards (shipped) for the price of a single MC33926 board. At these prices, it's hard to resist purchasing a few of these inexpensive h-bridges.
The video I made is long. Over 14 minutes (though it's shorter than TheRaspberryPiGuy's how to fry pi video). I show how one can control the h-bridge by setting the enable and direction pins directly without using a microcontroller. I hope by seeing how the pins need to be set, a newcomer to hobby robotics will have a better understanding of what the software needs to do to control the h-bridge.
Setting the control pins high and low is something one could also do with more expensive h-bridges. IMO, it's very helpful to get straight how the pins need to be set before attempting to use a h-bridge with a microcontroller.
Here's the video:
Here's a photo to which I added some diagrams on how the board should be connected to a microcontroller.
The battery high limit of 14V is to keep the 5V regulator from being burned out. The L298N can use voltages as high as 46V but the regulator can't take this high of a voltage. Apparently higher voltages can also cause trouble for the microcontroller attached to the board (as erco found out for himself
Here's a table of how the pins should be set to achieve forward and reverse motor control.
MotorA ENA IN1 IN2
Forward High High Low
Reverse High Low High
Coast Low X X "X" means it can be high or low
Brake High Low Low (If both IN1 and IN2 are high, it will also brake)
Forward and reverse are pretty much chosen arbitrarily. If a motor is spin in the opposite direction of the desired direction, there are several ways to reverse the direction of the motor.
By switching with wire is connected to which screw terminal, the motors will be reversed. The same is true for the "IN" pins. These can be either physically swapped, or the I/O pins can be switched in the program. Of course only one method (or an odd number of methods) should be used to reverse the direction of the motor. If one switched both the motor wires and the "IN" wires, you'd be back where you started.
I plan to add some additional material to this thread. I'll reserve a few posts (3 more) to use for software and other information.
Please wait to comment until I've make three additional posts to this thread.