MCP9808 found at I2C scanner, yet not accessible

Hi,

Got a generic MCP9808 temperature sensor board from Aliexpress.

I2C scanner finds the unit at default address 0x18, no problem there.
However, none of the MPC9808 libraries demo software can connect to the sensor, eventhough I2C addr is set 0x18.
Tried Adafruit, DFRobot, and some other library. All say "can't find sensor".

Bad sensor, or is there any recommended library to try with, or other tweak?

Thanks.

OP here... chatgpt helped to diagnose faulty sensor, with wire.h only bit level code to access the sensor registers. With this code i could access the sensor but receive constantly the same wrong result.

FYI the code:


#include <Wire.h>

#define MCP9808_ADDR 0x18

void setup() {
  Serial.begin(9600);
  Wire.begin();
  delay(1000);  // Allow sensor to initialize

  // Wake up sensor by clearing shutdown mode (Config register 0x01)
  Wire.beginTransmission(MCP9808_ADDR);
  Wire.write(0x01);  // Configuration register
  Wire.write(0x00);  // MSB
  Wire.write(0x00);  // LSB
  Wire.endTransmission();

  Serial.println("Sensor initialized. Reading temperature...");
}

void loop() {
  Wire.beginTransmission(MCP9808_ADDR);
  Wire.write(0x05);  // Temperature register
  Wire.endTransmission();
  Wire.requestFrom(MCP9808_ADDR, 2);

  if (Wire.available() == 2) {
    uint8_t msb = Wire.read();
    uint8_t lsb = Wire.read();

    uint16_t rawTemp = ((msb & 0x1F) << 8) | lsb;
    float temperature = rawTemp * 0.0625;
    if (msb & 0x10) {
      temperature -= 256;
    }

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");
  } else {
    Serial.println("Error reading sensor");
  }

  delay(1000);
}

Check all the jumper wires of your setup. If those are OK, maybe the sensor itself is faulty.

What is the wrong result?

TRy this variation of the code. It checks the return values of important I2C calls.
Please post 20 lines of output (as text).


#include <Wire.h>

#define MCP9808_ADDR 0x18

void setup() 
{
  while(!Serial);
  Serial.begin(9600);
  Wire.begin();
  delay(1000);  // Allow sensor to initialize

  // Wake up sensor by clearing shutdown mode (Config register 0x01)
  Wire.beginTransmission(MCP9808_ADDR);
  Wire.write(0x01);  // Configuration register
  Wire.write(0x00);  // MSB
  Wire.write(0x00);  // LSB
  int n = Wire.endTransmission();
  Serial.print("A: ");
  Serial.println(n);

  Serial.println("Sensor initialized. Reading temperature...");
}

void loop() {
  Wire.beginTransmission(MCP9808_ADDR);
  Wire.write(0x05);  // Temperature register
  int n = Wire.endTransmission();
  Serial.print("B: ");
  Serial.println(n);
  
  int r = Wire.requestFrom(MCP9808_ADDR, 2);
  Serial.print("R: ");
  Serial.println(r);
  
  if (Wire.available() == 2) {
    uint16_t msb = Wire.read();
    uint16_t lsb = Wire.read();

    uint16_t rawTemp = ((msb & 0x1F) << 8) | lsb;
    float temperature = rawTemp * 0.0625;
    if (msb & 0x10) {
      temperature -= 256;
    }

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");
  } else {
    Serial.println("Error reading sensor");
  }

  delay(1000);
}

BTW
wrote this lib - GitHub - RobTillaart/MCP9808_RT: Arduino library for MCP9808 temperature sensor
Did you test it too?

1 Like

Hi,
thanks for your reply.
With your library the sensor value is, and was earlier with chatgpt, constant 1.81C at room temperature.

Ran your library test and minimum. Please see

MCP9808_LIB_VERSION: 0.4.0

test_0
CONFIG:   1D
TUPPER:   0.00
TLOWER:   0.00
TCRIT:    0.00
TAMBIENT: 0.00
Resolut:  3
Manufact: 84
DeviceID: 4
Revision: 0
RFU:      29


test_1
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	
0.0000	4	

test_2
0.0000	0.0000	4	
3.2500	0.0000	5	
6.2500	0.0000	5	
9.5000	0.0000	5	
12.5000	0.0000	5	
15.7500	0.0000	5	
18.7500	0.0000	5	
22.0000	0.0000	5	
25.2500	0.0000	5	
28.2500	0.0000	5	

0.0000	0.0000	4	
3.2500	0.0000	4	
6.2500	0.0000	4	
9.5000	0.0000	4	
12.5000	0.0000	4	
15.7500	0.0000	4	
18.7500	0.0000	4	
22.0000	0.0000	4	
25.2500	0.0000	4	
28.2500	0.0000	4	

0.0000	0.0000	4	
4.0000	0.0000	0	
8.0000	0.0000	0	
12.0000	0.0000	0	
16.0000	0.0000	0	
20.0000	0.0000	0	
24.0000	0.0000	0	
28.0000	0.0000	0	
32.0000	0.0000	0	
36.0000	0.0000	0	


test_3
0	0
1	1
2	2
3	3


C:\Users\j\Documents\Arduino\ArdTest\mcp9808_minimumrt\mcp9808_minimumrt.ino
MCP9808_LIB_VERSION: 0.4.0
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125
1.8125

I guess the sensor is bad?

MCP9808_LIB_VERSION: 0.4.0

test_0
CONFIG:   1D
TUPPER:   0.00
TLOWER:   0.00
TCRIT:    0.00
TAMBIENT: 0.00
Resolut:  3
Manufact: 84
DeviceID: 4
Revision: 0
RFU:      29

Test 0 looks OK, only difference with my tests I see is the Revision


test_1
0.0000	4	

Temperature == 0 is not expected.
Status 4 is correct as the (wrong) temperature measured >= Tcritical.


test_2
0.0000	0.0000	4	
3.2500	0.0000	5	
...
0.0000	0.0000	4	
3.2500	0.0000	4	
...
0.0000	0.0000	4	
4.0000	0.0000	0	

test2 tests Tlower behaviour which works correctly, although the temperature measured is still incorrect.
Tupper idem
Tcritical idem


test_3
0	0
1	1
2	2
3	3

Test3 tests get set resolution, works OK


mcp9808_minimumrt.ino
MCP9808_LIB_VERSION: 0.4.0
1.8125
1.8125

Still temperature is incorrect (my assumption) although it is not zero as in the tests.


So my conclusion is

  1. I2C communication is working OK
  2. the processor in the sensor (memory + math) seems to work correctly,
  3. the analog temperature part in the sensor is not working,
  4. This makes the sensor 99.9% useless.

The 0.1% is that you still can store a few values in its registers, imho not worth saving it.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.