🛠 First Setup of the Encoder Motor Driver
Objectives
This tutorial aims to perform the first physical connection and power-up of the M5Stack Encoder Motor Driver Unit (DRV8837DSGR). You will learn to identify connectors, provide correct power, and verify initial I2C communication. By the end, you will know if your unit is functional and ready for motor control.
Required Materials
- 1x Encoder Motor Driver Unit (DRV8837DSGR)
- 1x DC motor with encoder (6-wire) or compatible TT motor
- 1x External DC Power Supply (6V to 12V)
- 1x Grove Cable (for I2C link to a master like M5Stack Core2 or ESP32)
- Arduino IDE software with M5Stack library installed
Steps
- Component Check : Ensure the unit has no visible damage. The default I2C address is 0x2F. If you change the address, note it immediately.
- Motor Connection : Connect the motor to the motor terminals on the unit. For a 6-wire motor, follow the standard pinout (Phase A/B and Encoder A/B). For a TT motor, connect the two power wires.
- External Power : Connect your DC source (6-12V) to the external power terminals (GND and VCC). The unit will convert this to internal 5V for the motor (max 1.2A).
- I2C Link : Connect the unit to your master board via the Grove port. Ensure SDA and SCL lines are correctly connected. Do not connect motor power before verifying the logical link.
- Software Initialization : Open Arduino IDE. Install the M5Stack library. Create a new project. Include
M5Unified.hor the specific driver library if available. - Test Code : Write a minimal code to initialize I2C and scan the bus. Basic command example:
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("Scanning I2C...");
for (byte i = 8; i < 120; i++) {
Wire.beginTransmission(i);
if (Wire.endTransmission() == 0) {
Serial.print("Found address: ");
Serial.println(i, HEX);
}
}
}
void loop() {}
- Upload : Compile and upload the code to your master board.
Verification
Open the serial monitor at 115200 bauds. You should see the address 0x2F displayed in the I2C scanner. If the address appears, communication is established. The WS2812C RGB LED may light up briefly at startup, indicating correct power. If no address is found, check SDA/SCL connections and power supply.
Further Steps
Once communication is confirmed, explore closed-loop control modes. Test encoder reading to measure actual motor speed. You can then implement a simple PID to maintain constant speed despite variable loads.
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
- GPIO and RGB LED Control on the Encoder Motor Driver Unit
- Encoder feedback automation with DRV8837
- Advanced Configuration and I2C Bus Validation
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