26 SERVO 11.2016
An L298N can be used in both four- and six-pin modes on
most L298N driver boards. I always recommend you use
L298N driver boards that support both four- and six-pin
modes, as that provides the maximum flexibility for your
Some L298N modules also have optional connections
for current sensing. However, even without those
connectors, it is possible to use a common ACS712 module
to measure the current used by each motor. Here’s is a link
to a L298N datasheet: www.st.com/resource/en/
For Berry, I will be using six-pin control of the L298N
driver, as it uses less power from the batteries and is more
efficient than four-pin control. The six L298N inputs we
need to drive are shown in Table 1. The speed of each
motor (A and B) will be controlled by applying a PWM
signal between 0% and 100% to the motor enable pin.
You will find that the motor will not start turning until
the PWM duty cycle is high enough so that it has enough
torque to move the robot’s weight. So, don’t
expect to see any movement at low duty cycles.
For more about L293D, L298N, four- vs. six-pin
control, and some other motor driver boards,
please see “Serving Raspberry Pi #3” in the
March 2016 issue of SERVO Magazine.
I’ll be using the same “Easy Motor” Python
API I used for Hobbit on Berry.
Adding a Compass —
There are a LOT of compass modules on the
market, at wildly varying prices. Some of the
most popular modules use the Honeywell HMC5883L triple
axis magnetometer. You can find the datasheet for the
HMC5883L at www.farnell.com/datasheets/
There are much more accurate tilt-compensated
modules out there, but the low price of the HMC5883L
modules outweighs the need for accuracy for hobby and
educational robots. If we desire greater accuracy, it is
possible to calibrate the sensor readings for your location,
and it is also possible to add tilt compensation in the future
using an inexpensive ADXL345 (or similar) module.
For our initial experiments here, two degrees of
accuracy will be more than sufficient.
Positioning the HMC5883L
Module on Your Robot
In an ideal world, we would mount our compass
modules in the geometric center of our robot’s drive
PHOTO 7. HMC5883L mounted close to the center of
Berry Bot. PHOTO 6. HMC5883L module on Berry Bot.
EnA Enable Motor A Connected to RoboPi FlexIO #6
IN1 Direction control 1 for Motor A Connected to RoboPi FlexIO #12
IN2 Direction control 2 for Motor A Connected to RoboPi FlexIO #13
EnB Enable Motor B Connected to RoboPi FlexIO #7
IN3 Direction control 1 for Motor B Connected to RoboPi FlexIO #14
IN4 Direction control 2 for Motor B Connected to RoboPi FlexIO #15