Homepage Wiki Forum Buy

LM75

From GNUBLIN

severity (level) requirement Gnublin family
Gnublin logo advanced.png Kernel compile, Toolchain All


Contents


In order to messure temperature the LM75 is aquiet common chip. It is driven on an I2C bus which gives the oportunity to use up to 8 chips on one bus.

Quickstart with Gnublin Distribution

This article explains, how to measure the temperature with LM75 temperature sensors. The sensors are using the I2C interface. The I2C address of each sensor depends on the level of pin 5-7 (VCC or GND).

MODULE-TEMPSENSOR SCHRAEGBILD 001.jpg

For a quickstart with the module you should plug all wires to the outer side:

Attention: the Gnublin connector cable has a red wire. This wire must be on GPA0/GPA1 on the Gnublin board!!

Then you can start reading out the temperature with the following command:

gnublin-lm75

You get the actual temperature in ° Celsius as output:

21 °C

With RaspberryPi:

pi@raspberrypi ~ $ sudo gnublin-lm75

You can also get JSON compatible output:

gnublin-lm75 -j

Then the output looks like this

{"temperature":"21","result":"0"}

If you only use one I2C module from the shop, you must plug both jumpers beside the Gnublin connector (2x7 pole). This jumpers are the pullups for SDA and SCL line for I2C. If you got more than one I2C module it's enough to plug the jumpers on one module

For Beginners

(Only by use of the LM75 temperatur modul of the embedded-projects shop:)

If you only use one I2C module from the shop, you must plug both jumpers beside the Gnublin connector (2x7 pole). This jumpers are the pullups for SDA and SCL line for I2C. If you got more than one I2C module it's enough to plug the jumpers on one module

In the newest Gnublin_Distribution all drivers compiled as build-in to the kernel and the used i2c-tools are also preinstalled. You just have to set the I2C Address on the module. Therefor are three jumpers on the module. Hereafter the I"C Addresses are listed in reference to the jumper position.

JP1 JP2 JP3 I2C-Address
LOW LOW LOW 0x48
HIGH LOW LOW 0x49
LOW HIGH LOW 0x4A
HIGH HIGH LOW 0x4B
LOW LOW HIGH 0x4C
HIGH LOW HIGH 0x4D
LOW HIGH HIGH 0x4E
HIGH HIGH HIGH 0x4F

In order to easely read the temperature of the sensor we wrote a wrapper skript:

gnublin-lm75 -a <address>

If you wnat to read the temperature of a sensor just type:

gnublin-lm75 -a 0x48

Now you should recive the value in m°C (Milligrad Celsius).

For Advanced Users

LM75.jpg

The first step is to connect SCL, SDA, GND and VCC pins of the sensor with the same pins on the GNUBLIN. (Dont forget to set the I2C-address). Please note, that I2C needs pullup resistors, that means you must connect SDA and SCL over 4.7kOhm resistors to VCC.

Here you can see how to wire up the I2C-BUS.

And here you can see the pins of the LM75 Sensors.

LM75 pins en.jpeg

If you want to connect more than one LM75 sensors with the I2C-BUS, you must connect the pins A0, A1 and A2 of each sensor different with VCC and GND. The following table shows you how to connect four LM75 sensors with the I2C-BUS and how to wire up the addresspins:

Sensornr. A0 A1 A2 I2C-Address
1 VCC GND GND 0x49
2 GND VCC GND 0x4A
3 GND GND VCC 0x4C
4 VCC VCC GND 0x4B


Kernel modules

Kernel options you have to set:

Device Drivers -> I2C Support -> I2C Hardware Bus Support -> I2C Bus support for Philips PNX targets
Hardware Monitoring Support -> National Semic. LM75 and compatibles

Compile the kernel and the modules and copy the zImage and the modules to the SD-card. (for detailed instructions look at Kernel compile + Module installation)

Boot the Gnublin.

Measure the temperature

loading the module:

modprobe i2c-pnx
modprobe lm75

The output of the command above looks like the following if you have connected four LM75 sensors.

pca9532 0-0060: setting platform data i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2200, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... i2c i2c-0: Master timed out. stat = 2a00, ctrl = 0007, state = 1. Resetting master... lm75 1-0049: hwmon0: sensor 'lm75' lm75 1-004a: hwmon1: sensor 'lm75' lm75 1-004b: hwmon2: sensor 'lm75' lm75 1-004c: hwmon3: sensor 'lm75'

The module creates the following hierarchy in the directory /sys/class/hwmon:

|-- hwmon
|   |-- hwmon0 -> ../../devices/platform/pnx-i2c.1/i2c-1/1-0049/hwmon/hwmon0
|   |-- hwmon1 -> ../../devices/platform/pnx-i2c.1/i2c-1/1-004a/hwmon/hwmon1
|   |-- hwmon2 -> ../../devices/platform/pnx-i2c.1/i2c-1/1-004b/hwmon/hwmon2
|   `-- hwmon3 -> ../../devices/platform/pnx-i2c.1/i2c-1/1-004c/hwmon/hwmon3

You can see, that there were created four new "devices" by the module, each "device" is corresponding to one of our four LM75 sensors. Now you can change into the directory /sys/class/hwmon/hwmon0/device for example and yo will find a file named temp1_input. To measure the temperature you just have to cat this file:

cat /sys/class/hwmon/hwmon0/device/temp1_input

You will only get the measured temperature in ° Celsius as an output.

This is how an example output looks like:

root@gnublin-debian:~# cat /sys/class/hwmon/hwmon0/device/temp1_input 23000

Read the temperature with the I2C-Tools

With the following command we check the address of the sensor:

i2cdetect 1

This returns following output (after a short request):

 WARNING! This program can confuse your I2C bus, cause data loss and worse!
 I will probe file /dev/i2c-1.
 I will probe address range 0x03-0x77.
 Continue? [Y/n] y
      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
 00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 40: -- -- -- -- -- -- -- -- -- 49 4a 4b 4c -- -- -- 
 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6e -- 
 70: -- -- -- -- -- -- -- --     

We see the four connected sensors which are found under the addresses 49, 4a 4b and 4c Note: The address 6e is the adress from GNUBLIN it self.

If the execution of i2cdetect 1 returns the error message Error: Could not open file `/dev/i2c-1': No such device you have to loadt the i2c-pnx-driver:

modeprobe i2c-pnx

Now we can request the acutal temperature:

i2cget -y 1 0x49

This request returns for example this value:

0x18

The output value is hexadecimal.

The -y in the command just disable the request if GNUBLIN realy should do this.

The syntx is constructed as yiu can see here:

i2get -y I2CDEVICE SLVE-ADDRESS

For I2CDEVICE we use the 1 and for the SLAVE-ADDRESS the adddress we have identified in the privious step.

In other languages