I ran an I2C scanner that I found here: http://www.esp8266.com/viewtopic.php?f=29&t=3683
The scanner found the sensor and gaves the expected adress (0x1C).
If the scanner works, can I be sure that the I2C connection works?
After that I made a small program to see if I could read something from the sensor (I use the arduino IDE).
#include <Wire.h>
void setup()
{
Wire.begin(0, 2);
Wire.setClock(100000);
Serial.begin(9600);
Serial.println();
}
void loop()
{
Wire.beginTransmission(0x1C);
Wire.write(0x0D); //WHO_AM_I register
int error=Wire.endTransmission(false); // MMA8451 + friends uses repeated start!!
Serial.print("Transmissionerror: ");
Serial.println(error);
Wire.requestFrom(0x1C, 1);
if (! Wire.available()) {
Serial.println("Nothing came back");
}
else {
Serial.println(Wire.read());
}
delay(1000);
}
This is what I get in the serial monitor:
- Transmissionerror: 0
Nothing came back
Transmissionerror: 4
Nothing came back
Transmissionerror: 4
...
If I put the same program on a arduino nano and use Wire.begin(), it works perfect and I get the value from the register (26). So there is nothing wrong with the program or sensor. The only place where I think the problem can be is in the special Wire library or in the hardware connection.
I added two 10k pull-up resistor to GPIO 0 and 2 and connected them to SDA and SCL. Here is the schematic of the sensor board:
http://imgs.inkfrog.com/pix/ebayimage2012/24767-4.jpg
Can somebody help me figuring out what the problem is? I tried a lot of different things (changing clock speed, removing the pull-ups, using a lvl shifter to go back to 5v,...) But nothing seems to work.