itsmedoofer
Posts: 420
Joined: Wed Sep 25, 2013 8:43 am
Location: Canterbury, Kent, UK
Contact: AOL

i2c-sensor overlay

Mon Mar 13, 2017 1:56 pm

Hi,

I’ve been playing with a few I2C interfacing projects, it would seem that LM75 compatible temperature sensors are quite popular...

Most guides will show you how to read raw data with this sensor but this can be cumbersome...

Having done a bit of reading I see there is a driver for the LM75 already, and there is a generic i2c-sensor overlay, would it be possible to add the LM75 to i2c-sensor ?

Code: Select all

          lm75:   lm75@4f {
				compatible = "lm75";
				reg = <0x4f>;
				status = "okay";
			 };

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Mon Mar 13, 2017 2:21 pm

Yes, of course. I don't have an lm75 to play with - is that fragment tested?

itsmedoofer
Posts: 420
Joined: Wed Sep 25, 2013 8:43 am
Location: Canterbury, Kent, UK
Contact: AOL

Re: i2c-sensor overlay

Mon Mar 13, 2017 4:01 pm

Hi Phil,

Thanks for getting back to me, appreciated.

In a word, no, it’s not confirmed..

This is my first look at overlays, I have put that together as a best guess based on when I’ve found so far... To be honest I was hoping that someone could confirm if I was on the right track or not with the concept and code...

I will have a look at how to compile overlays tonight and see if that works or not..

This is where I got the idea from:-

https://bergzand.net/the-raspberry-pi-a ... -tree.html

Here the guy is de-compiling bcm2835-zero.dts editing and then recompiling, not the best strategy I think, so I thought first to create my own LM75 overlay and then found i2c-sensors and thought that would be the perfect place...

One possible fly in the ointment is that these devices can have an address between 0x48 and 0x4F, would the overlay need to accommodate all these possibilities ?

The other thing I have taken a flyer at is the naming, the original source I found had “lm75@48 {“ where as all the overlays I saw in GIT had the format “lm75: lm75@4f {“ I assumed that latter.....

Once I’ve worked out compilation I’ll get back on here.....

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Mon Mar 13, 2017 4:27 pm

Try this: https://drive.google.com/open?id=0B_P-i ... HdUU1ZvS1k

To use it, add:

Code: Select all

dtoverlay=i2c-sensors,lm75
or

Code: Select all

dtoverlay=i2c-sensors,lm75,lm75addr=0x48
to specify an alternate address (it defaults to 0x4f).

If it works I'll merge the change into the Linux repo.

itsmedoofer
Posts: 420
Joined: Wed Sep 25, 2013 8:43 am
Location: Canterbury, Kent, UK
Contact: AOL

Re: i2c-sensor overlay

Mon Mar 13, 2017 4:42 pm

Hi,

Hey you are a star !!! :)

I'll confirm when I get home :)

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Mon Mar 13, 2017 4:43 pm

By the way, the extra "lm75: " is the label needed by the overrides (DT parameters) mechanism to locate the lm75@4f node. The labels are stripped by the DT compiler and turned into phandles (integers counting up from 1) used to store intra-DT references.

itsmedoofer
Posts: 420
Joined: Wed Sep 25, 2013 8:43 am
Location: Canterbury, Kent, UK
Contact: AOL

Re: i2c-sensor overlay

Mon Mar 13, 2017 7:39 pm

Hi Phil,

Works a treat... One small thing......

Code: Select all

dtoverlay=i2c-sensor,lm75
<-Not sensor(s)

Code: Select all

pi@raspberrypi3:~ $ dmesg|grep lm75
[    6.738872] lm75 1-004f: hwmon0: sensor 'lm75'

Code: Select all

pi@raspberrypi3:~ $ sensors
lm75-i2c-1-4f
Adapter: 3f804000.i2c
temp1:        +20.0°C  (high = +80.0°C, hyst = +75.0°C)
When I get 5 I'll try changing the address of the sensor, but for now all looks splendid.

Thanks for all your help, really appreciated !

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Mon Mar 13, 2017 7:49 pm

You won't be able to use more than one at the moment, or at least you won't be able to use this overlay more than once because there will be name clashes. I'll consider this another prod to get me to make the dtparam mechanism just a bit more powerful, to solve problems like this.

itsmedoofer
Posts: 420
Joined: Wed Sep 25, 2013 8:43 am
Location: Canterbury, Kent, UK
Contact: AOL

Re: i2c-sensor overlay

Tue Mar 14, 2017 9:56 am

Hi Phil,

Not an issue for me at this stage :) Thanks again !!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Tue Mar 14, 2017 10:00 am

I'll be pushing the updated overlay to the kernel repo in a little while, from where it will find its way into future firmware releases.

ed_attfield
Posts: 2
Joined: Mon Sep 10, 2018 8:53 pm

Re: i2c-sensor overlay

Mon Sep 10, 2018 9:06 pm

By reading between the lines in this thread, I got my adafruit BME280 to work on I2C with the drivers that came with Raspbian Stretch. (It looks like Jessie should work, too)

I had to set the I2C address because sudo i2cdetect -y 1 said that my BME280 was at 0x77 instead of the default? 76.

my /boot/config.txt has
dtparam=i2c_arm=on
# dtoverlay to turn on i2c sensor driver and override the address for a bme280
dtoverlay=i2c-sensor,bme280,addr=0x77

and now gives realistic numbers:
cd /sys/bus/i2c/devices/i2c-1/1-0077/iio:device0
cat name
bme280
cat in_temp_input
23350
cat in_pressure_input
101.327527343
cat in_humidityrelative_input
56.271484375

Thanks to everyone in the thread.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3126
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: i2c-sensor overlay

Tue Sep 11, 2018 8:32 am

PhilE wrote:
Mon Mar 13, 2017 7:49 pm
You won't be able to use more than one at the moment, or at least you won't be able to use this overlay more than once because there will be name clashes. I'll consider this another prod to get me to make the dtparam mechanism just a bit more powerful, to solve problems like this.
This is no longer true - the "addr" parameter now has the side effect of changing the name of the node, so this overlay can support multiple BME280s (and the other devices that support the "addr" parameter) simultaneously.

Return to “Device Tree”