I have been able to get the MCP9808 to work in the past but am totally stumped now.
I am using a pi zero with raspbian lite
I install pip3
sudo apt install python3-pip
cd ~
git clone https://github.com/adafruit/Adafruit_Python_MCP9808.git
cd Adafruit_Python_MCP9808
sudo python3 setup.py install
all seems to go well but when I run simplest.py I get this error
Traceback (most recent call last):
File "simpletest.py", line 29, in <module>
import Adafruit_MCP9808.MCP9808 as MCP9808
ImportError: No module named Adafruit_MCP9808.MCP9808
help with getting mcp9808 code to work on pi
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
@JzHarrison,
You can use pip3 to install the library. No need to go to the old github site for the original Python code.
If you use sudo to install with pip3 then be consistent and use sudo python3 to run the example code.
https://learn.adafruit.com/adafruit-mcp ... -2997670-6
You can use pip3 to install the library. No need to go to the old github site for the original Python code.
Code: Select all
sudo pip3 install adafruit-circuitpython-mcp9808
Code: Select all
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_mcp9808
i2c = board.I2C() # uses board.SCL and board.SDA
# To initialise using the default address:
mcp = adafruit_mcp9808.MCP9808(i2c)
# To initialise using a specified address:
# Necessary when, for example, connecting A0 to VDD to make address=0x19
# mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x19)
while True:
tempC = mcp.temperature
tempF = tempC * 9 / 5 + 32
print("Temperature: {} C {} F ".format(tempC, tempF))
time.sleep(2)
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
thank you very much for your prompt reply, unfortunately I am still not having success.
I installed the library as you suggested and made a file called temp.py containing the code you posted.
when I ran it with sudo python3 I got the following error
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register
I am sorry to be a bother.
regards
John
I installed the library as you suggested and made a file called temp.py containing the code you posted.
when I ran it with sudo python3 I got the following error
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register
I am sorry to be a bother.
regards
John
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
Hi John,
A failure, but I think this is still good progress.
There is a line in the provided example:
The i2c address is manually being passed there.
Can you confirm that your MCP9808 is wired up to the Pi and that you are seeing the i2c address for it. I'm curious what the address is that is showing up.
Generally this command will show you what is on the i2c bus:
A failure, but I think this is still good progress.
There is a line in the provided example:
Code: Select all
# mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x19)
Can you confirm that your MCP9808 is wired up to the Pi and that you are seeing the i2c address for it. I'm curious what the address is that is showing up.
Generally this command will show you what is on the i2c bus:
Code: Select all
sudo i2cdetect -y 1
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
thanks for your continued help- much appreciated.
results of the command you gave me are below
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@temptest:~ $
results of the command you gave me are below
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@temptest:~ $
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
Let's focus on the i2cdetect not showing any i2c devices connected.
Two things to confirm here.
1) Did you enable i2c using raspi-config
2) Post a photo of your wiring to the Pi with your MCP9808 so we can confirm all four connections (3v3 / GND / SDA / SDL) have been made.
Two things to confirm here.
1) Did you enable i2c using raspi-config
2) Post a photo of your wiring to the Pi with your MCP9808 so we can confirm all four connections (3v3 / GND / SDA / SDL) have been made.
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
hi - yes I have enabled. i12c
I have a cloned sd card from another pi which has a MCP9808 attached and working so I put that card in the pi and simplest.py is giving me the correct temperature readings so I am sure my wiring is ok - but photo attached as requested
I have a cloned sd card from another pi which has a MCP9808 attached and working so I put that card in the pi and simplest.py is giving me the correct temperature readings so I am sure my wiring is ok - but photo attached as requested
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
when I run sudo i2cdetect -y 1
I get
pi@temptest:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@temptest:~ $
but running the code gives
sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $
I get
pi@temptest:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@temptest:~ $
but running the code gives
sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
That is a good sign that you are seeing the i2c address. Wiring looks good.
It sounds as though simpletest works as well. Maybe it is just an initialization issue with temp.py?
Since this device is at i2c address 0x18 does it make a difference if you manually initialize the mcp9808 in the code:
It sounds as though simpletest works as well. Maybe it is just an initialization issue with temp.py?
Since this device is at i2c address 0x18 does it make a difference if you manually initialize the mcp9808 in the code:
Code: Select all
mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x18)
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
hi
simplest worked on the sd card that I have previously got working. It does not work on the card that I am trying to install on now. I just did that to check the wiring was correct.
I have changed the mcp line to
mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x18)
and get this when running
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $
I notice that their is a difference in my home directory between the card the works and the one I am trying to install to
The one that I am trying to install to has this in the /home/pi/ directory
Bookshelf temp3.py temp.py test1.py
the one that works has in /home/pi/ a directory Adafruit_Python_MCP9808 which has a number of files and sub directories.
simplest worked on the sd card that I have previously got working. It does not work on the card that I am trying to install on now. I just did that to check the wiring was correct.
I have changed the mcp line to
mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x18)
and get this when running
pi@temptest:~ $ sudo python3 temp.py
Traceback (most recent call last):
File "temp.py", line 7, in <module>
import adafruit_mcp9808
File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp9808.py", line 41, in <module>
from adafruit_register.i2c_bits import RWBits
ModuleNotFoundError: No module named 'adafruit_register'
pi@temptest:~ $
I notice that their is a difference in my home directory between the card the works and the one I am trying to install to
The one that I am trying to install to has this in the /home/pi/ directory
Bookshelf temp3.py temp.py test1.py
the one that works has in /home/pi/ a directory Adafruit_Python_MCP9808 which has a number of files and sub directories.
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
So far this does sound like a library difference between the working SD card installation and the non-working. It appears that this was a MCP9808 library issue for the error you are seeing around "No module named 'adafruit_register'. It has been resolved recently, but you need to be on version 3.3.7 or higher.
https://github.com/adafruit/Adafruit_Ci ... /issues/30
https://github.com/adafruit/Adafruit_Ci ... /issues/30
Code: Select all
sudo pip3 install --upgrade adafruit-circuitpython-mcp9808
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
I did the pip3 upgrade
I then ran the python script and got this error
pi@temptest:~ $ python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
import adafruit_mcp9808
ImportError: No module named adafruit_mcp9808
I then ran the python script and got this error
pi@temptest:~ $ python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
import adafruit_mcp9808
ImportError: No module named adafruit_mcp9808
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: help with getting mcp9808 code to work on pi
You will need to be consistent with your python execution. You had been running python3 before the script and in the last instance you ran python (without the '3'). One will cause a failure to find the libraries.
also....
What versions are you running for you circuitpython related pip3 libraries? The pip3 installer can lag behind github releases.
also....
What versions are you running for you circuitpython related pip3 libraries? The pip3 installer can lag behind github releases.
Code: Select all
pip3 list | grep -i ada
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
hi
result using python3 to run the script
pi@temptest:~ $ python3 test.py
Traceback (most recent call last):
File "test.py", line 8, in <module>
i2c = board.I2C() # uses board.SCL and board.SDA
NameError: name 'board' is not defined
running pip3 list | grep -I ada
pi@temptest:~ $ pip3 list | grep -i ada
Adafruit-Blinka 6.10.2
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-mcp9808 3.3.8
adafruit-circuitpython-register 1.9.5
Adafruit-PlatformDetect 3.13.4
Adafruit-PureIO 1.1.9
pi@temptest:~ $
result using python3 to run the script
pi@temptest:~ $ python3 test.py
Traceback (most recent call last):
File "test.py", line 8, in <module>
i2c = board.I2C() # uses board.SCL and board.SDA
NameError: name 'board' is not defined
running pip3 list | grep -I ada
pi@temptest:~ $ pip3 list | grep -i ada
Adafruit-Blinka 6.10.2
adafruit-circuitpython-busdevice 5.0.6
adafruit-circuitpython-mcp9808 3.3.8
adafruit-circuitpython-register 1.9.5
Adafruit-PlatformDetect 3.13.4
Adafruit-PureIO 1.1.9
pi@temptest:~ $
- JzHarrison
- Posts: 14
- Joined: Fri Feb 22, 2019 12:12 pm
Re: help with getting mcp9808 code to work on pi
hi - success, thanks for all your help, I went back through your posts and followed a link from this link you sent me https://learn.adafruit.com/adafruit-mcp ... -2997670-6
that advised me to
sudo pip3 install adafruit-blinka
- sudo pip3 install adafruit-circuitpython-mcp9808
- sudo pip3 install adafruit_circuitpython_register
PYTHON SCRIPT
import board
import busio
import adafruit_mcp9808
i2c = busio.I2C(board.SCL, board.SDA)
mcp = adafruit_mcp9808.MCP9808(i2c)
print('Temperature: {} degrees C'.format(mcp.temperature))
which works perfectly - thanks for sticking with me and being so helpful'
regards
John
that advised me to
sudo pip3 install adafruit-blinka
- sudo pip3 install adafruit-circuitpython-mcp9808
- sudo pip3 install adafruit_circuitpython_register
PYTHON SCRIPT
import board
import busio
import adafruit_mcp9808
i2c = busio.I2C(board.SCL, board.SDA)
mcp = adafruit_mcp9808.MCP9808(i2c)
print('Temperature: {} degrees C'.format(mcp.temperature))
which works perfectly - thanks for sticking with me and being so helpful'
regards
John
Please be positive and constructive with your questions and comments.