<p align="center">
  <img src="docs/img/GithubBanner.jpeg" alt="LYNCEUS MK-I Banner" width="100%">
</p>

<p align="center">
  <a href="#2-hardware-connections-pinout"><img src="https://img.shields.io/badge/RADAR-24_GHz_FMCW-0284C7?style=for-the-badge&labelColor=18181B" alt="Radar 24 GHz" /></a>
  <a href="platformio.ini"><img src="https://img.shields.io/badge/MCU-ESP32--S3-E7352C?style=for-the-badge&logo=espressif&logoColor=white&labelColor=18181B" alt="ESP32-S3" /></a>
  <a href="#2-hardware-connections-pinout"><img src="https://img.shields.io/badge/DISPLAY-ST7789_IPS-16A34A?style=for-the-badge&labelColor=18181B" alt="ST7789 IPS" /></a>
  <a href="#6-bill-of-materials-bom"><img src="https://img.shields.io/badge/BATTERY-~18H_AUTONOMY-D97706?style=for-the-badge&labelColor=18181B" alt="Battery Autonomy" /></a>
  <a href="CAD/"><img src="https://img.shields.io/badge/CAD-STL_%26_STEP-7C3AED?style=for-the-badge&labelColor=18181B" alt="3D CAD Files" /></a>
</p>

<p align="center">
  <b>English</b> | <a href="README_RO.md">Română</a>
</p>

# Lynceus MK-I — ESP32-S3 + HLK-LD2450 + ST7789

**Lynceus MK-I** is a portable millimeter-wave radar (24 GHz FMCW) built around an **ESP32-S3**, the **HLK-LD2450** sensor, and an **ST7789 (320×240)** IPS display. It simultaneously detects and tracks up to 3 people in real time—displaying 2D position, distance, velocity, and movement direction on a fluid graphical interface running at ~35 FPS.

<p align="center">
  <img src="docs/img/lynceus_demo.gif" width="48%" alt="Lynceus MK-I Live Demo" />
  <img src="docs/img/lynceus_screen.png" width="48%" alt="Lynceus MK-I Display Screenshot" />
</p>

<p align="center">
  <img src="docs/img/lynceus_render_front.png" width="32%" alt="Lynceus MK-I Front View" />
  <img src="docs/img/lynceus_render_back.png" width="32%" alt="Lynceus MK-I Isometric View" />
  <img src="docs/img/lynceus_render_side.png" width="32%" alt="Lynceus MK-I Side View" />
</p>

---

## 1. Key Features

- **Dual-Core Architecture on ESP32-S3 (FreeRTOS):**
  - **Core 0:** Dedicated background task for continuous radar reading over UART at 256,000 baud, packet decoding, and executing kinematic filters.
  - **Core 1:** Renders the graphical interface at ~35 FPS, drives the RGB proximity LED, and handles serial console commands.
  - Fast, thread-safe inter-core synchronization via hardware spinlocks (`portENTER_CRITICAL`) and cooperative pausing during sensor configuration.
- **~35 FPS Graphical Display (In-RAM Double-Buffering):**
  - **40 MHz** hardware SPI communication with full in-memory off-screen rendering (`GFXcanvas16`) prior to display updates, completely eliminating screen flicker.
  - Precomputed offset Look-Up Table (LUT) for range rings and direct 2D vector rotation for velocity arrows.
  - Two on-the-fly switchable display scales: **CQB Zoom (3m)** for tight spaces and **Normal (6m)**.
- **Advanced Filtering & 2D Kinematic Tracking:**
  - **Anti-Ghost Filter:** Multi-frame confirmation, physically impossible jump rejection, and configurable FOV cone limiting (90° / 110° / 120°) to cut out side-wall multipath reflections.
  - **Desk Stabilization (Anti-Centroid Hopping):** When a person is seated and only moves their hand or mouse, the tracked point stays anchored to the torso without jumping between the chest and arm.
  - **Breathing-Cycle Persistence (3.8s Hold):** Retains static targets on screen during pauses between breaths (`[HLD]`), gradually fading the target outline as the signal ages.
  - **Velocity Vectors & Motion Trails:** Each target features a direction arrow scaled by velocity and a decaying visual motion trail behind it.
- **Optical Proximity Indicator (NeoPixel WS2812):**
  - Continuously shifts color based on the distance to the closest detected person:
    - Under 1m: Red (close proximity)
    - 1m – 2m: Orange
    - 2m – 3.5m: Yellow / Green
    - 3.5m – 5m: Cyan
    - Over 5m: Blue
    - Sensor disconnected: Pulsing Red (breathing effect when the sensor is unresponsive)

---

## 2. Hardware Connections (Pinout)

### ST7789 Display Connection (320x240 SPI)

| ST7789 Display Pin | ESP32-S3 Pin | Function |
| :--- | :--- | :--- |
| **GND** | GND | Common Ground |
| **VCC** | 3.3V / 5V | Power Supply |
| **SCL** | GPIO 12 | SPI Clock (SCLK) |
| **SDA** | GPIO 11 | SPI Data (MOSI) |
| **RES** | GPIO 8 | Display Reset |
| **DC** | GPIO 9 | Data / Command |
| **CS** | GPIO 10 | Chip Select |
| **BLK** | 3.3V (or floating) | Backlight |

### HLK-LD2450 Radar Connection

| LD2450 Pin | ESP32-S3 Pin | Function |
| :--- | :--- | :--- |
| **VCC** | 5V | 5V Power Supply |
| **GND** | GND | Common Ground |
| **TX** | GPIO 4 | Radar TX -> ESP32 RX (256,000 baud) |
| **RX** | GPIO 5 | Radar RX <- ESP32 TX (256,000 baud) |

