🛠 Automating Precise Movement with the Encoder Motor Driver

M5Stack Encoder Motor Driver Unit (DRV8837DSGR) · debutant · Apprenez à configurer un mouvement en boucle fermée pour un positionnement précis et répétable.

Objectives

This tutorial aims to automate a DC motor movement using closed-loop control. Unlike simple PWM mode, closed-loop control uses encoder data to correct speed in real-time, ensuring positioning accuracy even under variable load. We will configure the unit to reach a specific target position.

Required Materials

Steps

  1. Physical Connection: Connect the motor to the motor terminals of the unit. Ensure the encoder wires (usually center or dedicated wires depending on the model) are correctly connected to the unit's encoder ports. Connect the unit to the master via the Grove cable (I2C). Provide external power (6-12V).
  1. Software Configuration: In your IDE (Arduino or UIFlow), initialize I2C communication. The default address is 0x2F. If using UIFlow, add the 'Encoder Motor Driver' block.
  1. Parameter Definition: Configure the PPR (Pulses Per Revolution) of your encoder (between 3 and 15). For example, if your motor has a 12 PPR encoder, enter this value. Define the target speed in RPM.
  1. Position Command: Send a command to move the motor to an absolute or relative position. For example, ask the motor to rotate 360 degrees. The driver will use the DRV8837 H-bridge to adjust current and speed to reach the target.
  1. Status Monitoring: Use read functions to check the current position and actual speed. The RGB LED can be configured to indicate status (e.g., blue while moving, green when target is reached).

Verification

Run the program. The motor should rotate and stop precisely at the requested position. If you slightly block the motor with your hand, the driver should increase current to maintain position (thanks to INA199A detection). Verify that speed remains stable despite load variations.

Further Exploration

Explore the 'soft start/stop' mode to avoid mechanical shocks. You can also change the I2C address to connect multiple units on the same bus and create a multi-axis positioning system.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials