I have a robot project that includes one i2c bus that talks to two MD04 motor controllers and one accelerometer from an Arduino Mega 2560. I can read and write to the accelerometer just fine (with an example different than below), but no matter how simple of a program I put in to talk to the MD04, it won’t talk back. I have configured the MD04 with the utility, and when I go back in, it is set to what I want. I can set it to other things and see those settings stick also, so that seems ok. Here is my code. Anyone have any ideas?
//Super simple MD04 test
#include
#define ADDRESS 0xb2 // Address of MD04
void setup() {
Wire.begin();
Serial.begin(115200);
int software = getData(ADDRESS);
Serial.print("MD04 test using software version ");
Serial.println(software);
}
void loop() {
// put your main code here, to run repeatedly:
}
byte getData(byte reg){ // function for getting data from MD04
Serial.println ("Setting up for read...");
Wire.beginTransmission(ADDRESS);
Wire.write(reg);
Wire.endTransmission();
Serial.println ("Reading...");
Wire.requestFrom(ADDRESS, 1); // Requests byte from MD04
while( Wire.available() < 1) { // Waits for byte to become available
}
byte data = Wire.read();
return(data);
}