Thirsty Endgrain
Posts: 3
Joined: Thu Feb 01, 2024 5:08 am

6 BME280 sensors with rpi 4

Thu Feb 01, 2024 5:30 am

Hi all,
I’m very new to pi and programming, so be easy on me. I’ve read and read, I think I have all the parts, but there are some (many) holes in my understanding that I’d appreciate some help with,

The Project: I’m trying to set up 6 BME280 sensors to read temp/humidity in both a roof and wall assembly, to track moisture migration through said assemblies over the seasons. Due to where these assemblies are my first question is about allowable distance between sensors and pi. I wanted to plan to locate the rpi4 in a utility closet, and it would be about a 20’ run to the farthest sensors embedded in the ceiling. Is that possible? I was planning to use 22g wire, but I have some 18g wire if that would help with the distance. Or is that simply a non-starter and too far away?

The next questions are about connecting that many sensors, would I want to use a breadboard to make those 6 connections over the I2C bus?

From reading it seems that the BME280 uses a default address of either 0x76 or 0x77, but it seems you can configure custom addresses to allow them to share the bus, is that the case? I saw that there was a hardware modification that can be done to change the address

https://raspberrypi.stackexchange.com/q ... erry-pi-3b

but this was only when dealing with 2 sensors. I have yet to read anywhere instructions for connecting 6 sensors. Is a multiplexer necessary, or is there a software way to assign addresses?

I would like to set the whole thing up headless and be able to SSH in and access the data when I wanted, but just have it always taking readings, maybe 3xday. That’s if the project is even feasible, please help me fill in a couple holes here and let me know if I’m even remotely on the right track, thank you.

ullix
Posts: 46
Joined: Thu Sep 15, 2011 3:10 pm

Re: 6 BME280 sensors with rpi 4

Thu Feb 01, 2024 7:57 am

The BME280 is a good and reliable sensor in my experience. But it offers only 2 addresses. Though I haven't tried it myself, I think there are hub-like devices, which allow to extend the address space. Using 6 devices should be possible.

However, 6 meter long wires look to me like too long. Take a look at the I2C specifications to see what they say about wire length. I don't expect that signal-damping is the main problem, which could be partially overcome by thicker wire. The likely problem is the signal distortion due to length.

Speed is not you problem. So I imagine, but don't know, that perhaps the 1-wire technology is less sensitive to signal distortion? But then I don't know whether an I2C-to-1Wire transformer exist, or whether such sensors exist. Given that you need only temp and humid, it seems likely to find such sensors (The BME280 really shines when you also want barometric pressure!).

Edit:
I found this comment: "So the maximum bus length of an I2C link is about 1 meter at 100 Kbaud, or 10 meters at 10 Kbaud." here: http://www.mosaic-industries.com/embedd ... ifications

So, you can use the I2c by reducing the bitrate!

And a multiplexer is e.g. this one: https://www.az-delivery.de/products/tca ... ultiplexer

I find this an interesting question; let us know the outcome!

stevend
Posts: 740
Joined: Fri Oct 11, 2013 12:28 pm

Re: 6 BME280 sensors with rpi 4

Thu Feb 01, 2024 1:31 pm

Personally I wouldn't let I2C out of the box, and I'm not sure how susceptible it would be to interference.
And the BME280 has only two supported addresses (the 'hardware solution' referred to is, I suspect a matter of disconnecting one pin of the BME280 from a supply voltage, and connecting it to the other).
One-wire bus is potentially much more robust - I've got some loops which are 20-30m long which have been working for years. It is also pretty tolerant of randomly wired busses (mixture of star, spur, bus etc).
There's an I2C to OWB device, the DS2484, which does all the heavy lifting of timings etc (it is possible to bit-bash OWB, and the Pi has a driver to do it, but I doubt its as robust as using the purpose-designed interface). I think the Pi also has a driver for the DS2484 (and there may be newer devices since I last looked).
If you should come back to using the BME280, one possible solution is to use an intermediate board, such as a Pico. It has two I2C interfaces, so two of them would handle your 6 devices, and also be spread along the cable run, shortening the I2C bus lengths. Then use serial to talk to the Pi.

danjperron
Posts: 4678
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 6 BME280 sensors with rpi 4

Thu Feb 01, 2024 2:30 pm

I think your project should be split using modules instead of one unit.

2 methods,

1 - Use PicoW or esp32 and send information via wifi to MQTT raspberry's broker.
The Pi could run nodered and collect all the data or simply subscribe to it and read all the data.

