adafruit_mcp9808

CircuitPython library to support MCP9808 high accuracy temperature sensor.

  • Author(s): Scott Shawcroft, Jose David M.

Implementation Notes

Hardware:

Software and Dependencies:

Notes:

  1. Datasheet: http://www.adafruit.com/datasheets/MCP9808.pdf

class adafruit_mcp9808.MCP9808(i2c_bus: I2C, address: int = 24)[source]

Interface to the MCP9808 temperature sensor.

Parameters:
  • i2c_bus (I2C) – The I2C bus the MCP9808 is connected to.

  • address (int) – The I2C address of the device. Defaults to 0x18

MCP9808 Settings

You could set the MCP9808 with different temperature limits and compare them with the ambient temperature Ta

  • above_critical: this value will be set to True when Ta is above this limit

  • above_upper: this value will be set to True when Ta is above this limit

  • below_lower: this value will be set to True when Ta is below this limit

To get this value, you will need to read the temperature, and then access the attribute

Quickstart: Importing and using the MCP9808

Here is an example of using the MCP9808 class. First you will need to import the libraries to use the sensor

import board
import adafruit_mcp9808

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
mcp = adafruit_mcp9808.MCP9808(i2c_bus)

Now you have access to the change in temperature using the temperature attribute. This temperature is in Celsius.

temperature = mcp.temperature
above_critical

True when the temperature is above the currently set critical temperature. False Otherwise

above_upper

True when the temperature is above the currently set high temperature. False Otherwise

below_lower

True when the temperature is below the currently set lower temperature. False Otherwise

property critical_temperature: float

Critical alarm temperature in Celsius

property lower_temperature: float

Lower alarm temperature in Celsius

property resolution: Literal[0, 1, 2, 3]

Temperature Resolution in Celsius

Value

Resolution

Reading Time

0

0.5°C

30 ms

1

0.25°C

65 ms

2

0.125°C

130 ms

3

0.0625°C

250 ms

property temperature: float

Temperature in Celsius. Read-only.

property upper_temperature: float

Upper alarm temperature in Celsius