Skip to content

Commit b95a8a6

Browse files
Added support for returning temperature in Freedom Units, removed I2C hardware init in class constructor
*that's fahrenheit for all ya non-yanks.
1 parent 30e6e86 commit b95a8a6

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

examples/Example3_SetFilterCoeffecients/Example3_SetFilterCoeffecients.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void setup(){
3838
//check if the Device ID is correct
3939
if(tempSensor.checkDeviceID()){
4040
Serial.println("Device ID is correct!");
41+
Serial.print("Device ID reported as: 0x");
42+
Serial.println(tempSensor.readDoubleRegister(DEVICE_ID), HEX);
4143
}
4244
else {
4345
Serial.println("Device ID is not correct! Freezing.");

src/SparkFun_MCP9600.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ Distributed as-is; no warranty is given.
3030
MCP9600::MCP9600(uint8_t address, TwoWire &wirePort){
3131
_deviceAddress = address; //grab the address that the sensor is on
3232
_i2cPort = &wirePort; //grab the port that the user wants to use
33-
_i2cPort->begin();
34-
_i2cPort->setClock(10000);
3533
}
3634

3735

@@ -53,19 +51,22 @@ bool MCP9600::checkDeviceID(){
5351

5452
/*----------------------------- Sensor Measurements ---------------------*/
5553

56-
float MCP9600::thermocoupleTemp(){
54+
float MCP9600::thermocoupleTemp(bool units){
5755
int16_t raw = readDoubleRegister(HOT_JUNC_TEMP);
58-
return ((float)raw * DEV_RESOLUTION);
56+
float celcius = ((float)raw * DEV_RESOLUTION);
57+
units ? return celcius; : return (((float)celcius * 1.8f) + 32);
5958
}
6059

61-
float MCP9600::ambientTemp(){
60+
float MCP9600::ambientTemp(bool units){
6261
int16_t raw = readDoubleRegister(COLD_JUNC_TEMP);
63-
return ((float)raw * DEV_RESOLUTION);
62+
float celcius = ((float)raw * DEV_RESOLUTION);
63+
units ? return celcius; : return (((float)celcius * 1.8f) + 32);
6464
}
6565

66-
float MCP9600::tempDelta(){
66+
float MCP9600::tempDelta(bool units){
6767
int16_t raw = readDoubleRegister(DELTA_JUNC_TEMP);
68-
return ((float)raw * DEV_RESOLUTION);
68+
float celcius = ((float)raw * DEV_RESOLUTION);
69+
units ? return celcius; : return (((float)celcius * 1.8f) + 32);
6970
}
7071

7172
signed long MCP9600::rawADC(){

src/SparkFun_MCP9600.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class MCP9600{
106106
bool resetToDefaults(); //Resets all device parameters to their default values. Returns 1 if there was an error, zero otherwise.
107107

108108
//Sensor measurements
109-
float thermocoupleTemp(); //Returns the thermocouple temperature in degrees Celcius
110-
float ambientTemp(); //Returns the ambient (IC die) temperature in degrees Celcius
111-
float tempDelta(); //Returns the difference in temperature between the thermocouple and ambient junctions, in degrees Celcius
109+
float thermocoupleTemp(bool units = true); //Returns the thermocouple temperature. Set units to true for Celcius, or false for freedom units (Fahrenheit)
110+
float ambientTemp(bool units = true); //Returns the ambient (IC die) temperature. Set units to true for Celcius, or false for freedom units (Fahrenheit)
111+
float tempDelta(bool units = true); //Returns the difference in temperature between the thermocouple and ambient junctions. Set units to true for Celcius, or false for freedom units (Fahrenheit)
112112
signed long rawADC(); //Returns the raw contents of the raw ADC register
113113
bool inputRangeExceeded(); //Returns true if the MCP9600's EMF range has been exceeded, and false otherwise.
114114

0 commit comments

Comments
 (0)