This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:gabriel.eftimie [2026/05/18 17:39] gabriel.eftimie [Hardware Design] |
pm:prj2026:jan.vaduva:gabriel.eftimie [2026/05/25 00:09] (current) gabriel.eftimie [Software Design] |
||
|---|---|---|---|
| Line 86: | Line 86: | ||
| ^ ATmega328P Pin (Arduino Label) ^ Connected To ^ Component / Signal Description ^ | ^ ATmega328P Pin (Arduino Label) ^ Connected To ^ Component / Signal Description ^ | ||
| - | | PD0 (D0/RX) | ESP8266 TX (Pin 24) | UART Serial Data Receive | | + | | PD0 (D0/RX) | ESP8266 TX | UART Serial Data Receive | |
| - | | PD1 (D1/TX) | ESP8266 RX (Pin 25) | UART Serial Data Transmit | | + | | PD1 (D1/TX) | ESP8266 RX | UART Serial Data Transmit | |
| | PD2 (D2) | Button S1 (Pin 1) | Digital Input for Button 1 (Internal Pull-up) | | | PD2 (D2) | Button S1 (Pin 1) | Digital Input for Button 1 (Internal Pull-up) | | ||
| | PD3 (D3) | Button S2 (Pin 1) | Digital Input for Button 2 (Internal Pull-up) | | | PD3 (D3) | Button S2 (Pin 1) | Digital Input for Button 2 (Internal Pull-up) | | ||
| Line 122: | Line 122: | ||
| ===== 2. Controller Node ===== | ===== 2. Controller Node ===== | ||
| - | |||
| - | The Controller Node is based on the WiFi LoRa 32 V2 Module. It interfaces with an Addressable RGB LED (ARGB) strip, a DHT22 environment sensor, and a 4-pin PWM fan powered by an external 12V accumulator. | ||
| - | |||
| ==== 2.1 Microcontroller Pin Mapping ==== | ==== 2.1 Microcontroller Pin Mapping ==== | ||
| ^ Module Pin / GPIO ^ Connected To ^ Component / Signal Description ^ | ^ Module Pin / GPIO ^ Connected To ^ Component / Signal Description ^ | ||
| - | | 5V (Pin 20) | ARGB Pin 2 | 5V VCC Power Output for LED Strip | | + | | 5V | ARGB Pin 2 | 5V VCC Power Output for LED Strip | |
| - | | 3V3 (Pin 16 / 17) | DHT22 Pin 1 | 3.3V VCC Power Output for Sensor | | + | | 3V3 | DHT22 Pin 1 | 3.3V VCC Power Output for Sensor | |
| - | | GND (Pin 18 / 19) | System GND Rail | Shared Reference Ground | | + | | GND | System GND Rail | Shared Reference Ground | |
| - | | GPIO 16 (Pin 36) | 4 PIN PWM Pin 1 | Fan Control / Tachometer / PWM Output | | + | | GPIO 16 | 4 PIN PWM Pin 1 | Fan Control / Tachometer / PWM Output | |
| - | | GPIO 21 (Pin 1) | 4 PIN PWM Pin 2 | Fan Control / PWM / Tachometer Output | | + | | GPIO 17 | DHT22 Pin 2 | DHT22 Data Signal (Bidirectional) | |
| - | | GPIO 17 (Pin 35) | DHT22 Pin 2 | DHT22 Data Signal (Bidirectional) | | + | | GPIO 18 | ARGB Pin 4 | ARGB LED Data Signal Output | |
| - | | GPIO 18 (Pin 30) | ARGB Pin 4 | ARGB LED Data Signal Output | | + | |
| ==== 2.2 Peripheral Devices Connectivity ==== | ==== 2.2 Peripheral Devices Connectivity ==== | ||
| Line 162: | Line 158: | ||
| | Positive (+) | 4 PIN PWM Pin 4 | High-power +12V Supply for the Fan | | | Positive (+) | 4 PIN PWM Pin 4 | High-power +12V Supply for the Fan | | ||
| | Negative (-) | System GND Rail | Common ground loop safety connection | | | Negative (-) | System GND Rail | Common ground loop safety connection | | ||
| - | ===== Software Design ===== | + | ===== Firmware Description & Software Architecture ===== |
| + | ==== 1. Development Environment (IDE & Frameworks) ==== | ||
| + | The project utilizes a hybrid software architecture tailored to the specific capabilities of each microcontroller. The entire system is managed via **Visual Studio Code (VS Code)** combined with the **PlatformIO** extension. This IDE was chosen over the standard Arduino IDE due to its superior toolchain management and the ability to handle independent compilations for different architectures (ESP32 and AVR) within the same environment. | ||
| - | <note tip> | + | * **Central Node (Controller - ESP32-S3 T-HMI):** The firmware is developed using the official **ESP-IDF (Espressif IoT Development Framework)** in C. ESP-IDF was selected to ensure low-level control over hardware peripherals (such as hardware timers for PWM and the I80 parallel interface for the display) and to run the application on top of a Real-Time Operating System (**FreeRTOS**). |
| - | Descrierea codului aplicaţiei (firmware): | + | * **Remote Node (Control Unit - Arduino Mega 2560):** The firmware utilizes the standard **Arduino framework (C++)**, which significantly simplifies the management of hardware serial communication (''Serial1'' for the ESP-01S module) and the debouncing logic for the physical input buttons. |
| - | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | |
| - | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | |
| - | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
| - | * (etapa 3) surse şi funcţii implementate | + | |
| - | </note> | + | |
| - | ===== Rezultate Obţinute ===== | + | ==== 2. 3rd-Party Libraries and Sources ==== |
| + | The system is designed with minimal reliance on external third-party libraries, implementing critical logic from scratch to maximize efficiency and stability. For the Central Node, native ESP-IDF components were exclusively used: | ||
| + | * ''driver/ledc.h'': For generating the hardware PWM signals required by the fan. | ||
| + | * ''driver/gpio.h'' & ''esp_timer.h'': For managing hardware interrupts (ISR) and high-precision microsecond timing. | ||
| + | * ''esp_lcd_panel_*.h'': Native drivers for initializing and pushing data to the ST7789 LCD via the I80 parallel bus. | ||
| + | * //Note:// No external libraries (such as Adafruit DHT) were used for the AM2302/DHT22 temperature sensor. The 1-Wire communication protocol was manually implemented (bit-banging). | ||
| - | <note tip> | + | ==== 3. Planned & Implemented Algorithms and Structures ==== |
| - | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | + | The software architecture relies on the following core algorithms: |
| - | </note> | + | * **Digital Decoding Algorithm (Bit-Banging) for DHT22:** Because the ESP32-S3 FreeRTOS scheduler can cause microsecond desynchronization on the 1-Wire bus, a strict timing algorithm (''dht_wait_state'') was implemented. It measures high/low pulse durations in microseconds. Pulses longer than 40µs are interpreted as a logical ''1'', successfully reconstructing the 40-bit data packet (16-bit humidity, 16-bit temperature, 8-bit checksum). |
| + | * **Tachometric (RPM) Calculation Algorithm:** Utilizes an Interrupt Service Routine (ISR) attached to the falling edge of the fan's TACHO pin. A variable counts the pulses generated by the fan's internal Hall-effect sensor. Periodically, the interrupt is paused, and the pulse count is multiplied by a timing constant (e.g., 15, for a 2-second sampling interval) to calculate the exact Revolutions Per Minute (RPM). | ||
| + | * **Thermal Control Structure (Fan Curve):** A step-based linear conditional block maps the read temperature ranges to an 8-bit Duty Cycle interval (0–255). Predefined thresholds dynamically adjust the RPM (e.g., <25°C equals ~20% power; >35°C equals 100% power) to maintain an optimal cooling-to-noise ratio. | ||
| + | * **Framebuffer Rasterization for Display:** To prevent visual flickering on the LCD, characters are not drawn directly to the screen. Instead, they are drawn into an allocated memory structure (''uint16_t framebuffer[320 * 240]''). A rasterization algorithm parses a custom 8x8 font dictionary, applies a 3x scaling multiplier, maps the 16-bit RGB565 colors, and pushes the entire buffer to the display in a single block. | ||
| + | |||
| + | ==== 4. Implemented Sources and Functions (Stage 3 - Controller Node) ==== | ||
| + | The following critical C functions were developed and validated for the central unit: | ||
| + | |||
| + | * **''dht_wait_state(int state, int timeout_us)''**: A blocking function equipped with an internal timeout (based on ''esp_timer_get_time()'') that measures the duration of a logical state on the GPIO pin, preventing infinite loops in case of sensor disconnection. | ||
| + | * **''read_dht22(float *temp)''**: Initiates the sensor wake-up sequence, temporarily disables global OS interrupts (''taskDISABLE_INTERRUPTS'') to guarantee precise bus timing, decodes the bitstream, and validates data integrity via the checksum. | ||
| + | * **''tacho_isr_handler()''**: The hardware interrupt function. It incorporates a software debouncing mechanism (''now - last_pulse_time > 2500 µs'') to filter out parasitic electrical noise on the tachometer line before incrementing the ''pulse_count''. | ||
| + | * **''fan_hardware_init()''**: Configures the LEDC timer for a 25kHz frequency (the industry standard for 4-pin PC fans), sets the 8-bit resolution, and attaches the ISR to the RPM reading pin. | ||
| + | * **''init_display_primitive()''**: Initializes the 8-bit I80 parallel bus and configures the internal ST7789 display controller (including color inversion and XY memory mapping). | ||
| + | * **''draw_char_to_fb()'' / ''draw_string_to_fb()'' / ''clear_framebuffer()''**: A suite of custom graphical functions that take a string, read the corresponding binary pattern from the font matrix (''font8x8''), scale it, and write the pixel data into the framebuffer array. | ||
| + | * **''control_task()''**: The main FreeRTOS task running in an infinite loop (''while(1)''). It orchestrates the overall system logic: reads the DHT22 sensor, calculates the RPM while safely pausing interrupts, applies the thermal curve via ''ledc_set_duty'', renders the UI to the framebuffer, flushes it to the screen, and suspends itself for 2 seconds (''vTaskDelay''). | ||
| + | ===== Results / Photos ===== | ||
| + | Controller: | ||
| + | {{ :pm:prj2026:jan.vaduva:pozacontrollerventilator.jpeg?direct&400 |}} | ||
| + | Remote Control: | ||
| + | {{ :pm:prj2026:jan.vaduva:pozatelecomandaventilator.jpeg?direct&400 |}} | ||
| + | Testing that shows RPM and the temperature sensor working properly: | ||
| + | {{ :pm:prj2026:jan.vaduva:testingtemperatureandrpm.jpeg?direct&400 |}} | ||
| ===== Concluzii ===== | ===== Concluzii ===== | ||
| Line 184: | Line 203: | ||
| <note warning> | <note warning> | ||
| - | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | {{:pm:prj2026:jan.vaduva:schema_electrica_pm.fzz_1_.zip|}} |
| - | + | {{:pm:prj2026:jan.vaduva:videotestareeftimiegabriel.zip|}} | |
| - | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | + | |
| </note> | </note> | ||
| - | ===== Jurnal ===== | + | ===== Journal ===== |
| <note tip> | <note tip> | ||
| - | Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului. | + | This section serves as the official development log for the project assistant to monitor progress, track milestones, and review troubleshooting steps. |
| </note> | </note> | ||
| + | ^ Date ^ Task / Milestone Description ^ Status ^ Notes & Troubleshooting ^ | ||
| + | | 2026-05-16 | Hardware component selection & schematic design in Fritzing. Hardware pin alignment and safety review | **Completed** | Corrected ESP-01S power layout (pin EN pulled HIGH to 3.3V). Confirmed button wiring to GND for INPUT_PULLUP safety. | | ||
| + | | 2026-05-16 | Finalized hardware pinout documentation | **Completed** | | | ||
| + | | [Date] | Firmware development for the Remote Node (ATmega328PB) | *Pending* | Implementing button debouncing and serial UART packet transmission logic. | | ||
| + | | [Date] | Firmware development for the Controller Node | *Pending* | Writing logic for PWM fan control, DHT22 sensor readings, and ARGB lighting profiles. | | ||
| + | | [Date] | End-to-end integration and wireless communication testing | *Pending* | Testing packet delivery and response lag between the remote and the main controller. | | ||
| ===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||