Solved Bosch Sensortec BME280 - IIC

serjsk8

Active Member

Reaction score: 6
Messages: 136

Hello,
I have old Raspberry Pi 2 v1.1 and FreeBSD 12.2 - RELEASE installed on it.
Code:
# uname -a
12.2-RELEASE FreeBSD 12.2-RELEASE r366954 GENERIC  arm

And I wanted to do some tests with a BME280 temperature sensor connected to I2C.

OS has detected sensor at address 0x76
Code:
# i2c -sv
dev: /dev/iic0, addr: 0x0, r/w: r, offset: 0x00, width: 8, count: 1
Hardware may not support START/STOP scanning; trying less-reliable read method.
Scanning I2C devices on /dev/iic0: 76

I founded BME280 driver from Bosch:

I have compiled it successfully:
Code:
# make bsd
cc bsd_userspace.c ../bme280.c -I ../ -o bme280

But at the time of executing it gives me an error:
Code:
# ./bme280 /dev/iic0 
Failed to initialize the device (code -2).

I also understand that Python smbus module is not available in FreeBSD, right?

Has anyone had experience with the sensor BME280 or with I2C?

Best regards,
 

mark_j

Daemon

Reaction score: 681
Messages: 1,192

Some of those sensors are Chinese knock-offs which actually use a different address and are in reality bmp280s. Perhaps this is the case.
The error you're encountering is BME280_E_DEV_NOT_FOUND which is triggered if it can't find the correct id for the chip.
Obviously you've checked the device is in the /dev tree?
I can't recall the alternate address - either 0x77 or 0x78.
 
OP
serjsk8

serjsk8

Active Member

Reaction score: 6
Messages: 136

Hello mark_j,
This is case.
Yesterday I found that my sensor has ID 0x58
BME280 - have ID 0x60
BMP280 - have ID 0x57 or 0x58
My sensor is BME280 but from AliExpress and have ID 0x58.

In the C code of BME280 driver from Bosch I changed constant BME280_CHIP_ID = 0x60 to BME280_CHIP_ID = 0x58 and my sensor started to work.

# ./bme280 /dev/iic0
CHIP ID: 58
Temperature, Pressure, Humidity
27.84 deg C, 944.18 hPa, 0.00%
27.84 deg C, 944.17 hPa, 0.00%
27.84 deg C, 944.17 hPa, 0.00%
27.84 deg C, 944.17 hPa, 0.00%
27.84 deg C, 944.17 hPa, 0.00%
27.84 deg C, 944.17 hPa, 0.00%
27.84 deg C, 944.16 hPa, 0.00%


The only thing that the temperature is not correct.
At the moment I do not know if it is a sensor failure or I have to adapt the C code.
 

mark_j

Daemon

Reaction score: 681
Messages: 1,192

Most likely. I don't have time to look at the code at present (it's late night here) but perhaps take a look at this Code. It deals with the Arduino but it also uses i2c. You could also look-up Adafruit's library for BMP280s. Sorry I couldn't help more at the moment.
 
OP
serjsk8

serjsk8

Active Member

Reaction score: 6
Messages: 136

I do a little summary, maybe someone will find it useful.
BME280 - have ID 0x60
BMP280 - have ID 0x57 or 0x58
My sensor look like in the attached pic, and seller said it is BME280.
But ID of my sensor is 0x58. And I think mark_j had the same experience.
In the C code of BoschBME280_driver I changed constant BME280_CHIP_ID = 0x60 to BME280_CHIP_ID = 0x58 in file bme280_defs.h
And examples on C code have started to work.
 

Attachments

  • BMP280-Module-Image.png
    BMP280-Module-Image.png
    111.7 KB · Views: 12
Top