The MX1508 Dual H-bridge is a basic, cheap & small device ideal for small and low voltage motors. It can control two DC motors or one stepper. Motor voltage 2-10 volts. Continuous current 1.5 Amps, peak current 2.5 Amps and Logic voltage of 1.8-7 volts. There is no input for logic voltage it is derived from the motor power.
All 4 logic inputs IN1-IN4 must be PWM capable as per the truth table. In1 and In2 control motor 1. In3 and In4 control motor 2.
Module pinout
Pin Label | Function | Notes |
---|---|---|
'+' | Motor voltage | PSU for the motors (2V to 10V) |
'-' | Ground | Connect all GNDs to common rail (RPI , Motor PSU and Module) |
In1/In2 | Input 1 for channels A | inputs direction for Motor A, connected to 2 * RPI GPIO |
IN3/In4 | Input 2 for channels B | inputs direction for Motor B , connected to 2 * RPI GPIO |
Motor A | Output 1 for channels A | One of the two outputs to connect the motor A |
Motor B | Output 2 for channels B | One of the two outputs to connect the motor B |
HW Connection (for two DC motors) for the test file(see software section below) are as follows, (you can pick any GPIO pin you want).
- '+' to motor PSU (2-10 volts) tested at 5
- '-' to GND connect all GND's to a common rail together with PSU and RPI
- IN1 = 26 GPIO
- IN2 = 19 GPIO
- IN3 = 20 GPIO
- IN4 = 21 GPIO
- Motor A DC motor 1 +
- Motor A DC motor 1 -
- Motor B DC motor 2 +
- Motor B DC motor 2 -
The file rpi_dc_lib.py contains code for this component. It consists of a class called MC150XDc. The 5 methods are called:
- forward = Drive motor forward, passed one argument = duty cycle %
- backward = drive motor backward, passed one argument = duty cycle %
- standby = stop motor, passed one argument = duty cycle %
- brake = brake motor, passed one argument = duty cycle %
- cleanup = turn off the GPIO pins and will also run GPIO.cleanup() passed a boolean if False just turn off the GPIO used by motor driver, if True run in-built GPIO.cleanup() function.
Example:
There is a detailed example test code is in the MC150X_DC_Test.py file in test subfolder of rpiMotorLib repository.
To run this test file type python3 MC150X_DC_Test.py in a terminal.
In event of 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.if passed false it just sets the pins in play low. The standby function is independent of the class object and is set on and off by user. One class object is declared for each motor.