BME280 module

BME280 (combined humidity and pressure sensor) operation sample This code demonstrates basic feature of BME280. The BME280 supports I2C and SPI interfaces. Both interfaces are supported in this code. On addition to that, bbI2C and bbSPI classes are supported to perform the operation with those “bit-bang” interface classes. For bbI2C and bbSPI, see following repositories

This project is licensed under the MIT License, see LICENSE.txt file for details in https://github.com/teddokano/BME280_MicroPython

BME280.BME280(interface, *, address=118, cs=None)[source]

A constructor interface for BME280

Parameters:
  • interface (obj) – machine.I2C or machine.SPI object

  • address (int (option)) – If need to specify (for I2C interface)

  • cs (machine.Pin object (option)) – If need to specify (for SPI interface)

Returns:

returns BME280_I2C when interface is I2C or bbI2C returns BME280_SPI when interface is SPI or bbSPI

Return type:

BME280_I2C or BME280_SPI object

Examples

For using I2C
>>> intf = I2C( 0, freq = (400 * 1000) )
>>> rtc  = BME280( intf )
For using SPI
>>> intf = SPI( 0, 500 * 1000, cs = 0 )
>>> rtc  = BME280( intf )
class BME280.BME280_I2C(i2c, address=118)[source]

Bases: BME280_base

read_reg(r, len=None)[source]

Read register

Parameters:
  • r (int) – Register address

  • len (int (option)) – Read length

Returns:

  • int (If len was not given or 1)

  • bytearray (If len was >1)

write_reg(r, v)[source]

Write register

Parameters:
  • r (int) – Register address

  • v (int) – Value to write into the register

class BME280.BME280_SPI(spi, cs=None)[source]

Bases: BME280_base

read_reg(r, len=None)[source]

Read register

Parameters:
  • r (int) – Register address

  • len (int (option)) – Read length

Returns:

  • int (If len was not given or 1)

  • bytearray (If len was >1)

write_reg(r, v)[source]

Write register

Parameters:
  • r (int) – Register address

  • v (int) – Value to write into the register

class BME280.BME280_base[source]

Bases: object

A class to operate a combined humidity and pressure sensor: BME280

https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/

compensate_H(adc_H)[source]

Calculate humidity from sensor read value

Parameters:

adc_H (int) – read value form register 0xFD and 0xFE as big-endian 16 bit integer

Returns:

float

Return type:

temperature value in %RH

compensate_P(adc_P)[source]

Calculate pressure from sensor read value

Parameters:

adc_P (int) – read value form register 0xF7-0xF9 as big-endian 20 bit integer

Returns:

float

Return type:

temperature value in hPa

compensate_T(adc_T)[source]

Calculate temperature from sensor read value

Parameters:

adc_T (int) – read value form register 0xFA-0xFC as big-endian 20 bit integer

Returns:

float

Return type:

temperature value in degree-C

humidity()[source]

get humidity value in %RH

Returns:

float

Return type:

humidity value in %RH

pressure()[source]

get pressure value in hPa

Returns:

float

Return type:

pressure value in hPa

read()[source]
show_dump()[source]
show_reg(r)[source]

Print register value

Parameters:

r (int) – Register address

temperature()[source]

get temperature value in degree-C

Returns:

float

Return type:

temperature value in degree-C

BME280.main()[source]