BME280 Environmental Sensor
This documentation includes installation guidelines and sample code for your hardware.
Python Library
We upgraded the BME280 sensor to BME680 in the IoT HAT revision 2. We're keeping this documentation for backward compatibility. If you have the IoT HAT revision 2, please use the BME680 library.
The new BME680 sensor adds gas resistance (hence, air quality) reading to the IoT HAT.
Turta_BME280 library is responsible for communicating with BME280 sensor.
To install the library from the (PyPI) Python Package Index, enter the following command to the console.
Add the following statement to the top of your Python code.
Then, create an instance of the Turta_BME280 class.
Now you're ready to access the library by calling the bme280 instance.
Initialization
The library automatically initializes the required components when its instance is being created, so there is no need to do a manual initialization.
Basic Members
Read Temperature
Reads the temperature in Celsius.
Parameters
None
Returns
Float: Temperature reading.
Read Humidity
Reads the relative humidity.
Parameters
None
Returns
Float: Relative humidity reading.
Read Pressure
Reads the pressure in Pa.
Parameters
None
Returns
Float: Air pressure in Pa.
Read Altitude
Reads the altitude from the sea level in meters.
Parameters
Float meanSeaLevelPressureInBar: Mean sea level pressure in bar.
Returns
Float: Altitude from the sea level.
Samples
You can copy the example code from https://github.com/Turta-io/IoTHAT/tree/master/Samples/Raspbian/Python address, and then copy it to the Raspberry Pi. There is one example of this library.
BME280 Sample App
This application demonstrates temperature, humidity, pressure, and altitude readings.
To run the example:
Copy the library and sample code to a folder on the Raspberry Pi.
Open terminal, and go to the folder you copied the codes.
Run the sample with the following command:
Sample Code
Result
When you run the sample, it prints sensor readings to the terminal. The example output should be like this:
To stop the Python script, just press CTRL + C.
Last updated