initial commit
This commit is contained in:
1 parent
8a022ca22e
commit
e11564b359
7 files changed
+968
No files matched your search
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* cultivar_sensor.ino
|
||||
* Example sketch for the cultivar_env library.
|
||||
*
|
||||
* Grove5 Cultivar appliance — ENV-1-V0.1 sensor board
|
||||
* BME690 (required) + SCD43 (optional, auto-detected)
|
||||
*
|
||||
* STM32 responsibility: collect, validate, serialize → JSON → Linux
|
||||
* Linux responsibility: baseline, CO2e model, delta tracking, anomaly detection
|
||||
*
|
||||
* Board: ESP32S3 Dev Module (dev) / Arduino UNO Q (production)
|
||||
* I2C: SDA=42, SCL=41 (ESP32S3) — update for UNO Q pinout
|
||||
*
|
||||
* Grove5 — Open source software, honest hardware.
|
||||
* https://grovefive.com
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <cultivar_env.h>
|
||||
|
||||
// ── Collection interval ───────────────────────────────────────────────────
|
||||
// Production: 5 minutes. Dev/test: 30 seconds.
|
||||
#define COLLECT_INTERVAL_MS (5UL * 60UL * 1000UL)
|
||||
// #define COLLECT_INTERVAL_MS (30UL * 1000UL) // dev
|
||||
|
||||
// ── I2C pins — update for production board ────────────────────────────────
|
||||
#define SDA_PIN 42 // ESP32S3 dev
|
||||
#define SCL_PIN 41 // ESP32S3 dev
|
||||
|
||||
// ── JSON output buffer ────────────────────────────────────────────────────
|
||||
// Size: ~512 bytes for 10-point sweep + all fields
|
||||
static char jsonBuf[1024];
|
||||
|
||||
CultivarEnv env;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(2000);
|
||||
|
||||
Serial.println("\n╔═══════════════════════════════════╗");
|
||||
Serial.println("║ Grove5 Cultivar ENV v0.2.0 ║");
|
||||
Serial.println("║ Open source software, ║");
|
||||
Serial.println("║ honest hardware. ║");
|
||||
Serial.println("║ grovefive.com ║");
|
||||
Serial.println("╚═══════════════════════════════════╝\n");
|
||||
|
||||
if (!env.begin(Wire, SDA_PIN, SCL_PIN)) {
|
||||
Serial.println("[ERROR] BME690 init failed — check wiring");
|
||||
}
|
||||
|
||||
env.scanI2C();
|
||||
|
||||
Serial.printf("[cultivar_env] BME690: %s SCD43: %s\n",
|
||||
env.bme_ok ? "OK" : "FAIL",
|
||||
env.scd4x_ok ? "OK (dual sensor mode)" : "not populated (single sensor mode)");
|
||||
|
||||
if (env.scd4x_ok) {
|
||||
Serial.println("SCD43 warming up (~30s for first CO2 reading)...");
|
||||
}
|
||||
|
||||
Serial.printf("Collection interval: %lu min\n\n",
|
||||
COLLECT_INTERVAL_MS / 60000UL);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static unsigned long lastCollect = 0;
|
||||
static bool firstRun = true;
|
||||
|
||||
// First collection: wait for SCD43 warmup if present, else 5s
|
||||
unsigned long waitMs = firstRun
|
||||
? (env.scd4x_ok ? 35000UL : 5000UL)
|
||||
: COLLECT_INTERVAL_MS;
|
||||
|
||||
if (millis() - lastCollect >= waitMs) {
|
||||
lastCollect = millis();
|
||||
firstRun = false;
|
||||
|
||||
Serial.println("Starting collection...");
|
||||
|
||||
CultivarEnvPayload payload;
|
||||
env.collect(payload);
|
||||
|
||||
// Human-readable output
|
||||
env.printPayload(payload);
|
||||
|
||||
// JSON → Linux side (Serial or UART to QRB2210)
|
||||
size_t jsonLen = env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
|
||||
Serial.println("\n── JSON ──────────────────────────────");
|
||||
Serial.println(jsonBuf);
|
||||
Serial.println("─────────────────────────────────────\n");
|
||||
|
||||
// Example: Linux side echoes back baseline_established=true
|
||||
// env.setBaselineEstablished(true);
|
||||
}
|
||||
|
||||
// Keep SCD43 active between collections
|
||||
if (env.scd4x_ok) {
|
||||
CultivarCO2 co2;
|
||||
env.pollCO2(co2);
|
||||
// fresh readings available here if needed for display etc.
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
Reference in new issue
Block a user