i2c-motor-spin.ino
Minimalist example to initialize I2C communication and send a speed command to the first motor.
Uses the default I2C bus (GPIO 21/22 on ESP32/M5Stack). Verify that address 0x24 is correct. This code is a skeleton; for precise control (PID, position), use the official M5Stack_MotorDriverUnit library.
i2c-motor-spin.ino
#include <Wire.h>
#define UNIT_ADDR 0x24
#define MOTOR_CH 1 // 1-4
#define SPEED 100 // 0-100%
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("Starting Motor Driver Unit...");
}
void loop() {
// Commande simplifiée via registre de contrôle (exemple générique M5Stack)
// Note : L'API réelle nécessite souvent la lib M5Stack_MotorDriverUnit
// Ici, simulation d'une écriture bas niveau pour l'exemple
Wire.beginTransmission(UNIT_ADDR);
Wire.write(0x01); // Registre de commande
Wire.write(MOTOR_CH);
Wire.write(SPEED); // Vitesse positive = avance
Wire.endTransmission();
delay(1000);
}