I want to read three MCP9808 sensor breakout boards from adafruit. You can set the address on these boards with jumpers as described in adafruits tutorial. The default address is 0x18, while other available addresses are 0x19, 0x1A, and 0x1C. https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide/pinouts
there is a nice library by romainmp for particle devices here.
also available on particle build
There is an example for reading a single sensor - works great.
However, when I try to add a second sensor at 0x19 - the callout to the second sensor just keeps reading the first sensor at the default address of 0x18. Double checked all my wiring. Here is my code. Perhaps I am not addressing the second sensor properly.
Here is my code. Note, all I did was add a second instance of the sensor to romainmp’s example.
#include "MCP9808.h"
MCP9808 mcp = MCP9808();
MCP9808 mcp1 = MCP9808(0x19);
void setup()
{
Serial.begin(9600);
delay(5000);
Serial.println("MCP9808 test");
// Wait for the sensor to come up
while(! mcp.begin()){
Serial.println("MCP9808 -0 not found");
delay(500);
}
// Wait for the sensor to come up
while(! mcp1.begin()){
Serial.println("MCP9808 -1 not found");
delay(500);
}
// Set resolution to the maximum (slowest conversion)
mcp.setResolution(MCP9808_SLOWEST);
mcp1.setResolution(MCP9808_SLOWEST);
Serial.println("MCP9808 OK");
}
void loop()
{
Serial.print("Temp0:"); Serial.println(mcp.getTemperature(), 4);
delay(250);
Serial.print("Temp1:"); Serial.println(mcp1.getTemperature(), 4);
delay(250);
}