Add readings from BME280 sensor

This commit is contained in:
Cedric Girard 2019-05-02 15:59:42 +02:00
parent 3742bc3ae5
commit 77cbdf47b9
Signed by: X-dark
GPG key ID: E7D0E125DB9519E4
3 changed files with 48 additions and 1 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "libraries/U8g2_Arduino"] [submodule "libraries/U8g2_Arduino"]
path = libraries/U8g2_Arduino path = libraries/U8g2_Arduino
url = https://github.com/olikraus/U8g2_Arduino url = https://github.com/olikraus/U8g2_Arduino
[submodule "libraries/BME280"]
path = libraries/BME280
url = https://github.com/finitespace/BME280.git

View file

@ -9,11 +9,16 @@
#include <SPI.h> #include <SPI.h>
#endif #endif
#include <BME280I2C.h>
#include <Wire.h>
U8X8_SSD1327_EA_W128128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); U8X8_SSD1327_EA_W128128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
// setup the terminal (U8X8LOG) and connect to u8g2 for automatic refresh of the display // setup the terminal (U8X8LOG) and connect to u8g2 for automatic refresh of the display
// The size (width * height) depends on the display // The size (width * height) depends on the display
#define U8LOG_WIDTH 16 #define U8LOG_WIDTH 16
#define U8LOG_HEIGHT 12 #define U8LOG_HEIGHT 12
uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT]; uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
@ -49,12 +54,50 @@ void setup() {
u8x8log.print("\n"); u8x8log.print("\n");
u8x8log.print("\n"); u8x8log.print("\n");
//Init BME280 sensor
Wire.begin();
while(!bme.begin())
{
u8x8log.print("Could not find BME280 sensor!\n");
delay(1000);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
u8x8log.print("Found BME280 sensor! Success.\n");
break;
case BME280::ChipModel_BMP280:
u8x8log.print("Found BMP280 sensor! No Humidity available.\n");
break;
default:
u8x8log.print("Found UNKNOWN sensor! Error!\n");
}
} }
void loop() { void loop() {
//Clear screen //Clear screen
u8x8log.print("\f"); u8x8log.print("\f");
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
bme.read(pres, temp, hum, tempUnit, presUnit);
u8x8log.print("Temp: ");
u8x8log.print(temp);
u8x8log.print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
u8x8log.print("\nHumidity: ");
u8x8log.print(hum);
u8x8log.print("% RH");
u8x8log.print("\nPressure: ");
u8x8log.print(pres);
u8x8log.print("Pa\n");
delay(10000); delay(10000);
} }

1
libraries/BME280 Submodule

@ -0,0 +1 @@
Subproject commit 7a211f03aa3ac5567b14e2cbc12ac21e185b6e0b