🛠 Advanced Configuration and I2C Bus Validation
Objectives
This tutorial targets advanced users aiming to go beyond default settings. The goal is to modify the I2C address of the Encoder Motor Driver Unit (DRV8837DSGR) to avoid bus conflicts, then verify low-level communication by reading internal registers. We will confirm that the STM32G031G8U6 microcontroller responds correctly to requests and that the DRV8837DSGR H-bridge is initialized.
Hardware Required
- A development board compatible with M5Stack or a microcontroller with an I2C bus (ESP32, Arduino, etc.).
- The Encoder Motor Driver Unit (DRV8837DSGR).
- A 6-wire geared motor or TT motor.
- External DC power supply between 6V and 12V (connected to the DC port).
- Grove cables or connection wires for I2C (SDA, SCL) and power.
- A serial terminal or I2C logic analyzer (optional but recommended).
Steps
- Hardware Connection: Connect the unit to your board via the Grove connector or I2C pins. Ensure SDA and SCL are correctly wired. Connect the DC power (6-12V) to the dedicated port. The internal regulator will convert this to 5V for the motor and interface.
- Initial I2C Scan: Before configuration, scan the bus to detect the default address 0x2F. Use a standard I2C scan code to confirm the unit's presence.
- Address Configuration: To change the address (range 0x08 to 0x77), send a specific command to the configuration register. Using the M5Stack library or raw I2C commands, write the new address to the identification register. Note that this change persists after reboot.
- Driver Initialization: Send an initialization command to activate the DRV8837DSGR H-bridge. Verify that the INA199A current sensing circuit is active by reading the corresponding status register.
- Communication Test: Send a slow rotation command (low PWM) and read the AB encoder data (3-15 PPR) to validate the bidirectional data flow.
Verification
Use a logic analyzer to observe I2C frames. You should see the configured address responding to read requests. The WS2812C RGB LED can be programmed to blink upon receiving valid commands, providing immediate visual confirmation of bus activity.
Further Reading
Explore closed-loop position control by configuring PIDs via advanced registers. Test overcurrent protection by manually stalling the motor to observe the INA199A circuit's reaction.
Other tutorials for this board
- First connection and startup of the Encoder Motor Driver Unit
- Mastering I/O with the Encoder Motor Driver Unit
- Automating Precise Movement with the Encoder Motor Driver
- First Setup of the Encoder Motor Driver
- GPIO and RGB LED Control on the Encoder Motor Driver Unit
- Encoder feedback automation with DRV8837
Code examples for this board
m5stack-encoder-motor-i2c-esp32.inoC++ (Arduino)m5stack-encoder-motor-pwm-control.inoC++ (Arduino)m5stack-encoder-motor-closed-loop.inoC++ (Arduino)m5stack-encoder-motor-position-control.inoC++ (Arduino)m5stack-encoder-motor-led-status.inoC++ (Arduino)closed_loop_speed_pid.pyMicroPython