---

## 3. Project Structure

```text
Lynceus/
├── CAD/                   # 3D enclosure files: STL (for 3D printing) and STEP (complete assembly)
├── docs/img/              # 3D enclosure renders, project banner, and live demo GIF
├── include/
│   ├── config.h           # All hardware settings, pins, colors, and filtering thresholds
│   ├── radar_types.h      # Data structures for targets and shared inter-core state
│   ├── ld2450.h           # Radar class and internal tracker definitions
│   ├── display.h          # Graphics manager for the ST7789 TFT display
│   └── proximity_led.h    # Control module for the NeoPixel RGB LED
├── src/
│   ├── ld2450.cpp         # 30-byte packet decoding, Core 0 task, and kinematic filters
│   ├── display.cpp        # Canvas rendering, LUT rings, velocity arrows, and HUD telemetry
│   ├── proximity_led.cpp  # Distance-based LED color calculation
│   └── main.cpp           # Initialization, display loop, and Serial Monitor commands
├── platformio.ini         # PlatformIO configuration (ESP32-S3, compiler optimizations, libraries)
├── LICENSE                # MIT License
├── README.md              # English documentation
└── README_RO.md           # Romanian documentation (Documentația în limba română)
```

---

## 4. Serial Monitor Commands (Interactive)

Open the Serial Monitor at **115200 baud** and send the following commands in real time:

| Key | Action |
| :---: | :--- |
| **A** | Cycle accuracy mode (`NORMAL` -> `PRECISION` -> `FAST`) |
| **G** | Cycle anti-ghost reflection filter (`BALANCED` -> `AGGRESSIVE` -> `OFF / RAW`) |
| **M** | Enable Multi-Target mode (tracks up to 3 people simultaneously) |
| **S** | Enable Single-Target mode (tracks only the strongest target) |
| **V** | Query radar module firmware version |
| **F** | Factory reset the radar sensor |
| **R** | Software reboot the radar sensor |
| **O** | Rotate screen orientation by 180° |
| **Z** | Toggle display range scale (Zoom 3m <-> Normal 6m) |
| **?** | Display the help menu with all available commands |

---

## 5. Building and Flashing (PlatformIO)

From the terminal or the bottom status bar in VS Code / PlatformIO:

```bash
# Build the project
pio run

# Upload to the ESP32-S3 board
pio run -t upload
```

---

## 6. Bill of Materials (BOM)

The total hardware cost is approximately **150–180 RON (~30–35 €)**:

| Component | Model / Specification | Estimated Price |
| :--- | :--- | :---: |
| **Microcontroller** | ESP32-S3 DevKit (N16R8 recommended) | ~30 RON (~6 €) |
| **mmWave Radar Sensor** | Hi-Link HLK-LD2450 (24 GHz FMCW) | ~40 RON (~8 €) |
| **Graphical Display** | ST7789 2.0" / 2.4" IPS (320x240, SPI) | ~25 RON (~5 €) |
| **Power Supply** | 18650 Battery Shield V8 (Dual Slot) | ~20 RON (~4 €) |
| **Batteries** | 2× 18650 Li-Ion Cells (~3000–3300 mAh) | ~40 RON (~8 €) |
| **3D Printed Enclosure** | Filament (~180g) | ~15 RON (~3 €) |
| **Hardware / Fasteners** | M2 / M2.5 Screws | ~5 RON (~1 €) |

---

## 7. Enclosure & 3D Printing (CAD Files)

The print-ready files for your slicer are located in [`CAD/STL/`](CAD/STL/):

* **`mainBody.stl`** — Main housing that holds the PCBs and the battery shield.
* **`Screen.stl`** — Top display bezel, ergonomically angled for clear viewing while holding the device in hand.
* **`Front.stl` & `FrontOuter.stl`** — Front faceplate and protective radome cover for the radar antenna.
* **`button.stl`** — Side mechanical button actuator.
* **[`Lynceus.step`](CAD/Lynceus.step)** — Complete CAD assembly in STEP format (located in [`CAD/`](CAD/)), ready for custom modifications or dimensional adjustments in CAD software (Fusion 360, SolidWorks, Onshape, etc.).

**Recommended 3D Printing Settings:**
* **Layer Height:** 0.20 mm is more than sufficient.
* **Wall Count (Perimeters):** Use at least 3–4 walls so the screws have enough material to bite into without cracking the plastic.
* **Infill:** ~20–25% (Gyroid or Grid patterns work great).
* **Material:** Standard PLA prints cleanly. For higher heat resistance under direct sunlight or rugged outdoor use, PETG or ASA are even better choices.

---

## 8. Credits & Reference CAD Models

For designing the enclosure (clearances, USB cutout, standoff mounts, and radar FOV clearance), the following GrabCAD community models were used as dimensional references:
- **ESP32-S3 Module:** [ESP32-S3-WROOM-1](https://grabcad.com/library/esp32-s3-wroom-1-1)
- **mmWave Radar Sensor:** [HLK-LD2450 24G Human Presence Sensor](https://grabcad.com/library/hlk-ld2450-24g-human-presence-sensor-millimeter-wave-radar-module-1)
- **18650 Power Shield:** [18650 Battery Shield V8](https://grabcad.com/library/18650-battery-shield-v8_enclosure_r2-1)

---

*Lynceus MK-I — Open-source 24 GHz portable radar project powered by ESP32-S3.*
