1

I have a BMP280 (GYBMP280 datasheet) connected to a Raspberry Pi 3 using the IC2 interface (address 0x76). The GYBMP280 is connected to the 3.3V (Pin 1).

The Pressure readings seem to be fine - it fluctuates ever so slightly as expected.

However, the Temperature reading is always [255,255,0] = 0x000FFFF0. I confirmed with an infrared thermometer that my sensor has a reasonable temperature (about 70F) which is well within the detection range.

I have distilled down the libraries I plan to use into a brief test program that just initializes the GYBMP280 and reads the appropriate registers, see below.

Page 24 of the Bosch Data Sheet shows the memory map.

Am I doing something wrong or is the module defect?

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# BMP280 address, 0x76(118)
# Select Control measurement register, 0xF4(244)
# 0x27(39) Normal mode, Pressure and Temperature Oversampling rate = 1
bus.write_byte_data(0x76, 0xF4, 0x27) # 0b11 + (0b001 << 2) + (0b001 << 5)


# BMP280 address, 0x76(118)
# Select Configuration register, 0xF5(245)
# 0xA0(00) Stand_by time = 1000 ms
bus.write_byte_data(0x76, 0xF5, 0xA0)
time.sleep(0.5)

# BMP280 address, 0x76(118)
# Read data back from 0xF7(247), 8 bytes
# Pressure MSB, Pressure LSB, Pressure xLSB, Temperature MSB, Temperature LSB Temperature xLSB
data = bus.read_i2c_block_data(0x76, 0xF7, 6)
print(data) # OUTPUT: [102, 217,0, 255, 255,0], Press: [102,217,0] Temp: [255,255,0]

# Extract Pressure and Temperature
adc_p = (data[0]<<16 | data[1]<<8 | data[2]) >> 4
adc_t = (data[3]<<16 | data[4]<<8 | data[5]) >> 4
print("press=0x{0:08X}".format(adc_p)) #press = 0x00066D90
print("temp= 0x{0:08X}".format(adc_t)) #temp  = 0x000FFFF0
0andriy
  • 4,183
  • 1
  • 24
  • 37
Stefan
  • 21
  • 2
  • The value must be adjusted using the calibration formula, but if the register value is always exactly the same, this either means you made an error enabling the measurement or the sensor is in fact broken. – PMF Jan 07 '22 at 19:57
  • Thanks PMF! According to the data sheet (Bosch link above, page 25), the temp measurement is set via register 0xF4, bits 5-7. 0b001 means "oversampling x 1". That is what I have done (at least I think so). Can someone if I made an error enabling the Temp measurement? (Note: When I set those bits to 0b000, I correctly receive the "reset state" 0x800000 for adc_t). – Stefan Jan 07 '22 at 20:21
  • I suggest you try one of the existing example projects first. – PMF Jan 07 '22 at 20:21
  • In fact, that's what I did first. And when I did not get a valid Temp reading (and as a consequence a garbage compensated Pressure reading) I traced it down to the problem described above. O well. – Stefan Jan 07 '22 at 22:37
  • That would be a strong indication that this time, it's really the sensor that's broken, not your code. – PMF Jan 08 '22 at 08:19
  • Why are you not using in-kernel driver for it? _drivers/iio/pressure/bmp280-*.c_ – 0andriy Jan 11 '22 at 20:16
  • SOLVED: The sensor itself was defect. I bought a new PCB, connected it and it works like a charm. THANKS for all the suggestions. – Stefan Jan 24 '22 at 19:47

0 Answers0