I have several MCUs but all of them are SPI. Anyway, to determine what is going on with your Due-9DOF Stick, I'd recommend you to start trying to communicate with one of the sensors, let's say the accelerometer, and then with the other two. I assume that you know how accelerometers work. Just in case remember, under steady-state, all the values (x,y,z) should be zero. When the stick is in motion, the values change.
Here a sketch that I have built just for the accelerometer after the chionophilous' tutorial that you have followed. It should work (theoretically). I assume, also, that you have connected 3.3V, GND, SDA and SCL between the stick and due.
#include <Wire.h>
#define ADXL345_ADDRESS (0xA6 >> 1)
#define ADXL345_REGISTER_XLSB (0x32)
#define ADXL_REGISTER_PWRCTL (0x2D)
#define ADXL_PWRCTL_MEASURE (1 << 3)
int accelerometer_data[3];
void setup() {
Wire.begin();
Serial.begin(9600);
for(int i = 0; i < 3; ++i) {
accelerometer_data[i] = 0;
}
init_adxl345();
}
void loop() {
read_adxl345();
Serial.print("ACCEL: ");
Serial.print(accelerometer_data[0]);
Serial.print("\t");
Serial.print(accelerometer_data[1]);
Serial.print("\t");
Serial.print(accelerometer_data[2]);
Serial.print("\n");
delay(100);
}
void init_adxl345() {
byte data = 0;
i2c_write(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, ADXL_PWRCTL_MEASURE);
i2c_read(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, 1, &data);
Serial.println((unsigned int)data);
}
void read_adxl345() {
byte bytes[6];
memset(bytes,0,6);
i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB, 6, bytes);
for (int i=0;i<3;++i) {
accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
}
}
void i2c_write(int address, byte reg, byte data) {
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(data);
Wire.endTransmission();
}
void i2c_read(int address, byte reg, int count, byte* data) {
int i = 0;
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.requestFrom(address,count);
while(Wire.available()) {
char c = Wire.read();
data[i] = c;
i++;
}
Wire.endTransmission();
}
Let me know how it goes.
p
EDIT: Try to make shorter the wires between Due and the stick.