#include #include #include #include #include "i2c_scan.h" #include "veml.h" constexpr auto SDA = 6; constexpr auto SCL = 23; constexpr auto BME_ADDR = 0x76; static TwoWire wire(SDA, SCL); static Adafruit_BME680 bme(&wire); static ocularium::VEML veml(wire); struct init_check { const String name; bool (*f)(); bool succeeded; }; static init_check STARTUP_CHECKS[] = { { .name = String("bme680"), .f = [] { return bme.begin(BME_ADDR); }, .succeeded = false, }, { .name = String("veml7700"), .f = []{ return veml.init(ocularium::veml::Config { .gain = ocularium::veml::AmbientLightGain::Quarter, }); }, .succeeded = false, } }; void startup_checks() { auto success = true; do { success = true; for (auto & check : STARTUP_CHECKS) { if (check.succeeded) continue; Serial.print("checking " + check.name + "... "); check.succeeded = check.f(); success = success && check.succeeded; if (check.succeeded) Serial.println("ok"); else Serial.println("bad"); } if (!success) delay(10); } while (!success); } void setup() { Serial.begin(115200); delay(2000); Serial.println("boot"); wire.begin(); ocularium::scan(wire); startup_checks(); Serial.println("sensors initialized"); } void loop() { static uint32_t bme_target_millis = 0; if (millis() >= bme_target_millis) { if (bme_target_millis != 0 && !bme.endReading()) { Serial.println("bme read error!"); } bme_target_millis = bme.beginReading(); } Serial.print("lux: " + String(veml.lux())); Serial.print(", temp: " + String(bme.temperature)); Serial.print(", hum: " + String(bme.humidity)); Serial.print(", pres: " + String(bme.pressure)); Serial.print(", gas: " + String(bme.gas_resistance)); Serial.println(); delay(100); }