2 - Use Pico on a RS-485 bus. Modbus will be a good candidate for that. One cable with 4 wires (GND, POWER, A+ and B- for data).


I know is a little bit more complicated but I'll give two examples

for #1 My garden solar. I do have code for the BME280
https://github.com/danjperron/PicoWSolar

for #2 a small Rs-485 server (Should be esay to add two bme280)
https://github.com/danjperron/rp2040-modbus_example


I.M.O. I will go with #1 because it is cheaper. Just need to power them. But if you don't want wifi then RS-485.

Thirsty Endgrain
Posts: 3
Joined: Thu Feb 01, 2024 5:08 am

Re: 6 BME280 sensors with rpi 4

Thu Feb 01, 2024 3:42 pm

Thank you for all of the suggestions so far. Some of what you are all saying I will have to do research on, as again I’m very new to this. I build houses, so learning to build software and use all these components is new territory to me. Perhaps if I give you a better idea of the project it’ll inform the best path. One thing to note is that I only have a max of 2 weeks before drywall goes up and I will no longer be able to run wires and embed any sensors, so even if I don’t fully understand the programming side of things I will at least need to get the hardware buried. I realize this is not ideal since I may not be able to test the whole system in case there’s a bad connection, hardware issue, or wiring fault, but it’s just kinda how it is.
IMG_0082.png
IMG_0082.png (110.4 KiB) Viewed 635 times
In my middle school scribble you can see the rough locations of the six sensors.
stevend wrote: Personally I wouldn't let I2C out of the box, and I'm not sure how susceptible it would be to interference.
And the BME280 has only two supported addresses (the 'hardware solution' referred to is, I suspect a matter of disconnecting one pin of the BME280 from a supply voltage, and connecting it to the other).
One-wire bus is potentially much more robust - I've got some loops which are 20-30m long which have been working for years. It is also pretty tolerant of randomly wired busses (mixture of star, spur, bus etc).
There's an I2C to OWB device, the DS2484, which does all the heavy lifting of timings etc (it is possible to bit-bash OWB, and the Pi has a driver to do it, but I doubt its as robust as using the purpose-designed interface). I think the Pi also has a driver for the DS2484 (and there may be newer devices since I last looked).
If you should come back to using the BME280, one possible solution is to use an intermediate board, such as a Pico. It has two I2C interfaces, so two of them would handle your 6 devices, and also be spread along the cable run, shortening the I2C bus lengths. Then use serial to talk to the Pi.
I looked into 1 wire sensors (until now I didn’t know what 1 wire was). All I could find was this, but at $70 a pop I can’t stomach almost $500 in sensors for this project.

https://www.paralanstore.net/teracom-sy ... r-tsh202v3

So if there is a way I’d like to use the BME’s. Perhaps it’s through the use of PICO’s like suggested?
danjperron wrote: I think your project should be split using modules instead of one unit.

2 methods,

1 - Use PicoW or esp32 and send information via wifi to MQTT raspberry's broker.
The Pi could run nodered and collect all the data or simply subscribe to it and read all the data.

2 - Use Pico on a RS-485 bus. Modbus will be a good candidate for that. One cable with 4 wires (GND, POWER, A+ and B- for data).


I know is a little bit more complicated but I'll give two examples

for #1 My garden solar. I do have code for the BME280
https://github.com/danjperron/PicoWSolar

for #2 a small Rs-485 server (Should be esay to add two bme280)
https://github.com/danjperron/rp2040-modbus_example


I.M.O. I will go with #1 because it is cheaper. Just need to power them. But if you don't want wifi then RS-485.
I wouldn’t want wifi in this case due to the fact that this will be a client’s house, so I want everything hardwired. I will have to have the pi connected to wifi to gather data, but I’d like to keep it to that. So given the 3 locations of the pairs of sensors, does that help inform how this might be designed. Thanks again everyone, your help is much appreciated!

ghp
Posts: 3668
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: 6 BME280 sensors with rpi 4

Thu Feb 01, 2024 5:46 pm

Considering delivery time of components it will be almost impossible to setup this project in two weeks. When you build it yourself and you do not have the necessary software/electronics experience AND you want it in two weeks then plan it for next project.

If you still want to realize this project, then buy industrial grade modbus sensors (buy somewhere where full documentation is available !) And do a test run before you build the sensors into the wall.

Just what I found with a short search:
https://www.antratek.de/temperature-and ... dbus-rs485
https://www.turck.de/en/product/3025898

ullix
Posts: 46
Joined: Thu Sep 15, 2011 3:10 pm

Re: 6 BME280 sensors with rpi 4

Fri Feb 02, 2024 9:34 am

Setting this up will very likely take much longer than you have time. Install at least the cables. Regular Ethernet cable should do the job.

The sensors will not last forever, so you need to have access to them anyway. Cheap BME280 and a multiplexer will do the job.

Thirsty Endgrain
Posts: 3
Joined: Thu Feb 01, 2024 5:08 am

Re: 6 BME280 sensors with rpi 4

Sun Feb 04, 2024 12:50 am

Is it feasible to use I2C range extenders? Connect each bme280 to an Adafruit LTC4311 I2C Extender, then run ethernet cable to a multiplexer, that is then connected to the pi?

extender:
https://www.adafruit.com/product/4756

multiplexer:
https://www.adafruit.com/product/2717

Have been consulting with a friend who is fluent in electronics, this was one of his suggestions. Any reason why extenders would not be a good idea, and is CAT5 cable a good way to make those runs?

danjperron
Posts: 4678
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 6 BME280 sensors with rpi 4

Sun Feb 04, 2024 4:54 am

it took me one hour to add BM280 on my RS-485 Pico demo and another hour to debug.

they are connected to GPIO10 and GPIO11 on I2C.
It is also possible to add two others using GPIO 12 & 13.

Now you could set the sensors far away.

I will update the doc tomorrow on my github.
https://github.com/danjperron/rp2040-modbus_example

I also add a small python script using minimalmodbus to show how to read the sensors.

Quite simple. I just add the register to 2200 . each sensor needs 32 bits per measurement of temperature, humidity and pressure.
Temperature and pressure value need to be divide by 100 and the humidity by 1024.

and the result

Code: Select all

daniel@benchpi4:~/rp2040-modbus_example $ python readBME280.py 
probe1
 Temperature: 17.49˚C
 Humidity   : 37.52%
 Pressure   : 1016.50hPa
probe2
 Temperature: 17.52˚C
 Humidity   : 35.52%
 Pressure   : 1016.07hPa

probe1
 Temperature: 17.48˚C
 Humidity   : 37.47%
 Pressure   : 1016.50hPa
probe2
 Temperature: 17.52˚C
 Humidity   : 35.51%
 
*** 4 February 2024.
Update add Sensor validity. address are now offset by one.
address 2200 indicates sensors validity. Check readBME280.py

ghp
Posts: 3668
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: 6 BME280 sensors with rpi 4

Sun Feb 04, 2024 6:15 pm

This looks promising. I'd propose to setup a prototype: RPI, Multiplexer, LTC4311, long ethernet wire, sensor.

For the LTC4311. there are remarks on the adafruit site:
Adafruit: connect it to your I2C bus at the beginning of the chain
and
Adafruit: With a 100KHz signal, we even ran a BME680 over 100 feet of Ethernet
Remark: A system based on RS485 for transport is for sure a 'state of the art' solution. But this needs intelligent sensors, which you can develop/build/test/deploy yourself (with e.g. a raspberry pico and an RS485 to serial adapter and the sensors needed ) or buy ready to use.

danjperron
Posts: 4678
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 6 BME280 sensors with rpi 4

Sun Feb 11, 2024 9:24 pm

Remark: A system based on RS485 for transport is for sure a 'state of the art' solution. But this needs intelligent sensors, which you can develop/build/test/deploy yourself (with e.g. a raspberry pico and an RS485 to serial adapter and the sensors needed ) or buy ready to use.
This is what I did. Works well and it is simple.
PicoModbus2.jpg
PicoModbus2.jpg (49.47 KiB) Viewed 143 times
https://github.com/danjperron/rp2040-modbus_example

I also add a small script to log the data on to a text file. Just add it on crontab.

Code: Select all

daniel@benchpi4:~/sensor_log $ tail log_2024_02_11.txt 
02/11/24 16:20:01	18.26	42.63671875	1009.05	17.9	41.2646484375	1008.47	18.78		1010.1	17.44	43.7294921875	1008.77	
02/11/24 16:21:01	18.19	42.6845703125	1009.13	17.88	41.2177734375	1008.52	18.76		1010.13	17.44	43.6796875	1008.85	
02/11/24 16:22:01	18.2	42.6318359375	1009.09	17.87	41.25	1008.55	18.75		1010.13	17.41	43.677734375	1008.88	
02/11/24 16:23:01	18.16	42.572265625	1009.09	17.86	41.2041015625	1008.52	18.73		1010.16	17.42	43.6181640625	1008.82	

Return to “Automation, sensing and robotics”