Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created November 28, 2019 17:42
Show Gist options
  • Save CelliesProjects/0228d85568c02612925ed0a46591fffd to your computer and use it in GitHub Desktop.
Save CelliesProjects/0228d85568c02612925ed0a46591fffd to your computer and use it in GitHub Desktop.
POC to drive M5 Balancer Robot I2C base with motors.
#include <Wire.h>
#define M5GO_WHEEL_ADDR 0x56
#define MOTOR_CTRL_ADDR 0x00
#define ENCODER_ADDR 0x04
#define DEAD_ZONE 5
void setMotor(int16_t pwm0, int16_t pwm1) {
Wire.beginTransmission(M5GO_WHEEL_ADDR);
Wire.write(MOTOR_CTRL_ADDR); // Motor ctrl reg addr
Wire.write(((uint8_t*)&pwm0)[0]);
Wire.write(((uint8_t*)&pwm0)[1]);
Wire.write(((uint8_t*)&pwm1)[0]);
Wire.write(((uint8_t*)&pwm1)[1]);
Wire.endTransmission();
}
void setup() {
// put your setup code here, to run once:
Wire.begin();
delay(100);
Wire.beginTransmission( M5GO_WHEEL_ADDR );
uint8_t error = Wire.endTransmission();
if ( error ) ESP_LOGI( TAG, "no motors" );
setMotor( 0,-0 );
}
void loop() {
int16_t power = time(NULL) % 256;
setMotor( power, 0-power );
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment