Add a MCP9808 Temperature Sensor to the Pi
Power down your Pi before you connect something onto the GPIO pins!
Install i2c-tools
To see the I²C address matrix:
$ sudo apt-get install i2c-tools -y
Check sensor address
Type into the cli:
$ sudo i2cdetect -y 1
There should be a HEX number into the matrix. Default is 0x18, but if you used another address it should be between 0x18 - 0x1F.
Install the CircuitPython MCP9808 Library
Check if the library does exist on
pypi.org with the search command
CircuitPython mcp9808
Once you know the name, install it with:
$ pip3 install adafruit-circuitpython-mcp9808
Run that code!
The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.
Check out the examples for your library by visiting the repository for the library and looking in the example folder.
In this case, it would be
https://github.com/adafruit/Adafruit_CircuitPython_MCP9808/tree/master/examples
Save this code to your Pi by copying and pasting it into a text file, downloading it directly from the Pi, etc.
Then in your command line run:
$ python3 mcp9808_simpletest.py
If the code is stuck into a loop, you can get out of this with: Ctrl c
Different addresses with Adafruit Circuitpython Library
Code for default address (0x18) is:
mcp = adafruit_mcp9808.MCP9808(i2c_bus)
For all other seven addresses you should use the following code:
Addresses should be in decimal! So you have to convert the HEX addresses to decimal: 0x18 = 24, 0x19 = 25 etc.
(See list on
Sensor page)
mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=25)
Python
External addresses to Adafruit:
Python & CircuitPython
Python Docs (Adafruit MCP9808 Python Library)