🛠 Distributed Automation: Precise Control and Telemetry with the Encoder Motor Driver Unit

M5Stack Encoder Motor Driver Unit (DRV8837DSGR) · avance · Intégrez l'unité DRV8837DSGR dans un système IoT pour un contrôle en boucle fermée synchronisé et une remontée de données en temps réel.

Objectives

This advanced tutorial aims to design an autonomous automation node using the Encoder Motor Driver Unit (DRV8837DSGR). The goal is to move beyond manual control to implement a closed-loop (PID) strategy based on encoder data, while integrating the card into an IoT network for telemetry. We will leverage the INA199A current sensing capabilities for motor protection and the RGB LED for local status indication.

Required Hardware

Steps

Connect the unit to the Grove I2C port of your main board. Ensure the external power supply is connected to the unit's DC connector (6-12V). By default, the I2C address is 0x2F. For a multi-node network, you must configure a unique address (between 0x08 and 0x77) via AD0/AD1 lines if available, or via the initial software command if the firmware allows, to avoid bus conflicts.

  1. Hardware Configuration and Addressing

Initialize I2C communication in the code. Configure the operating mode to "Closed Loop". Calibrate the encoder resolution. The unit supports encoders from 3 to 15 PPR (Pulses Per Revolution). Define the PPR constant according to your specific motor to convert pulses into degrees or revolutions.

  1. Initialization and Encoder Calibration

Do not just send a speed setpoint. Read position and speed data via I2C registers. Implement a simple PID algorithm on the main board: calculate the error between the target position and the current position, then adjust the PWM setpoint sent to the unit. Use "Progressive Start/Stop" modes to avoid mechanical shocks during setpoint changes.

  1. PID Control Loop Implementation

Every 500ms, read status registers: current consumption (INA199A), current speed, and position. Publish this data to an MQTT broker. Use the current sensing circuit to define a safety threshold: if current exceeds 1.2A (load limit), immediately stop the motor to prevent overheating.

  1. Network Integration and Telemetry

Drive the integrated WS2812C LED to reflect system status: Green (nominal operation), Red (position error or overcurrent), Blue (active network connection). This allows for immediate visual diagnosis without a screen.

  1. Visual Feedback via RGB LED

Verification

To Go Further

Explore multi-axis synchronization using multiple units on the same I2C bus with distinct addresses. Integrate a Kalman filter algorithm to smooth AB encoder data and improve PID control stability at high speeds.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials