Setting up BME280

I am now trying to set up the BBB, running latest image of Debian XFCE, to accept Temp/H/P sensor BME280 on i2c2 (i2c0 is being used by Ext. Real Clock)
As I have so far learned, overlays are needed. I am still pretty confused about overlay usage, but will continue researching.
For the BME280 I found the following overlay .dts: BB-I2C2-BME280.dts
In order to get it installed into BBB, would I use the following:
n /boot/uEnv.txt add:

uboot_overlay_addr4=BB-I2C2-BME280.dtbo

Or, does addr4 need to be changed to some other address (but I would not know how to select another addr)
And, would I now use pins 19 and 20?

Why not use the already configured i2c bus that the rtc.module uses ?
The only reason you might not be able to do that is if both devices use the same addresses.

I2C devices either have some pins to configure alternative addresses or they can be fixed

In order to use the RealTimeClock, nothing worked until CNelson instructed me on the overlay. Would this now be different for the BME280?
I’d rather be safe than sorry. Plus, is there a reason not to use the i2c2?

Addendum: Benedict.hewson: You are absolutely correct it seems!
I powered down BBB, attached BME280 to same pins as DC3132 and I believe both are working.
Will do a little more checking on BME with python to see if it reads out, but i2cdetect is showing 76!
TY!!!

Depends. If there is a kernel driver for the device you would need to modify the overlay to include it.

However if you just want to read/ write the device with your own code then it should just work.

Now confused again:
I definitely am not capable of writing an overlay or driver, is that what you mean?
I am currently writing a little python3 script to access the sensors data, that should work?

Yes that is what I meant. Python is pretty simple to use with I2C devices

Great :slight_smile: TY

Not working so easily - guess I need more brain cells!
the python3 code I wrote for the RPi imports a BME280.py script (which was written specifically for the RPI) and includes a ā€˜import smbus’ line.
smbus is probably not used by BBB as it throws an error.
The smbus is used to designate which bus is being utilized (in my bbb, it is bus 1)
what would be the correct code to give it the correct bus?

Or, if it is needed to install the overlay, would my above decription be correct:
For the BME280 I found the following overlay .dts: BB-I2C2-BME280.dts
In order to get it installed into BBB, would I use the following:
n /boot/uEnv.txt add:

uboot_overlay_addr4=BB-I2C2-BME280.dtbo

Or, does addr4 need to be changed to some other address (but I would not know how to select another addr)
And, would I now use pins 19 and 20?

Try installing smbus2
Probably and apt package if you Google for it

I will try it!

You are absolutely correct again!
I have readings from the BME280 in tandem with the ext clock working!
Great! TY

Here’s an example using the bm280 with Golang on the QWIIC bus that I have working on a new Beagle Play.

TY Josh,
the BME280 has been working as I mentioned last, but will read through your GitHub!
Rainer

Just thought I would add to this post. I got one of these BME280 Temperature-Humidity-Barometer sensors that communicates via i2c.
https://www.seeedstudio.com/Grove-BME280-Environmental-Sensor-Temperature-Humidity-Barometer.html

I also got a new BeagleBone Green

with the built in on-board Grove connectors so I don’t have to mess around with the pins and pin wires, Just plug it in, pretty nice!

I booted the new kernel 6.18.25-bone30 image on the SD card and plugged in the BME280.

sudo i2cdetect -r -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --                         

There it is at address 76.

I saw that the kernel has a built in driver for BMP280 (Temp and Press only) but I have the BME280 with humidity. So I abandoned the idea of using the kernel driver.

Here is a c program to read the BME280. Hope this is useful to someone.
bme280read.c (6.4 KB)

Humidity on the BME280 is supported with the ā€œBMP280ā€ kernel driver: bosch,bme280 Making sure you're not a bot!

Regards,

1 Like

Great! So two options to use the BME280.

Using the kernel driver is shown below,

ls /sys/bus/iio/devices/
iio:device0

sudo modprobe bmp280

lsmod |grep bmp
bmp280_i2c             12288  0
bmp280                 49152  1 bmp280_i2c
industrialio_triggered_buffer    12288  1 bmp280
industrialio           90112  4 bmp280,ti_am335x_adc,industrialio_triggered_buffer,kfifo_buf

sudo echo bme280 0x76 | sudo tee /sys/bus/i2c/devices/i2c-2/new_device
bme280 0x76

ls /sys/bus/iio/devices/
iio:device0  iio:device1

ls /sys/bus/iio/devices/iio:device1
buffer                                  in_pressure_scale
buffer0                                 in_temp_input
current_timestamp_clock                 in_temp_oversampling_ratio
dev                                     in_temp_raw
in_humidityrelative_input               in_temp_scale
in_humidityrelative_oversampling_ratio  name
in_humidityrelative_raw                 power
in_humidityrelative_scale               scan_elements
in_pressure_input                       subsystem
in_pressure_oversampling_ratio          trigger
in_pressure_raw                         uevent


device1 shows up.

write a script getdata.sc

#!/bin/bash

DEVICE=/sys/bus/iio/devices/iio:device1

TEMP_RAW=$(cat $DEVICE/in_temp_input)
PRESS_RAW=$(cat $DEVICE/in_pressure_input)
HUM_RAW=$(cat $DEVICE/in_humidityrelative_input)

# Convert to human-readable units
TEMP_C=$(awk "BEGIN {printf \"%.2f\", $TEMP_RAW / 1000}")      # millidegrees → °C
TEMP_F=$(awk "BEGIN {printf \"%.2f\", $TEMP_C * 9/5 + 32}")   # °C → °F

PRESS_Pa=$(awk "BEGIN {printf \"%.2f\", $PRESS_RAW * 1000.0}")          # already Pa
PRESS_inHg=$(awk "BEGIN {printf \"%.2f\", $PRESS_Pa * 0.0002953}") # Pa → inHg

HUM=$(awk "BEGIN {printf \"%.2f\", $HUM_RAW / 1024}")          # 1/1024 %RH

echo "Temperature: $TEMP_C °C / $TEMP_F °F"
echo "Pressure: $PRESS_Pa Pa / $PRESS_inHg inHg"
echo "Humidity: $HUM %RH"

exit 0

output

./getdata.sc
Temperature: 21.25 °C / 70.25 °F
Pressure: 98946.00 Pa / 29.22 inHg
Humidity: 29.63 %RH

Very nice! Thanks Robert.