forked from RAKWireless/WisBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbme680.ino
52 lines (46 loc) · 1.2 KB
/
bme680.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
@file bme680.ino
@author rakwireless.com
@brief Setup and read values from bme680 sensor
@version 0.1
@date 2021-01-12
@copyright Copyright (c) 2020
**/
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h" //http://librarymanager/All#Adafruit_BME680
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme;
/**
@brief set and init bme680
*/
void bme680_init()
{
if (!bme.begin(0x76))
{
Serial.println("Could not find a valid BME680 sensor, check wiring!");
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
/**
@brief get bme680 data
*/
uint32_t bme680_read_data(double& temperature, double& pressure, double& humidity, double& gas_resist)
{
if (!bme.performReading())
{
Serial.println("Failed to perform reading :(");
return -1;
}
temperature = bme.temperature;
pressure = bme.pressure / 100.0;
humidity = bme.humidity;
gas_resist = bme.gas_resistance / 1000.0;
return 0;
}