m5stack-encoder-motor-i2c-esp32.ino

M5Stack Encoder Motor Driver Unit (DRV8837DSGR) · File : m5stack-encoder-motor-i2c-esp32.ino · Language : C++ (Arduino) · Use case : Initialiser la communication I2C avec l'unité Encoder Motor Driver sur un ESP32 et vérifier la présence du périphérique.

Minimal example to detect the unit via the I2C bus on an ESP32.

This code uses the standard Arduino Wire library. It configures the I2C bus on the ESP32 default pins (GPIO21/22). It attempts to send a frame to address 0x2F to confirm physical connection. If the return is 0, the device is present. Ensure the external 6-12V power supply is connected for the logic circuit to function correctly.

m5stack-encoder-motor-i2c-esp32.ino

#include <Wire.h>

// Adresse I2C par défaut du DRV8837DSGR Unit
#define I2C_ADDRESS 0x2F

void setup() {
  Serial.begin(115200);
  Wire.begin(); // Initialisation I2C par défaut (GPIO21 SDA, GPIO22 SCL sur ESP32)

  Serial.println("Searching for Encoder Motor Driver Unit...");
  
  // Vérification simple de la présence du périphérique
  Wire.beginTransmission(I2C_ADDRESS);
  if (Wire.endTransmission() == 0) {
    Serial.println("Found Encoder Motor Driver Unit at 0x2F");
  } else {
    Serial.println("Device not found. Check wiring or address.");
  }
}

void loop() {
  delay(1000);
}

← Back to the board