0
\$\begingroup\$

I have a MCP9808 temperature sensor and a Raspberry Pi 3B plus. I had great success reading the temperature from this sensor via i2c on an Arduino Uno, but am not able to read the temperature with the Raspberry Pi. There are several libraries available to read the sensor through Python and C, but I get error messages with all of them. Therefore, I'm attempting to use simple command line tools to diagnose the issue.

Datasheet can be found here: http://ww1.microchip.com/downloads/en/DeviceDoc/MCP9808-0.5C-Maximum-Accuracy-Digital-Temperature-Sensor-Data-Sheet-DS20005095B.pdf

I have already enabled i2c on the Pi, and am able to detect the sensor (default address 0x18):

root@raspberrypi:~# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
...etc...

Furthermore, I can probe the registers of the sensor:

root@raspberrypi:~# i2cdump 1 0x18

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: XX 00 00 00 00 80 00 04 03 60 a0 27 00 XX XX XX    X....?.??`?'.XXX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
...etc...

But I can not get individual bytes or words from the sensor:

root@raspberrypi:~# i2cset -y 1 0x18 0x05
Error: Write failed
root@raspberrypi:~# i2cget -y 1 0x18 0x05 w
Error: Read failed
root@raspberrypi:~# i2cget -y 1 0x18 0x05 b
Error: Read failed
root@raspberrypi:~# i2cget -y 1 0x18 0x05 i
Error: Invalid mode!

Nor can I set the config register of the sensor:

root@raspberrypi:~# i2cset -r 1 0x18 0x01 0x0000 w
Error: Write failed

I've read the relevant portions of the datasheet (i think), yet I don't understand why I'm not getting data. If I understand correctly, I don't have to write anything to any registers to prepare the sensor (the power-on defaults render it ready to go).

What am I doing wrong?

\$\endgroup\$
0
\$\begingroup\$

Well, add me to the long list of people who have wiring issues. I had connected the wires to the Pi on pins 1, 3, 5, and 7, but should have been using 9 instead of 7.

The important thing to observe here is that I could successfully i2cdetect the sensor and i2cdump the sensor, but not able to i2cget or i2cset the sensor. Not sure why this is, but the facts speak for themselves.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.