Small and efficient library for reading ambient temperature and barometric pressure from Bosch Sensortec Pressure sensor BMP280 and relative humidity from Humidity sensor BME280 with a unified interface. It was intended to be used with the ATtiny85 on the DigiSpark running the ATTinyCore Bootloader. The sensors are set to forced mode without oversampling and filters giving you measurements on request only to minimize current consumption. To reduce size of your compiled binary, different classes are available supporting only the functionality needed in your project.
There isn't a large amount of small, efficient and easy to use libraries for the BME280; that's what JVKran found out. That was the main goal of this entire library.
I needed only a temperature sensor and had a BMP280 lying around. So I modified this great library to support this sensor as well. Also, I included some checks to ensure that the sensor is connected. (...and fixed the typo in Celcius being nitpicky). I created several classes to support only the aquisitions and data format needed:
- ForcedBMX280
- Minimal version supporting only temperature aquisition in integer format
- ForcedBMX280Float
- Supporting temperature aquisition in integer and float format
- ForcedBMP280
- Supporting temperature and pressure aquisition in integer format
- ForcedBMP280Float
- Supporting temperature and pressure aquisition in integer and float format
- ForcedBME280
- Supporting temperature, pressure and humidity aquisition in integer format
- ForcedBME280Float
- Supporting temperature, pressure and humidity aquisition in integer and float format
See the full example on how to use the different classes.
The name of this respository stands for the mode in which the sensor is used. In forced mode the chip sleeps and gets waked up if data is requested. During measurements it peeks up to normal current consumption. However, when not in use, the chip only uses 0.25uA! Great for battery powered ATtiny's ;).
- Ultra low power. In sleep mode the BME280 only uses 0.25uA!
- Ultra small footprint; this library was made with efficiency and memory usage in mind.
- Easy to use interface and functions. Despite the small size of this library, functions are still very intuitive.
- Automatically change between using Wire and TinyWire.
A bare minimum example is given below:
#include <forcedBMX280.h>
// Create an instance of a BMX280. The parameters I2C bus and I2C address are optional.
// For example:
// - ForcedBMX280 climateSensor = ForcedBMX280(TinyWireM, BMX280_I2C_ALT_ADDR);
ForcedBMX280 climateSensor = ForcedBMX280();
void setup() {
Serial.begin(9600);
Wire.begin(); // Or "TinyWireM.begin()" when using an ATtiny.
// you might want to check if the sensor is available when "starting it up"
climateSensor.begin();
}
void loop() {
Serial.print("Temperature: ");
Serial.print(climateSensor.getTemperatureCelsius(true)/100);
Serial.println(" °C");
delay(2000);
}
This library automatically determines wether to use TinyWireM or Wire. The only thing the user has to take care of, is to make sure begin() is called on the appropriate instance in the setup(); TinyWireM.begin() or Wire.begin.
Further examples can be obtained from within the Arduino IDE in File->Examples->forcedBMX280->[...].
This function initializes the library. Call before use...
The funcion will return an error if the sensor is unavailable:
- ERROR_BUS (0x01) - Some error with the two-wire bus,
- ERROR_SENSOR_TYPE (0x02) - Chip-ID doesn't match our expectations (needs to be 0x58 for BMP280 and 0x60 for BME280),
- or 0 if everything went well.
Will return the Chip-ID as read with begin().
This function takes a forced measurement which means getTemperatureCelsius(), getPressure() (if class ForcedBMP280 or ForcedBME280 is used) and getRelativeHumidity() (if class ForcedBME280 is used and a BME280 is connected) use the updated values. Useful in case all functions are all called at the same time or you want to check the sensor's availability.
The funcion will return an error if the sensor is unavailable:
- ERROR_BUS (0x01) - Some error with the two-wire bus,
- or 0 if everything went well.
This function can be used to retrieve the temperature. The parameter defaults to false which means takeForcedMeasurement() should be called first to make sure updated values are used. If the passed parameter is equal to true, a forced measurement is taken; useful in case only the getTemperatureCelsius() function is called. The function is available in all classes.
See above, but using float for the result. The function is available in all classes ending with Float (i.e. ForcedBMX280Float, ForcedBMP280Float, ForcedBME280Float).
This function can be used to retrieve the pressure. The parameter defaults to false which means takeForcedMeasurement() should be called first to make sure updated values are used. If the passed parameter is equal to true, a forced measurement is taken; useful in case only the getPressure() function is called. The function is available in ForcedBMP280 and ForcedBME280 and their Float counterparts.
See above, but using float for the result. The function is available in ForcedBMP280Float and ForcedBME280Float.
This function can be used to retrieve the humidity. The parameter defaults to false which means takeForcedMeasurement() should be called first to make sure updated values are used. If the passed parameter is equal to true, a forced measurement is taken; useful in case only the getRelativeHumidity() function is called. The function is only available in ForcedBME280 and ForcedBME280Float.
See above, but using float for the result. The function is only available in ForcedBME280Float.
Open up the Arduino Library Manager
in the Arduino IDE and search for forcedBMX280. Select / install the the latest version. Click this badge for more detailed instructions.
Press the green clone or download button in the upper-right and download as .ZIP. Then go to the Arduino IDE and go to Sketch>Use Library->Add .ZIP Library_ and select the just downloaded zip file.