Skip to content

Wkesther2/Weather-Station-Bare-Metal

Repository files navigation

☀️ STM32F407 Weather Station: Bare-Metal Driver Development

This repository contains the firmware for a simple weather station built on an STM32F407 Discovery Board. The project reads ambient temperature and humidity from a DHT11 sensor and displays the collected data on a 16x2 LCD module.


⚙️ Implementation Approach: Native Drivers

The core strength of this project is the Bare-Metal implementation. All peripheral control logic (drivers) was developed directly at the register level in C. I did not use the Hardware Abstraction Layer (HAL) or any external third-party libraries; the project relies solely on the standard C library and the stm32f407xx.h header file.

This approach demonstrates a deep understanding of the STM32 architecture and memory-mapped peripherals.

  • Custom-Developed Drivers for:
    • RCC: Configuration of the system clock, and enabling peripheral clocks.
    • GPIO: Pin configuration (Mode, Speed, Pull-up/down) for all components.
    • Basic Timer: Used for precise timing control required by the DHT11 protocol.
    • I²C (PCF8574): Implementation of the full $\text{I}^2\text{C}$ protocol (Start, Stop, ACK, NACK) for communication.
    • LCD (HD44780U): Low-level driver for sending commands and data to the display.
    • DHT11: Implementation of the single-wire protocol, including bit timing and data decoding.
    • EXTI: Configuration for button press detection.

🛠️ Components and Functionality

The weather station consists of the following hardware components:

Component Function Connection Pin
Microcontroller STM32F407VGT6 -
DHT11 Sensor Measures temperature ($\text{}^{\circ}\text{C}$) and humidity (%). PA0
PCF8574 Expander $\text{I}^2\text{C}$ to parallel interface for the LCD. PB6 (SCL), PB7 (SDA)
16x2 LCD Displays the current environmental readings. Via PCF8574
Push Button Used for requesting new data from the DHT11 (Triggers measurement via EXTI) PA3

🚀 Building and Usage

This project utilizes the GCC ARM Toolchain for compilation and an auto-generated Makefile (from STM32CubeIDE) to automate the entire bare-metal build process. This separation ensures the logic is fully decoupled from the build system.

Prerequisites

To successfully build and flash the firmware, ensure you have the following tools installed and configured:

  • GCC ARM Toolchain (arm-none-eabi-gcc)
  • GNU Make
  • OpenOCD or an equivalent utility for the ST-Link programmer

Build and Flash Instructions

  1. Clone the Repository:
    git clone https://github.com/Wkesther2/Weather-Station-Bare-Metal.git
    cd weather-station-bare-metal
  2. Compile the Project: The make all command compiles all source files using the custom toolchain and links them into the final executable binary.
    make all
  3. Flash the MCU: This command uses the configured programmer to transfer the compiled firmware to the STM32F407's flash memory.
    make flash

Operation

Upon a successful power-on or reset:

  1. The custom LCD driver initializes the display and displays the first reading of the DHT11.
  2. The station waits for the user input.
  3. Pressing the Push Button (PA3) triggers an External Interrupt (EXTI), which then calls the custom DHT11 driver to read the latest temperature and humidity values.
  4. The display updates immediately with the new data.

🧭 Project Structure

The project code is organized into modular directories to maintain clarity and driver isolation:

  • Inc/: Contains the main header file (main.h).
  • Src/: Contains the main application logic (main.c) and system initialization files.
  • Drivers/Inc: All header files (.c) for the custom-developed hardware drivers (e.g., gpio.h, i2c.h, dht11.h).
  • Drivers/Src: All source files (.c) for the custom-developed hardware drivers (e.g., gpio.c, i2c.c, dht11.c).

📸 Project Setup and Hardware Notes

The pictured prototype of the weather station was intentionally built using jumper wires instead of permanent soldering.

Why Jumper Wires?

This project serves primarily as a learning platform. Due to the specific hardware used—namely the overpowered STM32F407G-DISC1 board and the inaccurate DHT11 sensor for the intended application—this weather station will not be deployed permanently. The components remain unsoldered to allow for quick and flexible reuse in future embedded projects.

Weather Station Front Weather Station Back

Regarding the Disconnected Button

The reset button is not connected to the STM32 board in this photo. This is because I could not establish a stable connection using jumper wires on the button itself. However, the corresponding functionality (e.g., resetting sensor values) has been fully implemented and tested and works perfectly once a stable connection is established.

Weather_Station_Inside


👤 Author and License