Skip to content

Commit 6ea508e

Browse files
authored
Merge pull request #13 from mikeysklar/setAmbientResolution
setAmbientResolution()
2 parents bbb08d9 + 930d661 commit 6ea508e

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

Adafruit_MCP9600.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,17 @@ uint8_t Adafruit_MCP9600::getStatus(void) {
363363

364364
return status.read();
365365
}
366+
367+
/**************************************************************************/
368+
/*!
369+
@brief Sets the resolution for ambient (cold junction) temperature readings
370+
@param res_value Ambient_Resolution enum value to set resolution
371+
*/
372+
/**************************************************************************/
373+
void Adafruit_MCP9600::setAmbientResolution(Ambient_Resolution res_value) {
374+
uint8_t config;
375+
_config_reg->read(&config, 1); // Read the current configuration
376+
config &= ~0xC0; // Clear existing resolution bits
377+
config |= ((~res_value & 0x03) << 6); // Set inverted resolution bits
378+
_config_reg->write(config); // Write back the configuration
379+
}

Adafruit_MCP9600.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ typedef enum _resolution {
6464
MCP9600_ADCRESOLUTION_12,
6565
} MCP9600_ADCResolution;
6666

67+
/*! The possible Ambient resolutions */
68+
typedef enum {
69+
RES_ZERO_POINT_25 = 0b00, ///< 0.25°C
70+
RES_ZERO_POINT_125 = 0b01, ///< 0.125°C
71+
RES_ZERO_POINT_0625 = 0b10, ///< 0.0625°C
72+
RES_ZERO_POINT_03125 = 0b11 ///< 0.03125°C
73+
} Ambient_Resolution;
74+
6775
/**************************************************************************/
6876
/*!
6977
@brief MCP9600 driver.
@@ -91,6 +99,8 @@ class Adafruit_MCP9600 {
9199
MCP9600_ADCResolution getADCresolution(void);
92100
int32_t readADC(void);
93101

102+
void setAmbientResolution(Ambient_Resolution res_value);
103+
94104
void setAlertTemperature(uint8_t alert, float temp);
95105
float getAlertTemperature(uint8_t alert);
96106
void configureAlert(uint8_t alert, bool enabled, bool rising,

examples/mcp9600_test/mcp9600_test.ino

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@
77

88
Adafruit_MCP9600 mcp;
99

10+
/* Set and print ambient resolution */
11+
Ambient_Resolution ambientRes = RES_ZERO_POINT_0625;
12+
1013
void setup()
1114
{
12-
Serial.begin(115200);
13-
while (!Serial) {
14-
delay(10);
15-
}
16-
Serial.println("MCP9600 HW test");
15+
Serial.begin(115200);
16+
while (!Serial) {
17+
delay(10);
18+
}
19+
Serial.println("MCP9600 HW test");
1720

18-
/* Initialise the driver with I2C_ADDRESS and the default I2C bus. */
19-
if (! mcp.begin(I2C_ADDRESS)) {
20-
Serial.println("Sensor not found. Check wiring!");
21-
while (1);
22-
}
21+
/* Initialise the driver with I2C_ADDRESS and the default I2C bus. */
22+
if (! mcp.begin(I2C_ADDRESS)) {
23+
Serial.println("Sensor not found. Check wiring!");
24+
while (1);
25+
}
2326

2427
Serial.println("Found MCP9600!");
2528

29+
/* Set and print ambient resolution */
30+
mcp.setAmbientResolution(ambientRes);
31+
Serial.print("Ambient Resolution set to: ");
32+
switch (ambientRes) {
33+
case RES_ZERO_POINT_25: Serial.println("0.25°C"); break;
34+
case RES_ZERO_POINT_125: Serial.println("0.125°C"); break;
35+
case RES_ZERO_POINT_0625: Serial.println("0.0625°C"); break;
36+
case RES_ZERO_POINT_03125: Serial.println("0.03125°C"); break;
37+
}
38+
2639
mcp.setADCresolution(MCP9600_ADCRESOLUTION_18);
2740
Serial.print("ADC resolution set to ");
2841
switch (mcp.getADCresolution()) {

0 commit comments

Comments
 (0)