The L9110S 2-Channel motor driver module is a compact board that can be used to drive small robots. This module has two independent motor driver chips which can each drive up 800mA of continuous current. The boards can be operated from 2.5V to 12V enabling this module to be used with both 3.3V and 5V microcontrollers. A set of female header pins is used to connect this module to a microcontroller. The motors are attached via two sets of screw terminals.
A PWM Pulse Width Modulation signal is used to control the speed of a motor and a digital output is used to change its direction. This module can also be used to drive a single four line two phase stepper motor. Four holes make this board easy to mount onto your robot or other project
On-board 2 L9110 motor control chip
- Module can be driven by two dc motors at the same time or one phase 4 line 2 type stepping motor
- Input voltage: 2.5-12V DC
- Each channel has a continuous output current 800 ma
- PCB Size: 29.2mm x 23mm
The four and pins are connected as so to Rpi where GPIO 1-4 can be any GPIO pins Motor VCC and GND are connected to VCC and GND(decouple power supply with capacitor) and remember to connect all gnds L9110S Rpi and power supply to common GND rail) IA controls PWM and IB controls direction
- B-IA: Motor B Input A - GPIO 2 - PWM
- B-IB: Motor B Input B - GPIO 1 - DIR
- GND: ground
- VCC: 2.5V-12V DC
- A-IA: Motor A Input A - GPIO 4 - PWM
- A-IB: Motor A Input B - GPIO 3 - DIR
This library was tested on a RF-310T-11400 DC motor.
This software is same as for the DRV8833 module hence name of class which it was written for originally. Both modules use same test file as well.
The file rpi_dc_lib.py contains code for this component, It consists of a class called DRV8833NmDc and five methods. The five methods are called:
- forward = Drive motor forward, passed one argument = duty cycle %
- backward = drive motor backward, passed one argument = duty cycle %
- stop = stop motor, passed one argument = duty cycle %
- brake = brake motor, passed one argument = duty cycle %
- cleanup = turn off the 3 GPIO pins and will also run GPIO.cleanup() passed a boolean if False just turn off the 2 GPIO useds by motor, if True run in-built GPIO.cleanup() function.
Example:
The GPIO pins of pi in this example A-IB = 26 = direction A-IA = 19 = Speed PWM
When initializing the class first GPIO pin(26) is direction, second is PWM(19).
- Runs a motor forwards at duty cycle 15 for 3 seconds
- Stop
- Run a motor forwards in steps of 1 from duty cycle 15 to 30
- Stop
- Runs a motor backwards at duty cycle 15 for 3 seconds
- Stop
- Run a motor backwards in steps of 1 from duty cycle 15 to 30
- Stop
- Run a motor forwards at 50 and test brake
- cleanup
In event or error or keyboard interrupt call "cleanup function" NOTE their is no error handling in this class but their is the "cleanup" function, Its left to user to catch exceptions and call "cleanup" if they want. The cleanup function executes GPIO.cleanup() if passed True
More example code is in the DRV8833_or_ L9110S_DC_Test.py file in test subfolder of rpiMotorLib repository.
import time
import RPi.GPIO as GPIO
from RpiMotorLib import rpi_dc_lib
def motorone():
print(" TEST: testing motor 1")
# Motorssetup
MotorOne = rpi_dc_lib.DRV8833NmDc(26 ,19 ,50 ,True, "motor_one")
try:
print("1. motor forward")
MotorOne.forward(15)
input("press key to stop")
print("motor stop\n")
MotorOne.stop(0)
time.sleep(3)
print("2. motor forward speed up")
for i in range(15,30):
MotorOne.forward(i)
time.sleep(1)
MotorOne.stop(0)
print("motor stoped\n")
time.sleep(3)
print("3. motor backward")
MotorOne.backward(15)
input("press key to stop")
MotorOne.stop(0)
print("motor stopped\n")
time.sleep(3)
print("4. motor backward speed up")
for i in range(15,30):
MotorOne.backward(i)
time.sleep(1)
MotorOne.stop(0)
print("motor stopped\n")
time.sleep(3)
print("5 brake check")
MotorOne.forward(50)
time.sleep(3)
MotorOne.brake(100)
print("motor brake\n")
except KeyboardInterrupt:
print("CTRL-C: Terminating program.")
except Exception as error:
print(error)
print("Unexpected error:")
finally:
MotorOne.cleanup(False)
if __name__ == '__main__':
print("START")
motorone()
exit()