MCP9808 precision I2C temperature sensor
This is a module that makes it easy to connect to a MCP9808 Precision I2C Temperature sensor.
The MCP9808 is a precision I2C temperature sensor from Microchip between -20°C and +100°C with +- 0.25°C / +- 0.5°C (typical/maximum) accuracy. This module makes it easy to connect this sensor with an espruino board.
Use the MCP9808 module for it.
Wiring Up
Pin | Espruino |
---|---|
GND | GND |
VCC | 3.3v |
SDA | B7 |
SCL | B6 |
ALERT | Open-Drain-Output |
A2 | GND or 3.3v |
A1 | GND or 3.3v |
A0 | GND or 3.3v |
Software
How to use the module:
I2C1.setup({scl:B6,sda:B7, bitrate: 60000});
var mcp = require("MCP9808").connect(I2C1, 0b000); // 0b000 means A2 = A2 = A1 = GND
var temperature = mcp.getTemperature();
console.log("Temperature: " + temperature + " C");
The sensor can handle bitrates up to 400000 but I had stability problems with this.
Reference
/* returns the current sensor resolution as enum
* MCP9808.RESOLUTION_0_5_CELSIUS 0.5°C, approx. 30 ms
* MCP9808.RESOLUTION_0_25_CELSIUS 0.25°C, approx. 65 ms
* RESOLUTION_0_125_CELSIUS 0.125°C, approx. 130 ms
* RESOLUTION_0_0625_CELSIUS 0.0615°C approx. 250 ms
*/
MCP9808.prototype.getResolution = function () { ... }
/* set the current sensor resolution
* Allowed values are:
* MCP9808.RESOLUTION_0_5_CELSIUS 0.5°C, approx. 30 ms
* MCP9808.RESOLUTION_0_25_CELSIUS 0.25°C, approx. 65 ms
* RESOLUTION_0_125_CELSIUS 0.125°C, approx. 130 ms
* RESOLUTION_0_0625_CELSIUS 0.0615°C approx. 250 ms
*/
MCP9808.prototype.setResolution = function (resolution) { ... }
/* return the temperature in °C
*/
MCP9808.prototype.getTemperature = function () { ... }
/* return whether the sensor is running or in power down mode
* true if the sensor is running
*/
MCP9808.prototype.isRunning = function () { ... }
/* wakeup the sensor from power down mode
*/
MCP9808.prototype.wakeup = function () { ... }
/* Set the sensor in power down mode
* The temperature can be read but will not be updated anymore.
*/
MCP9808.prototype.shutdown = function () { ... }
/* returns whether a configured limit temperature (lower, upper, critical) is reached
* {
* aboveCriticalLimit: true/false,
* aboveUpperLimit: true/false,
* belowLowerLimit: true7false
* }
*/
MCP9808.prototype.getAlertStatus = function () { ... }
/* get the hysteresis for alerts in °C
* If an alert has triggered and alert mode is CHECK_ALL_LIMITS_COMPARATOR or CHECK_CRITICAL_LIMIT
* the current temperature must below the limit temperature minus hysteresis.
* This avoids the flickering of the ALERT pin when temperature is around a configured limit temperature.
*
* Only 4 different values are supported. Possible return values would be
* 0.0°C, 1.5°C, 3.0°C or 6.0°C.
*
*/
MCP9808.prototype.getHysteresis = function () { ... }
/* set the hysteresis for alerts in °C
* Only 4 different values are supported: 0.0°C, 1.5°C, 3.0°C or 6.0°C.
*/
MCP9808.prototype.setHysteresis = function (celsius) { ... }
/* returns whether the ALERT pin goes high or low when an temperature alert occurs.
* returns true is the ALERT pin goes high when an temperature alert occurs.
* Hint: The ALERT pin is an open-drain-output. At least a pull-up resistor is required!
*/
MCP9808.prototype.isAlertHighActive = function () { ... }
/* set the output polarity of the ALERT pin
* true - the ALERT pin goes high when ALERT occurs
* false - the ALERT pin goes low when ALERT occurs
*
* Hint: The ALERT pin is an open-drain-output. At least a pull-up resistor is required!
*/
MCP9808.prototype.setAlertHighActive = function (highActive) { ... }
/* If the sensor is in alert mode MCP9808.CHECK_ALL_LIMITS_INTERRUPT then the alert will not
* disapper when the temperature is in a valid range again.
* Only a call the clearInterrupt() will reset the alert.
*/
MCP9808.prototype.clearInterrupt = function () { ... }
/* get the configured alert mode. Possible return values are
* MCP9808.DISABLED
* MCP9808.CHECK_ALL_LIMITS_COMPARATOR
* MCP9808.CHECK_ALL_LIMITS_INTERRUPT
* MCP9808.CHECK_CRITICAL_LIMIT
*/
MCP9808.prototype.getAlertMode = function () { ... }
/* set the alert mode, Allowed values . Possible are
* MCP9808.DISABLED
* MCP9808.CHECK_ALL_LIMITS_COMPARATOR
* MCP9808.CHECK_ALL_LIMITS_INTERRUPT
* MCP9808.CHECK_CRITICAL_LIMIT
*/
MCP9808.prototype.setAlertMode = function (mode) { ... }
/* returns if a configure temperature alert has occured
*/
MCP9808.prototype.hasAlert = function () { ... }
/* get the lower temperature limit to trigger an alert
* The default value after reset is 0°C.
*/
MCP9808.prototype.getAlertLowerLimit = function () { ... }
/* Set the lower temperature limit to trigger an alert.
* @param temperature lower limit in celsius
*/
MCP9808.prototype.setAlertLowerLimit = function (temperature) { ... }
/* get the upper temperature limit to trigger an alert
* The default value after reset is 0°C.
*/
MCP9808.prototype.getAlertUpperLimit = function () { ... }
/* Set the upper temperature limit to trigger an alert.
* @param temperature upper limit in celsius
*/
MCP9808.prototype.setAlertUpperLimit = function (temperature) { ... }
/* get the critical temperature limit to trigger an alert
* The default value after reset is 0°C.
*/
MCP9808.prototype.getAlertCriticalLimit = function () { ... }
/* Set the critical temperature limit to trigger an alert.
* @param temperature critical limit in celsius
*/
MCP9808.prototype.setAlertCriticalLimit = function (temperature) { ... }
// Read 1 byte from register reg
MCP9808.prototype.read8 = function (reg) { ... }
// Read two bytes from register reg and combine to unsigned integer
MCP9808.prototype.read16 = function (reg) { ... }
// Write one byte (value) to register reg
MCP9808.prototype.write8 = function (reg, value) { ... }
// Write an unsigned integer value (two bytes) to register reg
MCP9808.prototype.write16 = function (reg, value) { ... }
exports.connect = function (i2c, a2a1a0Pins) { ... }
Buying
Links
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.