I2C Temperature Sensor MCP980X

Hello

I want to use a MCP9801 Temperature Sensor from Microchip.

Here is the DATASHEET

I managed to get data from the sensor, this is my code:

#include <Wire.h>
int ADRESS = 0x48; // define I2C Address


void setup()
{
  Wire.begin();        
  Serial.begin(9600);  
}

void loop()
{
 
   Wire.beginTransmission(ADRESS); 
    Wire.write(0b01100000);               
  Wire.endTransmission();   
 
 
  Wire.requestFrom(ADRESS, 2);    
  while(Wire.available())    
  {
    int upperbit = Wire.read(); 
    int lowerbit = Wire.read();
    Serial.print("up:   ");
    Serial.println(upperbit,BIN);        
    Serial.print("down:   ");
    Serial.println(lowerbit,BIN);
    
  }
  delay(5000);
}

The byte i send, is to switch the resolution to 0.125 C°, as described on page 18. All other configs are 0, because they are irrelevant

My problem is now, the lower bit i request.

The upper one delivers actually the value " (00)00100010 " in decimal 34 C° which is possible.

But the lower one is strange, its either “00000000” which is 0, or its “10000000” which is 128.

I placed a fan near the IC, switching on and off, even placed an ice-block near the IC. Upper bit changes to possible values. Lower one is still doing one of these…

Why?

I tried another ic, does the same :slightly_frowning_face:

What am i doing wrong?

Hi sgt_johnny

   Wire.beginTransmission(ADRESS);
    Wire.write(0b01100000);               
  Wire.endTransmission();

Before sending the value to set resolution, you have to send the address of the configuration register (I don't mean the I2C address). See the top diagram on p19 of the datasheet.

So change the code above to:

   Wire.beginTransmission(ADRESS);
    Wire.write(0b00000001);  // Select register 1
    Wire.write(0b01100000);  // Write value to register             
  Wire.endTransmission();

Then, to read the temperature from the Ta register, you need to send that register's address before your requestFrom code:

Wire.beginTransmission(ADRESS);
    Wire.write(0b00000000);  // Select register 0 for next operation               
  Wire.endTransmission(); 
  Wire.requestFrom(ADRESS, 2);   
  while(Wire.available())   
  {
etc

Regards

Ray

Hi Hackerscribble

Thank you very much, works now! :slight_smile:

:smiley: