Files
Cultivar-Firmware/cultivar_env
..
2026-04-27 19:30:45 -07:00
2026-04-29 21:03:53 +00:00
2026-04-27 19:30:45 -07:00
2026-04-27 19:30:45 -07:00

cultivar_env

Environmental sensor library for the Grove5 Cultivar appliance.

Grove5 — Open source software, honest hardware.


Overview

cultivar_env runs on the real-time MCU (STM32 on Arduino UNO Q) and is responsible for:

  • Collecting ambient temp/humidity/pressure (BME690, heater off)
  • Running a 10-point mycology-tuned gas sweep
  • Reading real CO2 from SCD43 (if populated)
  • Cross-validating temp/humidity between BME690 and SCD43
  • Serializing a structured JSON payload for the Linux side

The Linux side (QRB2210) is responsible for baseline management, CO2e estimation, delta tracking, and anomaly detection. The STM32 just collects and sends.


Hardware

ENV-1-V0.1 sensor board — two population variants:

Variant Sensors Chamber
Full BME690 + SCD43 Fruiting — real CO2, cross-validation, drift detection
Lite BME690 only Colonization — CO2e from gas sweep (Linux side)

SCD43 is auto-detected at begin() — same firmware for both variants.


Dependencies


Installation

  1. Download Bosch BME690 SensorAPI
  2. Copy bme69x.h, bme69x.c, bme69x_defs.h into cultivar_env/src/
  3. Install Sensirion I2C SCD4x via Arduino Library Manager
  4. Install cultivar_env via Sketch → Include Library → Add .ZIP Library

Quick Start

#include <Wire.h>
#include <cultivar_env.h>

CultivarEnv env;
char jsonBuf[768];

void setup() {
    Serial.begin(115200);
    env.begin(Wire, 42, 41);  // SDA, SCL
}

void loop() {
    CultivarEnvPayload payload;
    env.collect(payload);
    env.printPayload(payload);

    env.toJSON(payload, jsonBuf, sizeof(jsonBuf));
    Serial.println(jsonBuf);  // → Linux side

    delay(300000); // 5 min
}

10-Point Mycology Gas Sweep

# Temp°C Dur ms Zone Notes
0 200 150 1 — Baseline Humidity/CO2 proxy
1 220 150 1 — Baseline Light alcohols low
2 250 150 1 — Baseline Ethanol / light alcohols
3 280 180 2 — Biological Acetic acid / bacterial marker
4 300 180 2 — Biological Terpene zone low
5 320 180 2 — Biological Geosmin / 1-octen-3-ol
6 340 200 2 — Biological Aldehyde zone
7 360 200 3 — Heavy Ammonia / nitrogen compounds
8 380 200 3 — Heavy Sulfur compounds
9 400 200 3 — Heavy Heavy VOC fingerprint

Important: Resistance values are raw. Humidity correction, baseline normalization, and compound inference are handled on the Linux side. The MOX sensor measures total gas load at each temperature — ratios and deltas are more meaningful than absolute values.


JSON Payload

{
  "ts": 300000,
  "ambient": {"temp": 23.45, "hum": 82.10, "pres": 929.88, "ok": true},
  "co2": {"ppm": 1850, "temp": 24.10, "hum": 83.20, "ok": true},
  "health": {
    "scd43": true,
    "tdelta": 0.65, "hdelta": 1.10,
    "tok": true, "hok": true
  },
  "baseline": {"established": false, "samples": 3},
  "sweep": [
    {"t": 200, "dur": 150, "zone": 1, "r": 85000000, "stable": true, "ok": true},
    {"t": 220, "dur": 150, "zone": 1, "r": 72000000, "stable": true, "ok": true},
    {"t": 250, "dur": 150, "zone": 1, "r": 61000000, "stable": true, "ok": true},
    {"t": 280, "dur": 180, "zone": 2, "r": 420000,   "stable": true, "ok": true},
    {"t": 300, "dur": 180, "zone": 2, "r": 280000,   "stable": true, "ok": true},
    {"t": 320, "dur": 180, "zone": 2, "r": 195000,   "stable": true, "ok": true},
    {"t": 340, "dur": 200, "zone": 2, "r": 148000,   "stable": true, "ok": true},
    {"t": 360, "dur": 200, "zone": 3, "r": 102400000,"stable": true, "ok": true},
    {"t": 380, "dur": 200, "zone": 3, "r": 102400000,"stable": true, "ok": true},
    {"t": 400, "dur": 200, "zone": 3, "r": 102400000,"stable": true, "ok": true}
  ]
}

Baseline Handshake

The STM32 increments baseline.samples every collection cycle. The Linux side determines when enough samples exist to establish a baseline and echoes back established=true. The STM32 includes the current baseline state in every payload.

// Called when Linux confirms baseline is ready
env.setBaselineEstablished(true);

// Called at start of new cultivation run
env.resetBaseline();

Sensor Health

When both sensors are populated, cultivar_env cross-validates temp and humidity between BME690 and SCD43 every collection cycle. Thresholds:

  • Temp delta warn: 2.0°C
  • Humidity delta warn: 5.0%RH

A persistent warning may indicate condensation on the BME690, sensor damage, or I2C degradation — all meaningful in a high-humidity grow chamber environment.


Notes

  • collect() blocks for ~15-25s (ambient settle + 10-point sweep)
  • SCD43 needs ~30s warmup on first power-on
  • BME690 gas resistance stabilizes over 15-30 min per session; full calibration takes several days per Bosch documentation
  • 5-minute collection interval recommended for production — frequent heater cycling causes thermal drift in ambient readings
  • Altitude not included in payload — compute on Linux side if needed

Architecture

STM32 (cultivar_env)          Linux / QRB2210
─────────────────────         ──────────────────────────────
collect()                 →   JSON payload (Serial/UART)
  readAmbient()               baseline management
  readCO2()                   humidity correction model
  runSweep() x10              CO2e estimation
  computeHealth()             delta tracking
toJSON()                      anomaly detection
                              Cultivar UI / MQTT
                          ←   baseline_established echo

License

MIT — Grove5
Bosch BME690 SensorAPI: BSD-3-Clause — Bosch Sensortec GmbH