Last active
March 29, 2023 14:50
-
-
Save alphaville/ab31addca96b511f6e85964453496015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; PlatformIO Project Configuration File | |
; | |
; Build options: build flags, source filter | |
; Upload options: custom upload port, speed and extra flags | |
; Library options: dependencies, extra library storages | |
; Advanced options: extra scripting | |
; | |
; Please visit documentation for the other options and examples | |
; https://docs.platformio.org/page/projectconf.html | |
[env:esp32dev] | |
platform = espressif32 | |
board = esp32dev | |
framework = arduino | |
monitor_speed = 115200 | |
lib_deps = adafruit/Adafruit BME680 Library@^2.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <Wire.h> | |
#include "Adafruit_BME680.h" | |
Adafruit_BME680 bme; | |
void setup_bme() | |
{ | |
bool status = bme.begin(); | |
if (!status) | |
{ | |
Serial.println("Could not connect to BME!"); | |
while (1) | |
; | |
} | |
} | |
void setup_serial() | |
{ | |
Serial.begin(115200); | |
while (!Serial) | |
; | |
} | |
void setup() | |
{ | |
setup_serial(); | |
setup_bme(); | |
} | |
void loop() | |
{ | |
unsigned long end_time = bme.beginReading(); | |
if (end_time == 0 || !bme.endReading()) | |
{ | |
Serial.println("Reading error :("); | |
return; | |
} | |
float temperature = bme.temperature; | |
float pressure = bme.pressure / 100.0; | |
Serial.print("Temperature = "); | |
Serial.print(temperature); | |
Serial.println(" *C"); | |
Serial.print("Pressure = "); | |
Serial.print(pressure); | |
Serial.println(" hPa"); | |
delay(200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment