What it proves
The project develops the first camera prototype into a complete multi-board product architecture. Real-time work is divided between microcontroller firmware, a Wi-Fi transport bridge, and an embedded Linux NPU service instead of forcing every task onto one constrained device.
STM32 captures and transports OV2640 frames, ESP32 handles SPI reception and Algorithm-mode motion detection, while NanoPi is the only web server and runs neural motion segmentation, YOLOv5s INT8 RKNN inference, masks, and persistent track IDs.
System layers
STM32H503 firmware uses STM32 HAL and ThreadX to control ArduCAM and move frames over SPI.
ESP32 stores incoming frames, performs lightweight motion analysis, and forwards the stream over Wi-Fi/TCP.
NanoPi R5S serves the dashboard and performs RKNN inference, motion segmentation, masks, and interactive tracking.
STM32 as an expandable hardware hub
STM32H503 is not limited to forwarding camera data. It is the deterministic hardware hub of the system: it owns sensor initialization, real-time capture, peripheral timing, diagnostics, and the gateway toward ESP32. The current baseline connects OV2640 through ArduCAM, but the same architecture can be extended with additional sensors and control hardware without moving time-critical I/O into the networking layer.
Additional IMUs, environmental sensors, encoders, distance sensors, relays, or actuators can be integrated through available SPI, I²C, UART, GPIO, ADC, and PWM peripherals.
ThreadX tasks keep capture and hardware timing independent from Wi-Fi quality, Linux load, and neural-network latency.
New devices can be normalized into the STM32 application layer and sent upstream without requiring every sensor to implement networking.
How motion detection works on ESP32
The detector runs as a dedicated FreeRTOS task on core 1 and is active only in Algorithm mode. Processing is rate-limited so JPEG decoding and image analysis never starve SPI reception or the Wi-Fi transport task.
- 01The newest JPEG is decoded and reduced to an 80×60 grayscale plane.
- 02Gaussian smoothing suppresses JPEG noise; average brightness delta compensates for global exposure changes.
- 03The current and previous frames are compared with an absolute threshold of 18 to build a binary motion mask.
- 04Isolated pixels are removed and one-pixel gaps are bridged without allocating another full-size mask.
- 05An 8-connected flood fill extracts components of at least eight pixels and rejects near-full-frame shake or exposure transitions.
- 06Nearby regions are merged, sorted by changed-pixel count, and converted back into source-image coordinates; up to four boxes are retained.
- 07Tracking scores candidates by predicted center, luminance, area, and aspect ratio; velocity prediction keeps a target alive through short detection gaps.
Data-transfer protocols
I²C1 configures OV2640 registers; SPI1 reads the JPEG data from the ArduCAM FIFO.
SPI2 mode 0 plus a READY GPIO uses the binary CAM1 protocol: a 20-byte header, START/DATA/END packets, chunks up to 1536 bytes, offsets, frame IDs, and control query/reply messages.
A persistent Wi-Fi/TCP connection to port 5000 carries NPI1 frames: a 20-byte binary header, JPEG payload, optional UTF-8 JSON metadata, and a compact control response for mode, resolution, and tracking.
HTTP on port 8080 provides the dashboard, REST endpoints, status JSON, snapshots, and multipart MJPEG streaming in source, 800, 640, or 320 pixel quality profiles.
Software features and reliability decisions
STM32 circulates two fixed chunk objects and never stores a full JPEG. ESP32 uses three guarded 32 KiB frame slots, preventing a published frame from being overwritten while TCP or the detector reads it.
NanoPi publishes every valid frame immediately, while the NPU worker replaces stale pending work instead of building a queue. The result prioritizes low latency over processing every frame.
Raw mode streams video, Algorithm mode adds ESP32 motion boxes, and Neural mode adds NanoPi segmentation, YOLO detections, masks, classes, confidence values, and track IDs.
Magic values, lengths, offsets, bounds, and JPEG markers are validated. Oversized frames trigger a lower-resolution fallback; Wi-Fi and TCP reconnect automatically, and systemd restarts the NanoPi service.
Core responsibilities
- Built STM32Cube/ThreadX firmware for camera initialization, capture, diagnostics, and SPI transport.
- Implemented production PlatformIO firmware for ESP32 frame reception, state management, motion detection, and NanoPi transport.
- Developed the NanoPi Linux service with an HTTP/MJPEG dashboard, detector abstraction, motion segmentation, and object tracking.
- Prepared the YOLOv5s ReLU INT8 RKNN pipeline for the RK3568 NPU at 320×320 input resolution.
- Documented architecture, interfaces, deployment, operations, verification, security, and compliance in English and Ukrainian.