Hey guys! My first post on this forum, posting about a problem I have with my first project in the arduino environment.
I recently bought the sensor MCP9808, a temperature sensor I wan't to run on the I2c-bus of the Arduino Uno rev3.
Datasheet
Hardware wise I got some help from a friend who works with soldering to put a 4 lead sensor cable to the pins VCC, SDA, SCL and GND. He also soldered on a bridge pin between VCC and the pins A0, A1 and A2 on the sensor giving the sensor the I2c address 0x1F. Also worth mentioning is that the cable going to the sensor is about 40-50cm long. I would rather not shorten this if I don't have to since I want the sensor resting in a metal tube and then submerged in a water bath.
I hooked the 5V of the arduino up to the VCC lead. Put the SDA and SCL to inputs A4 and A5 on the arduino. GND lead to GND next to 5V and bridged 5V to SDA and SCL respectively with 10kOhm resistors.
Code wise I sat down and played around alot with this for 6 hours last night... I tried alot of different examples on different ways to run sensors on I2c but it still seems like I can't really get through to the sensor. I have done an I2c scan and indeed 0x1F is the only address to show up. I tried switching places on SDA and SCL (my friend could have mixed them up) but that made the sensor go away completely from the scan. I have changed the I2c frequency in the arduino folder (I am not at home right now so can't tell you exactly which file) from 100kHz to 400kHz without any noticable difference. I have tried to put in 2 parallell coupled 10kOhm resistors each on SDA and SCL without any difference either. One thing I havn't tried is deactivate the internal pull ups of A4 and A5.
One thing that I was wondering about in particular, the code below
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Wire.beginTransmission(0x1F);
Wire.write(0x05); // Sending register pointer 0x05 for temp bytes
Serial.println(Wire.endTransmission());
delay(1000);
}
Will very often give me the values 2, sometimes also 3, in rare cases 4 and almost never 0. However I have completed the code with
Wire.requestFrom(0x1F, 2);
Serial.println(Wire.read(), BIN);
delay(1000);
Serial.println(Wire.read(), BIN);
delay(1000);
Which normaly produces the binary codes
0000 1101
1111 1111
Sometimes though it instead goes
0000 0001
1111 1111
I have calculated these values according to the datasheet but I get something like 500 degrees celsius which, let me tell you, I don't have that in my room...
Another thing worth mentioning is that when I for instance write
Wire.requestFrom(0x1F, 6);
all of the extra bytes I fetch will just be 1111 1111.
So... Anybody here who are able to give me any hints as to what I might be doing wrong?