This commit is contained in:
Fatima Idrees 2025-05-19 14:26:59 +03:00
parent 97f01b932a
commit e209cf0196
2 changed files with 8 additions and 8 deletions

View File

@ -1,11 +1,10 @@
#include <I2CMotor.h>
#include <Wire.h>
// Define I2C pins and slave addresses
#define SDA_PIN 8
#define SCL_PIN 3
#define INITIAL_SLAVE_ADDR 0x08
#define NEW_SLAVE_ADDR 0x10
#define INITIAL_SLAVE_ADDR 0x10
#define NEW_SLAVE_ADDR 0x12
I2CMotor motor(SDA_PIN, SCL_PIN);

View File

@ -18,11 +18,12 @@ String I2CMotor::identify() {
}
void I2CMotor::setDeviceName(const char* newname) {
uint8_t len = strlen(newname);
Wire.beginTransmission(slave_addr_);
Wire.write(0x06);
Wire.write(len);
Wire.write((const uint8_t*)newname, len);
Wire.write(0x02); // CMD_SET_NAME (must match slave)
for (uint8_t i = 0; i < strlen(newname); i++) {
Wire.write(newname[i]);
}
Wire.write('\0'); // Ensure null-terminated string for slave
Wire.endTransmission();
}
@ -74,7 +75,7 @@ uint8_t I2CMotor::scanForMotorController() {
if (c == '\0') break;
id += c;
}
if (id.length() && id.indexOf("dc motor") >= 0) {
if (id.length() && id.indexOf("GENERIC") >= 0) {
Serial.print("Found motor controller at 0x");
Serial.print(addr, HEX);
Serial.print(": ");