# bigfanofyours/weather-and-garden-monitoring-on-stm32 architecture

> Architecture diagram of the GitHub repository bigfanofyours/weather-and-garden-monitoring-on-stm32, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bigfanofyours/weather-and-garden-monitoring-on-stm32
- Repository: https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32

## Overview

##### Project type and purpose
- This is an embedded IoT system integrating:
- A bare-metal STM32F407VET6 microcontroller application (Core + Drivers folders).
- An ESP8266 NodeMCU WiFi module running Arduino sketches (ESP folder).
- A TFT LCD touchscreen interface (ILI9341 + XPT2046).
- Purpose: display data on a portrait-mode TFT, accept touch input, fetch/parse JSON over WiFi, render dynamic content (“Day”, “Night” screens).

##### File structure
- Top-level “Core” directory:
- Inc/: MCU headers (main.h, cJSON.h, display/touch driver headers).
- Src/: Bare-metal application code (main.c, display modes, cJSON parser, syscalls, startup).
- Startup/: CPU startup assembly.
- “Drivers” directory:
- CMSIS and STM32_HAL libraries used by Core.
- “ESP” directory:
- ESP_Sensor and ESP_Requester Arduino sketches.
- ArduinoJson library for JSON handling on ESP8266.

##### README for additional insights
- MCU runs at 168 MHz (HCLK), 8 MHz external crystal.
- SPI2 → XPT2046 touchscreen controller (raw coordinate sampling).
- FSMC → ILI9341 TFT display (16-bit parallel bus).
- USART (raw) → ESP8266: send URLs, receive JSON—no AT commands.
- ESP8266 flashed via Arduino IDE; default RX/TX pins.

a. Main components
- STM32F407 MCU
- Bare-metal firmware (HAL, cJSON, GUI modules)
- XPT2046 Touch Controller (SPI2)
- ILI9341 TFT LCD (FSMC)
- ESP8266 NodeMCU WiFi module (USART)
- External Web Server / Internet
b. Relationships and data flows
1. User touches screen → XPT2046 → SPI2 → MCU → firmware interprets coordinates.
2. MCU firmware builds URL request → USART → ESP8266.
3. ESP8266 connects to WiFi → HTTP request → Internet/Web API → JSON response.
4. ESP8266 receives JSON → USART → MCU.
5. MCU firmware parses JSON via cJSON → updates Day/Night UI → FSMC → TFT.
c. Architectural patterns and design principles
- Hardware-abstraction layer (STM32 HAL/CMSIS) isolates peripherals.
- Modular GUI: separate Day.c, Night.c display routines.
- JSON parsing on MCU and ESP: cJSON on STM32, ArduinoJson on ESP.
d. Key technologies/frameworks
- STM32 HAL (Drivers/STM32F4xx_HAL_Driver)
- CMSIS (Drivers/CMSIS)
- cJSON (Core/Src)
- ArduinoJson (ESP/libraries)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% STM32 and its peripherals
    subgraph "STM32F407" 
        style STM32 fill:#D0E8FF,stroke:#333,stroke-width:1px
        STM32["STM32F407 MCU"]:::hardware
        FW["Firmware (bare-metal)"]:::firmware
        TOUCH["XPT2046 Touch Controller (SPI2)"]:::peripheral
        DISPLAY["ILI9341 TFT LCD (FSMC)"]:::peripheral
    end

    %% ESP8266 WiFi module
    subgraph "ESP8266 NodeMCU"
        ESPHW["ESP8266 NodeMCU"]:::hardware
        HTTP["HTTP Client"]:::software
        AJ["ArduinoJson Library"]:::software
    end

    %% External Internet
    INTERNET["Web Server / Internet"]:::external

    %% Data flows
    TOUCH -->|"touch data (SPI2)"| FW
    FW -->|"render commands (FSMC)"| DISPLAY
    FW -->|"URL request (USART)"| ESPHW
    ESPHW -->|"HTTP over WiFi"| INTERNET
    INTERNET -->|"JSON response (HTTP)"| ESPHW
    ESPHW -->|"JSON data (USART)"| FW
    FW -->|"update UI"| DISPLAY

    %% Click Events
    click FW "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/tree/main/Core/Src"
    click TOUCH "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/blob/main/Core/Inc/XPT2046_touch.h"
    click TOUCH "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/blob/main/Core/Src/XPT2046_touch.c"
    click DISPLAY "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/blob/main/Core/Inc/ili9341.h"
    click DISPLAY "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/blob/main/Core/Src/ili9341.c"
    click ESPHW "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/blob/main/ESP/ESP_Requester/ESP_Requester.ino"
    click AJ "https://github.com/bigfanofyours/weather-and-garden-monitoring-on-stm32/tree/main/ESP/libraries/ArduinoJson"

    %% Styles
    classDef hardware fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef peripheral fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef firmware fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef software fill:#FFF0B3,stroke:#333,stroke-width:1px
    classDef external fill:#FFE4B5,stroke:#333,stroke-width:1px
```
