Simple test
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6import adafruit_mcp9808
7
8i2c = board.I2C() # uses board.SCL and board.SDA
9# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
10
11# To initialise using the default address:
12mcp = adafruit_mcp9808.MCP9808(i2c)
13
14# To initialise using a specified address:
15# Necessary when, for example, connecting A0 to VDD to make address=0x19
16# mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x19)
17
18while True:
19 tempC = mcp.temperature
20 tempF = tempC * 9 / 5 + 32
21 print("Temperature: {} C {} F ".format(tempC, tempF))
22 time.sleep(2)
Temperature Limit test
Show the MCP9808 to setup different temperature values
1# SPDX-FileCopyrightText: 2021 Jose David M.
2# SPDX-License-Identifier: MIT
3
4"""
5Show the MCP9808 to setup different temperature values
6"""
7
8import time
9import board
10import adafruit_mcp9808
11
12i2c = board.I2C() # uses board.SCL and board.SDA
13# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
14mcp = adafruit_mcp9808.MCP9808(i2c)
15
16# Change the values according to the desired values
17print("Setting Temperature Limits")
18mcp.upper_temperature = 23
19mcp.lower_temperature = 10
20mcp.critical_temperature = 100
21
22# To verify the limits we need to read the temperature value
23print(mcp.temperature)
24time.sleep(0.3) # This is the time temperature conversion at maximum resolution
25
26# Showing temperature Limits
27while True:
28 if mcp.below_lt:
29 print("too cold!")
30 if mcp.above_ut:
31 print("getting hot!")
32 if mcp.above_ct:
33 print("Above critical temp!")