🛠 First Connection and Startup of the 4-Encoder Motor Driver
Objectifs
This tutorial guides you through the initial setup of the M5Stack Unit 4-Encoder Motor Driver (DRV8837DSGR). The goal is to successfully power the module, connect it to an host controller (such as an M5StickC or I2C-compatible Arduino), and confirm that I2C communication is established. We will not drive the motors yet, but we will verify the module's presence on the bus.
Matériel nécessaire
- 1x Unit 4-Encoder Motor Driver (DRV8837DSGR)
- 1x I2C-compatible host controller (e.g., M5Stack Core2, M5StickC Plus, or Arduino Uno with Grove shield)
- 1x Grove HY2.0-4P cable
- 1x External DC power supply (6V to 12V) OR host controller USB power
- Computer with Arduino IDE installed
Étapes
- Hardware Preparation: Ensure the host controller is powered off. Locate the two Grove HY2.0-4P ports on the DRV8837 module. One is the input (IN) and the other the output (OUT) for I2C daisy-chaining.
- I2C Connection: Connect a Grove cable between the host controller's Grove port and the DRV8837 module's Grove IN port. I2C communication uses SDA and SCL lines. By default, the module's I2C address is 0x24.
- Power Supply:
- *Option A (Recommended for tests)*: If using a USB-powered M5Stack controller, the Grove port provides 5V. This is sufficient to initialize the module and detect its presence but will not drive motors under load.
- *Option B (For motors)*: Connect an external DC power supply (6-12V) to the dedicated connector on the module. The module has an integrated DC-DC converter that regulates voltage for the motors and can provide up to 5V to the host via the Grove port if needed.
- Software Configuration: Open the Arduino IDE. Install the M5Stack library or a standard I2C library. Upload the following test code to your controller:
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(); // Initialize I2C bus
Serial.println("Searching for DRV8837 module...");
// Default module address
byte address = 0x24;
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.println("Module found at address 0x24!");
} else {
Serial.print("Module not found. I2C Error: ");
Serial.println(error);
}
}
void loop() {
// Nothing to do in loop for this test
delay(1000);
}
- Physical Verification: Once the code is uploaded, open the Serial Monitor at 115200 bauds. If everything is correct, the message "Module found" will appear. The integrated WS2812C RGB LED may light up depending on the module's initial firmware state.
Vérification
- The Serial Monitor displays "Module found at address 0x24!".
- There is no short circuit or abnormal heating of the module.
- If the module is not found, check the Grove cable orientation and the I2C address (configurable between 0x08 and 0x77).
Pour aller plus loin
Once communication is established, you can explore basic commands to configure control modes (open loop vs closed loop) and test the soft-start of a gear motor connected to one of the four PH2.0-6P connectors.
Other tutorials for this board
- Discovering I/O: RGB LED and Encoder Reading
- Automate a Robot Chassis with the 4-Encoder Driver
- First connection and startup of the 4-Encoder Motor Driver
- GPIO and RGB LED Control on the 4-Encoder Motor Driver
- Closed-Loop Automation with the 4-Encoder Driver
- First wiring and initialization of the 4-Encoder Motor Driver
Code examples for this board
i2c-motor-spin.inoarduinoclosed-loop-speed-control.inoarduinorelative-position-move.inoarduinorgb-led-status-indicator.inoarduinodifferential-drive-robot.inoarduinoi2c_basic_motor_control.pyPython