I am trying to use this with I2C and have found plenty of examples.
Here is a current one with diagnostics in it:
#include <Wire.h>
#define deviceId 0x60 //defines address of compass
void setup(){
Wire.begin(); //conects I2C
Serial.begin(9600);
}void loop(){
Serial.println("About to begin transmission");Wire.beginTransmission(deviceId);
Serial.println("About to send a 2");
Wire.send(2);Serial.println("About to end transmission");
Wire.endTransmission();Serial.println("Transmission ended");
delay(10);Serial.println("About to request data");
Wire.requestFrom(deviceId,
2);delay(10);
int avail = Wire.available();
Serial.println("Wire.available()");
Serial.println(avail);unsigned int value =
((unsigned int)
Wire.receive()) << 8;
value = value + ((unsigned int)
Wire.receive());Serial.print("Data received, value is: ");
Serial.println(value);delay(1000);
}
I get this output over an over and...
About to begin transmission
About to send a 2
About to end transmission
Transmission ended
About to request data
Wire.available()
0
Data received, value is: 0
About to begin transmission
About to send a 2
About to end transmission
Transmission ended
About to request data
Wire.available()
0
Data received, value is: 0
I have checked and rechecked wiring. It matches what is documented. 4.5V to to the power pin (and I have checked it with a meter and I use the power for other working components). I am using a MEGA 2560, so I am going to pins 20 and 21 respectively for SDA and SCL.
One thing I cannot find documented is the little component (diode? LED? it is so tiny I am not sure) that flashes sometimes when the CMPS09 is powered up. It rarely flashes; maybe every fifth time I power it on and never for more than a fraction of a second. If someone else has one, I would appreciate knowing if that is normal.