How rodrigoacc10/ultrasonic_radar works
Project Type and Purpose
• This is a combined embedded‐firmware + PC tool project (“Arduino Radar”).
• The embedded side runs on an Arduino (PlatformIO/C++), controls a servo and LCD, reads ultrasonic sensor data, and streams measurements over serial.
• The PC side is a set of Python scripts that open a serial port, parse distance vs. angle data, and render a live radar‐style plot.
File Structure Analysis
Top‐level directories and files:
• platformio.ini – PlatformIO board/build config
• src/
– main.cpp (application entry: loop reading sensor, rotating servo, drawing on LCD, writing serial)
– lcd.cpp (LCD driver glue code)
• / – C++ headers for your application modules (lcd.h, etc.)
• lib/ – Third-party libraries:
– Servo (servo driver abstractions for AVR/megaAVR)
– SPI (low-level SPI master)
– Ucglib (graphics library + device drivers)
• script/ – PC‐side Python scripts (radar_serial_plot*.py) for serial plotting
• test/ – Unit tests for lcd, servo, main logic
• doc/ – Requirements, SDDs, test docs, Python script design
Key Architectural Insights from README
• Firmware is built and uploaded via PlatformIO in VS Code.
• Firmware controls hardware (servo, ultrasonic sensor, LCD) and emits data to USB‐serial (CH340).
• Python scripts use pySerial and matplotlib (or similar) to render live plots.
a. Main Components
• Hardware Layer
– Ultrasonic range sensor
– DC Servo motor
– SPI‐driven LCD display
– CH340 USB‐serial interface
• Firmware Layer (Embedded MCU)
– Hardware Abstraction & Drivers: Servo, SPI, Ucglib
– Application Logic: Sweep control, distance acquisition, display update, serial output
• PC Side
– Serial Acquisition Module (Python + pySerial)
– Plotting Module (matplotlib or similar)
• Development Toolchain
– PlatformIO/VS Code
– Arduino Core libraries
b. Component Interactions
– MCU ↔ Sensor (digital trigger/echo)
– MCU ↔ Servo via Servo library (PWM timers)
– MCU ↔ LCD via SPI & Ucglib
– MCU → PC via USB-serial (streaming angle + distance)
– PC Scripts → Plotter GUI
c. Architectural Patterns & Principles
– Layering:
• HAL (SPI, Servo)
• Graphics library (Ucglib)
• Application logic
– Separation of concerns: firmware vs. PC tools vs. tests
– Modularization: each library in lib/, each feature in its own source file
d. Key Technologies/Frameworks
– PlatformIO build system
– C++17 (Arduino style)
– Ucglib for graphics
– Servo library for motor control
– pySerial + matplotlib (or PyQtGraph)