Page 1 of 1

Interfacing mcp9808 temperature sensor

Posted: Mon Sep 13, 2021 7:14 am
by Zacks
I am trying to interface the MCP9808 temperature sensor with OpenMV Cam, and I found this library from here https://github.com/kfricke/micropython-mcp9808 However there was no example code on how to use the library to read the temperature. This maybe simple but since I am still new to miccropython it may take time to try to figure it out. Help from anyone who may have used used this before or can help with an example on how to use the library to read temperature will be much appreciated

Re: Interfacing mcp9808 temperature sensor

Posted: Mon Sep 20, 2021 12:09 pm
by mcauser
Firstly you need to download mcp9808.py and copy to your device.
Next connect the sensor to your I2C pins.
Then a simple example would be:

Code: Select all

from machine import Pin, I2C
import mcp9808

# adjust pins and frequency to suit your device
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)

# create an instance of the sensor, giving it a reference to the I2C bus
mcp = mcp9808.MCP9808(i2c)

# get the temperature (float)
temp_celsius = mcp.get_temp()
print(temp_celsius)