reformat cultivar_sensor.ino with 2-space indent and add CULTIVAR_ENV_WIRE define for platform-specific Wire selection

This commit is contained in:
grove5_admin committed 2026-04-29 20:36:15 -07:00
1 parent 89173129d9
commit 0f2dac32f1
3 files changed
+56 -57

No files matched your search

@@ -20,12 +20,12 @@
// ── Collection interval ─────────────────────────────────────────────────── // ── Collection interval ───────────────────────────────────────────────────
// Production: 5 minutes. Dev/test: 30 seconds. // Production: 5 minutes. Dev/test: 30 seconds.
#define COLLECT_INTERVAL_MS (5UL * 60UL * 1000UL) #define COLLECT_INTERVAL_MS (5UL * 60UL * 1000UL)
// #define COLLECT_INTERVAL_MS (30UL * 1000UL) // dev // #define COLLECT_INTERVAL_MS (30UL * 1000UL) // dev
// ── I2C pins — update for production board ──────────────────────────────── // ── I2C pins — update for production board ────────────────────────────────
#define SDA_PIN 42 // ESP32S3 dev #define SDA_PIN 42 // ESP32S3 dev
#define SCL_PIN 41 // ESP32S3 dev #define SCL_PIN 41 // ESP32S3 dev
// ── JSON output buffer ──────────────────────────────────────────────────── // ── JSON output buffer ────────────────────────────────────────────────────
// Size: ~512 bytes for 10-point sweep + all fields // Size: ~512 bytes for 10-point sweep + all fields
@@ -34,71 +34,71 @@ static char jsonBuf[1024];
CultivarEnv env; CultivarEnv env;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
delay(2000); delay(2000);
Serial.println("\n╔═══════════════════════════════════╗"); Serial.println("\n╔═══════════════════════════════════╗");
Serial.println("║ Grove5 Cultivar ENV v0.2.0 ║"); Serial.println("║ Grove5 Cultivar ENV v0.2.0 ║");
Serial.println("║ Open source software, ║"); Serial.println("║ Open source software, ║");
Serial.println("║ honest hardware. ║"); Serial.println("║ honest hardware. ║");
Serial.println("║ grovefive.com ║"); Serial.println("║ grovefive.com ║");
Serial.println("╚═══════════════════════════════════╝\n"); Serial.println("╚═══════════════════════════════════╝\n");
if (!env.begin(Wire, SDA_PIN, SCL_PIN)) { if (!env.begin(Wire, SDA_PIN, SCL_PIN)) {
Serial.println("[ERROR] BME690 init failed — check wiring"); Serial.println("[ERROR] BME690 init failed — check wiring");
} }
env.scanI2C(); env.scanI2C();
Serial.printf("[cultivar_env] BME690: %s SCD43: %s\n", Serial.printf("[cultivar_env] BME690: %s SCD43: %s\n",
env.bme_ok ? "OK" : "FAIL", env.bme_ok ? "OK" : "FAIL",
env.scd4x_ok ? "OK (dual sensor mode)" : "not populated (single sensor mode)"); env.scd4x_ok ? "OK (dual sensor mode)" : "not populated (single sensor mode)");
if (env.scd4x_ok) { if (env.scd4x_ok) {
Serial.println("SCD43 warming up (~30s for first CO2 reading)..."); Serial.println("SCD43 warming up (~30s for first CO2 reading)...");
} }
Serial.printf("Collection interval: %lu min\n\n", Serial.printf("Collection interval: %lu min\n\n",
COLLECT_INTERVAL_MS / 60000UL); COLLECT_INTERVAL_MS / 60000UL);
} }
void loop() { void loop() {
static unsigned long lastCollect = 0; static unsigned long lastCollect = 0;
static bool firstRun = true; static bool firstRun = true;
// First collection: wait for SCD43 warmup if present, else 5s // First collection: wait for SCD43 warmup if present, else 5s
unsigned long waitMs = firstRun unsigned long waitMs = firstRun
? (env.scd4x_ok ? 35000UL : 5000UL) ? (env.scd4x_ok ? 35000UL : 5000UL)
: COLLECT_INTERVAL_MS; : COLLECT_INTERVAL_MS;
if (millis() - lastCollect >= waitMs) { if (millis() - lastCollect >= waitMs) {
lastCollect = millis(); lastCollect = millis();
firstRun = false; firstRun = false;
Serial.println("Starting collection..."); Serial.println("Starting collection...");
CultivarEnvPayload payload; CultivarEnvPayload payload;
env.collect(payload); env.collect(payload);
// Human-readable output // Human-readable output
env.printPayload(payload); env.printPayload(payload);
// JSON → Linux side (Serial or UART to QRB2210) // JSON → Linux side (Serial or UART to QRB2210)
size_t jsonLen = env.toJSON(payload, jsonBuf, sizeof(jsonBuf)); size_t jsonLen = env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
Serial.println("\n── JSON ──────────────────────────────"); Serial.println("\n── JSON ──────────────────────────────");
Serial.println(jsonBuf); Serial.println(jsonBuf);
Serial.println("─────────────────────────────────────\n"); Serial.println("─────────────────────────────────────\n");
// Example: Linux side echoes back baseline_established=true // Example: Linux side echoes back baseline_established=true
// env.setBaselineEstablished(true); // env.setBaselineEstablished(true);
} }
// Keep SCD43 active between collections // Keep SCD43 active between collections
if (env.scd4x_ok) { if (env.scd4x_ok) {
CultivarCO2 co2; CultivarCO2 co2;
env.pollCO2(co2); env.pollCO2(co2);
// fresh readings available here if needed for display etc. // fresh readings available here if needed for display etc.
} }
delay(100); delay(100);
} }
+2
View File
@@ -31,11 +31,13 @@
do { char _b[128]; snprintf(_b, sizeof(_b), fmt, ##__VA_ARGS__); Serial.print(_b); } while(0) do { char _b[128]; snprintf(_b, sizeof(_b), fmt, ##__VA_ARGS__); Serial.print(_b); } while(0)
#define CULTIVAR_ENV_SDA 0 #define CULTIVAR_ENV_SDA 0
#define CULTIVAR_ENV_SCL 0 #define CULTIVAR_ENV_SCL 0
#define CULTIVAR_ENV_WIRE Wire1
#else #else
#define CULTIVAR_SERIAL_PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__) #define CULTIVAR_SERIAL_PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__)
// ── Default I2C pins (ESP32S3 dev board — override for production) ───────── // ── Default I2C pins (ESP32S3 dev board — override for production) ─────────
#define CULTIVAR_ENV_SDA 42 #define CULTIVAR_ENV_SDA 42
#define CULTIVAR_ENV_SCL 41 #define CULTIVAR_ENV_SCL 41
#define CULTIVAR_ENV_WIRE Wire
#endif #endif
#include <Arduino.h> #include <Arduino.h>
+2 -5
View File
@@ -28,10 +28,7 @@ CultivarEnv env;
static char jsonBuf[JSON_BUF_SIZE]; static char jsonBuf[JSON_BUF_SIZE];
void setup() { void setup() {
if (!Bridge.begin()) { Bridge.begin();
Monitor.println("[ERROR] Bridge init failed");
while (true) {}
}
Monitor.println("\n[cultivar] ENV bridge starting..."); Monitor.println("\n[cultivar] ENV bridge starting...");
@@ -41,7 +38,7 @@ void setup() {
Monitor.println("[cultivar] TCP bridge ready on :5678"); Monitor.println("[cultivar] TCP bridge ready on :5678");
// SDA=0, SCL=0 on Zephyr = device tree configured pins (correct) // SDA=0, SCL=0 on Zephyr = device tree configured pins (correct)
if (!env.begin(Wire, SDA, SCL)) { if (!env.begin(Wire1, SDA, SCL)) {
Monitor.println("[WARN] BME690 init failed — check wiring"); Monitor.println("[WARN] BME690 init failed — check wiring");
} }