Product Overview
The MD40 is a high-performance 4-channel motor driver module designed for multi-motor systems requiring precise motion control. It features 4 DC motor ports (M0-M3) and 4 encoder motor ports (E0-E3). The module receives control commands via the standard I2C communication protocol, drives DC and encoder motors, and provides a complete closed-loop control solution with signal feedback.
The module utilizes a professional PID control algorithm, offering both speed closed-loop and position closed-loop control functions. This enables precise speed maintenance and position positioning. Through real-time encoder feedback, the system automatically compensates for load changes, ensuring stability and accuracy in motion control.
The MD40 is ideal for applications requiring high-precision motion control and coordinated multi-motor operation, such as mobile robotics, automated guided vehicles (AGVs), and multi-axis gantry systems.
| Parameter | Specification |
|---|---|
| Logic Voltage | 5V DC |
| External Power Voltage | 6-16V DC |
| Interfaces | I2C & PH2.0 connectors: 2-pin (VIN, G) for external power; 2-pin for DC motors (M0-M3); 6-pin (-, V, B, A, G, +) for encoder motors (E0-E3) |
| Connection | PH2.0 anti-reverse DuPont cables |
| Communication | I2C protocol, default address 0x16 |
| Dimensions | 56mm x 40mm, compatible with LEGO bricks and M4 screw mounting holes |
| Pin Name | Description |
|---|---|
| G | Ground (GND) |
| V | 5V Power Supply |
| SDA | I2C Data Line |
| SCL | I2C Clock Line |
An external 6-16V DC power supply (connected via the VIN/G port) is MANDATORY for normal operation of connected DC or encoder motors.
Observe the following led status after connecting external power:
-
Power LED (ON): Indicates correct polarity and normal module power. This is the NORMAL operating state.
-
ERR LED (ON): Indicates REVERSE POLARITY connection. This is a critical error warning and is NOT a normal state. Immediately disconnect power and correct the wiring. Continuous reverse polarity may cause permanent module damage.
-
Both LEDs OFF: No external power detected. Check if the 6-16V power supply is connected and sufficiently charged.
The MD40 employs advanced digital signal processing to support standard AB-phase Hall-effect encoder motors. These motors integrate Hall sensors, a magnetic disk, and a geared motor, allowing for precise speed and position control. The module processes two square-wave pulse signals with a 90-degree phase difference (A and B phases) output by the encoder to determine position, speed, and direction.
Pulse counting is the accumulation of AB-phase signals from the encoder, where each pulse corresponds to the motor shaft rotating through a minimum angle.
-
Counting Method: The module uses optimized single-edge counting, triggering on each falling edge of the A-phase signal.
-
Direction Detection: Direction is determined by sampling the B-phase level during the A-phase falling edge.
- If the B-phase level matches the preset phase, the motor is considered to be rotating forward, and the pulse counter increments.
- If the B-phase level does not match, the motor is considered to be rotating in reverse, and the pulse counter decrements.
-
Key Properties:
- Real-time update on every A-phase falling edge.
- Accurate direction judgment based on the quadrature relationship.
- No cumulative error over long-term operation.
- Counter values: Positive for forward rotation, negative for reverse rotation.
Position represents the absolute angle of the motor output shaft accumulated from a reference zero point. It is calculated from the pulse count using a precise angular conversion formula:
Position (degrees) = Pulse Count * 360 / (Encoder PPR * Gearbox Reduction Ratio)
- Key Properties:
- High-resolution feedback derived from encoder pulses and gear ratio.
- Supports multi-turn absolute position recording.
- Position value includes direction sign (positive for forward, negative for reverse).
Speed reflects the real-time rotational speed of the motor output shaft. It is derived from the change in pulse count over a fixed time interval using an optimized differential algorithm:
Speed (RPM) = (Current Pulse - Previous Pulse) * 1000 * 60 / (Sampling Time (ms) * Encoder PPR * Reduction Ratio)
- Key Properties:
- Fixed 40ms sampling window for balanced real-time response and noise suppression.
- Sliding window average filtering to minimize pulse count jitter.
- Speed value includes direction sign (positive for forward, negative for reverse).
- Built-in zero-speed dead zone to prevent jitter at low speeds.
Before use, the encoder parameters must be correctly configured via the library or software interface:
- PPR (Pulses Per Revolution): Number of pulses the encoder generates per revolution.
- Reduction Ratio: Ratio of motor shaft speed to the output shaft speed.
- Phase Relationship: Defines the forward direction standard. Two configurations are supported:
- A-phase leads B-phase (A leads B by 90° during forward rotation).
- B-phase leads A-phase (B leads A by 90° during forward rotation).
- Speed Closed-Loop Control: Uses an adaptive PID algorithm to maintain a set speed. It features load adaptation, automatically compensating for speed fluctuations caused by changing loads to ensure constant output performance.
- Tunable PID Parameters: P (Proportional) for responsiveness, I (Integral) for steady-state error elimination, D (Derivative) to suppress overshoot and oscillation.
- Position Closed-Loop Control: Employs a dual-loop architecture (inner speed loop, outer position loop) for precise and smooth positioning. Includes intelligent motion planning that automatically decelerates as the target position nears, preventing overshoot. Position arrival is determined by both position error and velocity state.
- Tunable PID Parameters: P (Proportional) for responsiveness, I (Integral) for steady-state error elimination, D (Derivative) to suppress overshoot.
The MD40 is designed for standard AB-phase Hall-effect encoder motors with a 90° quadrature signal. Ensure signal levels are 3.3V/5V. The module uses a 6-pin PH2.0 interface (-, V, B, A, G, +) and is compatible with motors that meet this interface standard.
- MicroPython: Example programs for ESP32.
- Arduino: Library documentation, example programs, support Arduino Series and ESP32 Series.
- MakeCode Expansion: https://github.com/emakefun-makecode-extensions/emakefun_md40motor

