Skip to content
DaveMDSPublic

About

Growbox monitoring and automation on a Raspberry Pi

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🌱 Growberry

Monitoring and automation of a closed growbox with a Raspberry Pi.

Phase 1: full monitoring (climate, light, live camera, timelapse) and grow lamp control. Final goal: full automation (fan, heater, ...).

The growbox with the control box on the left pole, the LED lamp hanging from the top and a cat lying on the floor

The first prototype, November 2026: everything mounted in the growbox for the first time, control box (Pi, relays, fan board) on the left pole. Not the final layout, things will still move. The cat is not part of the hardware, it just moved in first.

Hardware

Part Role Notes
Raspberry Pi 3 B+ (rev 1.3) brain dual-band Wi-Fi
2× SparkFun BME280 (Qwiic) temperature, humidity, pressure 0x76 bottom, 0x77 top, inside the box
SparkFun VEML6030 (Qwiic) ambient light (lux) 0x48 (0x10 with the ADDR jumper)
SparkFun Qwiic pHAT Qwiic connectors on the Pi I²C bus
Joy-IT SBC-SSR01, 4× solid state relay switches the loads AC only, 100–240 V, max 2 A per channel. Active high
Logitech webcam, Zeiss 2 MP autofocus live stream and timelapse USB, served by µStreamer. Needs an ND filter (ND8) in front of the lens against banding from the PWM-dimmed lamp, see deploy/ustreamer.service
Mean Well HDR-30-5 5 V 3 A DIN-rail PSU trim to ~5.1–5.2 V for the Pi 3
Arctic P14 PWM PST 140 mm 4-pin PWM fan, 12 V 200–1700 rpm, stops below ~9% PWM. 12 V from an MT3608 boost converter on the 5 V PSU

Wiring (Pi header pin / BCM):

Pi to
pin 2 (5 V), pin 6 (GND) relay board DC+, DC−
pin 15 (GPIO 22) relay CH1: lamp (LED, 230 V)
pin 13 (GPIO 27) relay CH2: free
pin 11 (GPIO 17) relay CH3: free (heater, to come)
pin 16 (GPIO 23) relay CH4: free
pin 17 (3.3 V), 25 (GND), 3 (SDA), 5 (SCL) Qwiic chain: pHAT, 2× BME280, VEML6030
pin 31, 33, 35, 37 (GPIO 6, 13, 19, 26), 39 (GND) status LEDs, resistors on board, active high: green heartbeat, green ok, yellow warning, red error
pin 12 (GPIO 18), 18 (GPIO 24), 4 (5 V), 14 (GND) fan interface: PWM out, tachometer in

Relay channels on the pins suggested by the Joy-IT datasheet.

Wiring diagram: mains breaker and 5 V PSU on the DIN rail, Raspberry Pi with the Qwiic sensors, status LEDs, relay board and the fan through the MT3608

Wiring diagram, exported from docs/GrowBerry.odg (LibreOffice Draw).

The fan interface, on its own board: an NPN (2N3904) pulls the fan PWM input low, so the PWM is inverted (GPIO high = fan input low) and the fan runs at full speed while the Pi does not drive GPIO 18 (off, booting). A 4.7 kΩ pull-up to 5 V on the fan PWM input, the fan's own one is too weak: without it the slow rising edge cut the pulses by ~4 µs and the fan stopped below 20%. 1 nF across the base resistor speeds up the transistor. A second NPN brings the tachometer (0–5 V, 2 pulses per turn) down to the GPIO, with the internal pull-up: no 3.3 V wire.

Fan circuit schematic: Raspberry Pi, two 2N3904 NPN transistors for PWM and tachometer, the MT3608 boost and the 4-pin fan

Parts, perfboard layout and test measurements in docs/fan-circuit.html (open it in a browser).

Datasheets, drawings and photos in docs/.

Architecture

