itsmedoofer
Posts: 359
Joined: Wed Sep 25, 2013 8:43 am

LM75 Temp Sensor Help

Sun Mar 12, 2017 1:22 pm

Hi,

I have a LM75 compatible (a MCP9801) temperature sensor connected to my Pi...

My intention is to use this sensor as a "case" temperature monitor for the pi and display the temp in the panel bar

I have successfully setup I2C and can read raw data from the sensor..

Code: Select all

i2cget -y 1 0x4f 0x00 w |awk '{printf("%0.1f C\n",(a=((("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) )>128?a-256:a)}'
I've had a play with lm-sensors but the sensor is not seen when I run the detect script....

What I think I need to do is make it available as a device... I see the the kernel has a LM75 driver, but how do I get the driver to see the sensor ?

Do I need an overlay to tell the driver where the sensor is on the I2C bus if so how can I go about it...

Thanks in advance...

itsmedoofer
Posts: 359
Joined: Wed Sep 25, 2013 8:43 am

Re: LM75 Temp Sensor Help

Tue Mar 14, 2017 10:14 am

Hi,

I've done a bit of work and got a working LM75 setup with a driver that can be used to display the sensor temp on the panel bar at the top of Pixel....

This is a I2C sensor so you will need to enable I2C in raspi-config if not already done so, you will also need i2c-tools to test..

Code: Select all

sudo apt-get i2c-tools
There are plenty of guides detailing I2C setup so I wont go into this any further....

With I2C setup you can verify that the sensor is connected and working by reading the raw data from it using the following....

Code: Select all

i2cget -y 1 0x4f 0x00 w |awk '{printf("%0.1f C\n",(a=((("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) )>128?a-256:a)}'
LM75 compatible devices already have a kernel driver in Rasbain, so to make the sensor a device all we have to do is enable it using an overlay...

Until the overlay is made available in the distribution you can download it from here:-

viewtopic.php?p=1129909#p1129909

This needs to be copied into /boot/overlays backing up the original one first..

The instructions in that post are slightly wrong the following needs to be added to /boot/config.txt

Code: Select all

dtoverlay=i2c-sensor,lm75
After a reboot you can check things are loaded correctly by:-

Code: Select all

dmesg|grep lm75
You should see something like this if everything is working correctly...

[ 6.738872] lm75 1-004f: hwmon0: sensor 'lm75'

I wanted to use the sensor as a case monitor for my Pi and have the temperature displayed on the panel bar at the top of Pixel.....

Firstly the lm-sensors package is required

Code: Select all

sudo apt-get install lm-sensors
And then configure it for use:-

Code: Select all

sudo sensors-detect
Say YES (enter) to all the questions, until....

Do you want to add these lines automatically to /etc/modules? (yes/NO) , you will need to type Y here unless you want to make the modifications yourself..

Reboot and check everything is setup correctly by typing sensors, if everything is working correctly you should see

Code: Select all

sensors
lm75-i2c-1-4f
Adapter: 3f804000.i2c
temp1: +18.5°C (high = +80.0°C, hyst = +75.0°C)

To display the sensors temperature in the top panel of Rasbian you will need to compile a small applet for LXPanel..

Download and unpack the source code from here:-

http://danamlund.dk/sensors_lxpanel_plugin/

The packages required to compile on the raspberry are slightly different from what is shown in the instructions on the page..

Code: Select all

sudo apt-get install libglib2.0-dev libgtk2.0-dev libmenu-cache-dev libsensors4-dev
Once these are installed change directory to where you extracted the source and type..

Code: Select all

make
sudo make install
Compilation will take seconds...

After a reboot there will be an additional applet available in Panel Settings -> Panel Aplets -> Add -> “lm-sensors Monitor” This will display the sensor temp in the panel bar at the top of Pixel.....

For a clean up you can remove the source directory and the development packages...

Code: Select all

sudo apt-get remove libglib2.0-dev libgtk2.0-dev libmenu-cache-dev libsensors4-dev
sudo apt-get autoremove
I appreciate this is not a complete guide but intermediate users should find it useful...

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: LM75 Temp Sensor Help

Tue Mar 14, 2017 11:17 am

Thanks for that!

The PaPiRus HATs include an LM75, so this is useful to owners of those boards.

Return to “Automation, sensing and robotics”