Skip to content

Commit 961e263

Browse files
freakydudelmarzen
andauthored
add support for BME680 sensor (#169)
* add support for BME680 sensor * minor formatting --------- Co-authored-by: Luke Marzen <[email protected]>
1 parent a350453 commit 961e263

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

platformio/include/config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#define DRIVER_DESPI_C02
4343
// #define DRIVER_WAVESHARE
4444

45+
// INDOOR ENVIRONMENT SENSOR
46+
// Uncomment the macro that identifies your sensor.
47+
#define SENSOR_BME280
48+
// #define SENSOR_BME680
49+
4550
// 3 COLOR E-INK ACCENT COLOR
4651
// Defines the 3rd color to be used when a 3+ color display is selected.
4752
#if defined(DISP_3C_B) || defined(DISP_7C_F)
@@ -321,6 +326,10 @@ extern const uint32_t MIN_BATTERY_VOLTAGE;
321326
^ defined(DRIVER_DESPI_C02))
322327
#error Invalid configuration. Exactly one driver board must be selected.
323328
#endif
329+
#if !( defined(SENSOR_BME280) \
330+
^ defined(SENSOR_BME680))
331+
#error Invalid configuration. Exactly one sensor must be selected.
332+
#endif
324333
#if !(defined(LOCALE))
325334
#error Invalid configuration. Locale not selected.
326335
#endif

platformio/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ build_unflags = '-std=gnu++11'
2222
build_flags = '-Wall' '-std=gnu++17'
2323
lib_deps =
2424
adafruit/Adafruit BME280 Library @ 2.2.4
25+
adafruit/Adafruit BME680 Library @ 2.0.5
2526
adafruit/Adafruit BusIO @ 1.17.0
2627
adafruit/Adafruit Unified Sensor @ 1.1.15
2728
bblanchon/ArduinoJson @ 7.3.1

platformio/src/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const uint8_t PIN_EPD_PWR = 26; // Irrelevant if directly connected to 3.3V
4141
const uint8_t PIN_BME_SDA = 17;
4242
const uint8_t PIN_BME_SCL = 16;
4343
const uint8_t PIN_BME_PWR = 4; // Irrelevant if directly connected to 3.3V
44-
const uint8_t BME_ADDRESS = 0x76; // If sensor does not work, try 0x77
44+
const uint8_t BME_ADDRESS = 0x76; // 0x76 if SDO -> GND; 0x77 if SDO -> VCC
4545

4646
// WIFI
4747
const char *WIFI_SSID = "ssid";

platformio/src/main.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
#include "config.h"
1819
#include <Arduino.h>
19-
#include <Adafruit_BME280.h>
20+
#if defined(SENSOR_BME280)
21+
#include <Adafruit_BME280.h>
22+
#endif
23+
#if defined(SENSOR_BME680)
24+
#include <Adafruit_BME680.h>
25+
#endif
2026
#include <Adafruit_Sensor.h>
2127
#include <Preferences.h>
2228
#include <time.h>
@@ -26,7 +32,6 @@
2632
#include "_locale.h"
2733
#include "api_response.h"
2834
#include "client_utils.h"
29-
#include "config.h"
3035
#include "display_utils.h"
3136
#include "icons/icons_196x196.h"
3237
#include "renderer.h"
@@ -282,18 +287,27 @@ void setup()
282287
}
283288
killWiFi(); // WiFi no longer needed
284289

285-
// GET INDOOR TEMPERATURE AND HUMIDITY, start BME280...
290+
// GET INDOOR TEMPERATURE AND HUMIDITY, start BMEx80...
286291
pinMode(PIN_BME_PWR, OUTPUT);
287292
digitalWrite(PIN_BME_PWR, HIGH);
293+
TwoWire I2C_bme = TwoWire(0);
294+
I2C_bme.begin(PIN_BME_SDA, PIN_BME_SCL, 100000); // 100kHz
288295
float inTemp = NAN;
289296
float inHumidity = NAN;
297+
#if defined(SENSOR_BME280)
290298
Serial.print(String(TXT_READING_FROM) + " BME280... ");
291-
TwoWire I2C_bme = TwoWire(0);
292299
Adafruit_BME280 bme;
293300

294-
I2C_bme.begin(PIN_BME_SDA, PIN_BME_SCL, 100000); // 100kHz
295301
if(bme.begin(BME_ADDRESS, &I2C_bme))
296302
{
303+
#endif
304+
#if defined(SENSOR_BME680)
305+
Serial.print(String(TXT_READING_FROM) + " BME680... ");
306+
Adafruit_BME680 bme(&I2C_bme);
307+
308+
if(bme.begin(BME_ADDRESS))
309+
{
310+
#endif
297311
inTemp = bme.readTemperature(); // Celsius
298312
inHumidity = bme.readHumidity(); // %
299313

0 commit comments

Comments
 (0)