reformat cultivar_sensor.ino with 2-space indent and add CULTIVAR_ENV_WIRE define for platform-specific Wire selection
This commit is contained in:
1 parent
89173129d9
commit
0f2dac32f1
3 files changed
+56
-57
No files matched your search
@@ -20,12 +20,12 @@
|
||||
|
||||
// ── Collection interval ───────────────────────────────────────────────────
|
||||
// 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
|
||||
|
||||
// ── I2C pins — update for production board ────────────────────────────────
|
||||
#define SDA_PIN 42 // ESP32S3 dev
|
||||
#define SCL_PIN 41 // ESP32S3 dev
|
||||
#define SDA_PIN 42 // ESP32S3 dev
|
||||
#define SCL_PIN 41 // ESP32S3 dev
|
||||
|
||||
// ── JSON output buffer ────────────────────────────────────────────────────
|
||||
// Size: ~512 bytes for 10-point sweep + all fields
|
||||
@@ -34,71 +34,71 @@ static char jsonBuf[1024];
|
||||
CultivarEnv env;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(2000);
|
||||
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");
|
||||
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");
|
||||
}
|
||||
if (!env.begin(Wire, SDA_PIN, SCL_PIN)) {
|
||||
Serial.println("[ERROR] BME690 init failed — check wiring");
|
||||
}
|
||||
|
||||
env.scanI2C();
|
||||
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)");
|
||||
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)...");
|
||||
}
|
||||
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);
|
||||
Serial.printf("Collection interval: %lu min\n\n",
|
||||
COLLECT_INTERVAL_MS / 60000UL);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static unsigned long lastCollect = 0;
|
||||
static bool firstRun = true;
|
||||
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;
|
||||
// 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;
|
||||
if (millis() - lastCollect >= waitMs) {
|
||||
lastCollect = millis();
|
||||
firstRun = false;
|
||||
|
||||
Serial.println("Starting collection...");
|
||||
Serial.println("Starting collection...");
|
||||
|
||||
CultivarEnvPayload payload;
|
||||
env.collect(payload);
|
||||
CultivarEnvPayload payload;
|
||||
env.collect(payload);
|
||||
|
||||
// Human-readable output
|
||||
env.printPayload(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");
|
||||
// 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);
|
||||
}
|
||||
// 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.
|
||||
}
|
||||
// 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);
|
||||
delay(100);
|
||||
}
|
||||
@@ -31,11 +31,13 @@
|
||||
do { char _b[128]; snprintf(_b, sizeof(_b), fmt, ##__VA_ARGS__); Serial.print(_b); } while(0)
|
||||
#define CULTIVAR_ENV_SDA 0
|
||||
#define CULTIVAR_ENV_SCL 0
|
||||
#define CULTIVAR_ENV_WIRE Wire1
|
||||
#else
|
||||
#define CULTIVAR_SERIAL_PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__)
|
||||
// ── Default I2C pins (ESP32S3 dev board — override for production) ─────────
|
||||
#define CULTIVAR_ENV_SDA 42
|
||||
#define CULTIVAR_ENV_SCL 41
|
||||
#define CULTIVAR_ENV_WIRE Wire
|
||||
#endif
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -28,10 +28,7 @@ CultivarEnv env;
|
||||
static char jsonBuf[JSON_BUF_SIZE];
|
||||
|
||||
void setup() {
|
||||
if (!Bridge.begin()) {
|
||||
Monitor.println("[ERROR] Bridge init failed");
|
||||
while (true) {}
|
||||
}
|
||||
Bridge.begin();
|
||||
|
||||
Monitor.println("\n[cultivar] ENV bridge starting...");
|
||||
|
||||
@@ -41,7 +38,7 @@ void setup() {
|
||||
Monitor.println("[cultivar] TCP bridge ready on :5678");
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user