We have produced a library for Microchip Technology's MCP9804 I2C-connected temperature sensor.
Details here: Hackscribble MCP9804 project page
Download the library files, example programs and user guide from here: Hackscribble MCP9804 library files
You can get the MCP9804 datasheet from the Microchip Technology website.
Schematic and PCB design (KiCad format) now available here: MCP9804 hardware project page
We would love to get your feedback on the library and ideas for improvements, either here or through our GitHub pages.
Regards
Ray at Hackscribble
looks really good, only a few small remarks
void Hackscribble_MCP9804::_setThresholdInteger(MCP9804_Register reg, int8_t val)
{
// For Tupper and Tcrit, alert is triggered when Ta:
// 1. rises above threshold
// 2. falls back below (threshold - hysteresis)
// For Tlower, alert is triggered when Ta:
// 1. falls below (threshold - hysteresis)
// 2. rises back above threshold
uint16_t temp = (uint8_t)val << 4; // <<<<<<<<<<
temp |= (val < 0 ? 0x1000 : 0x0000);
_writeRegister16(reg, temp);
}
The int8_t val is casted to unsigned. you might loose info.
temp |= (val < 0 ? 0x1000 : 0x0000);
==>
if (val < 0) temp |= 0x1000;
boolean Hackscribble_MCP9804::alertTCRIT()
{
return (_readRegister16(REG_TA) & 0x8000) > 0;
}
boolean Hackscribble_MCP9804::alertTUPPER()
{
return (_readRegister16(REG_TA) & 0x4000) > 0;
}
boolean Hackscribble_MCP9804::alertTLOWER()
{
return (_readRegister16(REG_TA) & 0x2000) > 0;
}
These three are very similar, you might merge them into
uint8_t Hackscribble_MCP9804::getAlert()
{
uint8_t alert = _readRegister16(REG_TA) >> 9;
if (t & 4) return TCRITICAL; // to be defined enum
if (t & 2) return TUPPER;
if (t & 1) return TLOWER;
return TNONE;
}
functions like this below that are just a wrapper, can be better defined inline in the .h file,
then the compiler can optimize it
uint16_t Hackscribble_MCP9804::getManufacturerID()
{
return (_readRegister16(REG_MANUFACTURER_ID));
}
inline uint16_t Hackscribble_MCP9804::getManufacturerID()
{
return (_readRegister16(REG_MANUFACTURER_ID));
}
my 2 cents
Many thanks, Rob. Your comments are going on the todo list for the next release 