A single Python asyncio service (growberry), run by systemd:

  • sampler: reads the sensors and the relay states every sensors.interval seconds (2), and the health of the Pi every system.interval (30), as a sensor named system: CPU, RAM and disk use (%), CPU temperature, Wi-Fi signal (dBm), undervoltage (0/1). From /proc and /sys, and vcgencmd get_throttled for the undervoltage, which the firmware also remembers since boot. Every reading goes live to the dashboard; the readings are pooled per key and stored once every storage.average seconds (60), in windows aligned to the clock: the mean of each metric, the last value of a flag (relay states, undervoltage)
  • storage: SQLite (data/growberry.db), one long table samples(ts, key, value) with keys like top.temperature or lamp.on. Samples are buffered in RAM and flushed every storage.flush_interval seconds to spare the SD card
  • lamp: photoperiod schedule (lamp.on → lamp.off, may cross midnight) with manual override: mode auto / on / off
  • camera: µStreamer owns the webcam and serves the live MJPEG stream; the service grabs a frame from its /snapshot every camera.interval seconds into data/snapshots/<day>/<HHMMSS>.jpg, only while the lamp is on
  • plants: what grows in each of the 4 pots (a 2×2 grid, numbered 1–4): name, variety, sowing date, expected days to harvest, a color (one of ten, for the cards and the year chart), notes, and a diary of events (germinated, transplanted, watered, fed, pruned, note). A pot holds one growing plant; ended plants (harvested, died, removed) stay in the database as history. The same seeds in several pots are separate plants: the dashboard saves the edit form to every pot ticked, and remembers them in linked_pots to tick them again next time. Same SQLite file, tables plants and plant_events, written right away (rare, user-made writes)
  • status: the service health in three levels, ok / warning / error, from the problems found every second: a background loop crashed or a sensor not responding, undervoltage now (error), the lamp forced on or off, the camera failing twice in a row (after a failure it retries in 30 s), undervoltage since boot, CPU temperature or disk use over system.max_cpu_temperature / system.max_disk (warning). Shown in the dashboard and by the status LEDs: a traffic light lighting the worst level, and a heartbeat blinking at 0.5 Hz while the event loop runs. At startup a light runs back and forth along the LEDs for 5 seconds
  • system: restart the service, reboot or power off the Pi from the dashboard menu, through sudo -n systemctl (not with fake hardware)
  • logs: the dashboard menu shows the logs, live. On the Pi from the systemd journal (growberry and ustreamer units): it holds the earlier runs too, e.g. the traceback of a crash before systemd restarted the service; Raspberry Pi OS keeps it in RAM, so it is lost at reboot. Under systemd every line carries its syslog priority, so journalctl -p warning works too. With fake hardware, the lines of the process, kept in memory. No access log: one line per request drowned everything else
  • web: FastAPI, a static dashboard (plain JS, uPlot vendored) with live values over Server-Sent Events; the camera card shows the live stream or plays back the frames of a day in the browser, with the controls over the image and full screen; the menu also links to µStreamer's own page
  • fan: set by hand from the dashboard for now (fan.speed at start, stopped when the service stops). Hardware PWM at 25 kHz through sysfs, never disabled (its idle output, low, would mean full speed). Also a sensor: fan.speed (%) and fan.rpm, counted from the tachometer between two readings. Optional: no [fan] section, no fan
Endpoint
GET /api/info sensor names, relays, stream URL
GET /api/state latest readings, lamp, fan, last snapshot
GET /api/events SSE: full state, then every change
GET /api/history?hours=24 bucketed averages, uPlot column layout
GET /api/frames days with timelapse frames, newest first
GET /api/frames/{day} frames of a day (YYYY-MM-DD), oldest first
POST /api/lamp {"mode": "auto"|"on"|"off"} set lamp mode
POST /api/fan {"speed": 0-100} set the fan speed (%)
GET /api/logs?unit=&warnings=&before=&n=200 last log entries (before a time), oldest first
GET /api/logs/follow?unit=&warnings=&after= SSE: new log entries (after a cursor)
POST /api/system/{restart|reboot|poweroff} restart the service, reboot or power off the Pi
GET /api/pots every pot with its growing plant and diary, or null
GET /api/plants?year=2026 plants alive in a year (default: this one), ended ones too
GET /api/plants/{id} a plant, ended ones too
POST /api/plants {pot, name, sown, variety?, days_to_harvest?, notes?, color?, linked_pots?} plant something in an empty pot
PATCH /api/plants/{id} change any of those fields (pot moves it)
POST /api/plants/{id}/end {outcome, day?} harvested, died or removed: frees the pot
DELETE /api/plants/{id} forget a plant entered by mistake
POST /api/plants/{id}/events {kind, day?, note?} add to the diary (day defaults to today)
DELETE /api/plants/{id}/events/{event_id} remove from the diary

Development on a PC

With hardware.fake = true sensors, relays, fan and camera are simulated (the lamp heats the box up, the camera draws a growing plant), so everything runs without the Pi.

cp config.example.toml growberry.toml   # fake = true by default
uv sync --extra fake
uv run growberry                        # http://localhost:8090

Tests cover the backend: sensor drivers (BME280 checked against Bosch's reference code), fan, photoperiod, storage, camera, sampler, plants and HTTP API.

uv run pytest

On the Raspberry Pi

Raspberry Pi OS Lite 64-bit, hostname growberry, SSH key. The setup needs an admin user with sudo; the service runs as user berry, which owns the checkout and receives the deploys (SSH key, no password, no sudo but the rule below).

sudo timedatectl set-timezone Europe/Rome   # the lamp schedule uses local time
sudo raspi-config nonint do_i2c 0
sudo apt install i2c-tools ustreamer ffmpeg swig liblgpio-dev python3-dev
/usr/sbin/i2cdetect -y 1                    # expect 0x48, 0x76, 0x77
sudo useradd -m -s /bin/bash -G i2c,gpio,video,systemd-journal berry
sudo install -d -m 700 -o berry -g berry /home/berry/.ssh
sudo install -m 600 -o berry -g berry ~/.ssh/authorized_keys /home/berry/.ssh/

As berry, with the checkout in ~/growberry:

curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync --extra pi                          # builds lgpio, no aarch64 wheel

For the fan (hardware PWM on GPIO 18; the analog audio shares the PWM block), in /boot/firmware/config.txt, then reboot:

dtparam=audio=off
dtoverlay=pwm,pin=18,func=2

Copy config.example.toml to growberry.toml and set hardware.fake = false.

Two systemd services, install instructions inside each unit:

A sudoers rule, deploy/growberry.sudoers, lets berry restart them, reboot and power off without a password (exactly these commands, nothing else); the service uses it for the dashboard menu. Install instructions inside.

Security. The dashboard and µStreamer have no authentication and no TLS: anyone who reaches ports 8090 and 8081 sees the camera, switches the lamp and the fan, and can reboot or power off the Pi. Keep them on a trusted LAN; to reach them from outside, put them behind a reverse proxy with HTTPS and authentication, or a VPN. Never expose them directly to the internet.

Status

Done (October–November 2026), running on the Pi:

  • all sensors read (2× BME280, VEML6030), dashboard with live values and history
  • webcam live stream, timelapse frames every 5 min while the lamp is on, played back per day in the dashboard
  • lamp relay (CH1) with photoperiod and manual override; all four relay channels verified, active high
  • fan speed and rpm in the dashboard, set by hand; interface board soldered and mounted in the control box with the Pi
  • first prototype mounted in the growbox (November 2026), see the photo at the top; the layout is not final

Next:

  • final layout in the growbox
  • timelapse video: assemble a day/period of frames with ffmpeg
  • fan and heater (CH3) with automatic rules on temperature/humidity; decide what the fan does when the service stops or crashes
  • photoperiod still to decide (depends on the plants), 18/6 for now

License

Growberry is free software, released under the GNU Affero General Public License v3.0 or later. Vendored uPlot: MIT. The datasheets in docs/ belong to their manufacturers (Bosch Sensortec, Joy-IT), kept here because their links keep breaking.

About

Growbox monitoring and automation on a Raspberry Pi

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages