No description
  • C 92.4%
  • CMake 7.2%
  • HTML 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-25 12:07:34 +02:00
src debounce for rotary switch 2026-07-24 23:02:31 +02:00
.clangd refactor && index.shtml 2026-07-23 23:23:38 +02:00
.gitignore init && support rotary switch 2026-07-23 20:16:35 +02:00
CMakeLists.txt modbus support 2026-07-24 14:52:14 +02:00
README.md readme 2026-07-25 12:07:34 +02:00

Smart Fan (Raspberry Pi Pico 2 W)

Firmware for a smart fan powered by Raspberry Pi Pico 2 W, controllable via a physical rotary switch, a Web interface, and Modbus TCP.


📌 Pinout & Hardware Wiring

1. Rotary Switch (Inputs)

Configured as digital inputs with internal pull-ups. Connect the common pin of the switch to GND (Active LOW).

Pico 2 W Pin GPIO Component Pin Notes
Pin 2 GP1 Rotary Switch Position 1 Pulled LOW when Position 1 selected
Pin 4 GP2 Rotary Switch Position 2 Pulled LOW when Position 2 selected
Pin 5 GP3 Rotary Switch Position 3 Pulled LOW when Position 3 selected
GND GND Rotary Switch Common Pin Ground connection

2. Fan Speed Control Outputs (Relays / Triacs)

Configured as digital outputs with Active LOW logic (HIGH = OFF, LOW = ON).

Pico 2 W Pin GPIO Control Line Logic
Pin 15 GP11 Speed 1 Relay / Driver 0 = ON, 1 = OFF
Pin 16 GP12 Speed 2 Relay / Driver 0 = ON, 1 = OFF
Pin 17 GP13 Speed 3 Relay / Driver 0 = ON, 1 = OFF

3. Status LED

  • Onboard LED (CYW43_WL_GPIO_LED_PIN):
    • Solid ON: Wi-Fi connected.
    • OFF: Wi-Fi disconnected / reconnecting.

🛠 Build & Flash

Prerequisites

  • CMake (>= 3.13)
  • GCC ARM Toolchain (arm-none-eabi-gcc)
  • Pico SDK (with PICO_SDK_PATH environment variable set)

Building

mkdir build && cd build
cmake -DWIFI_SSID="Your_SSID" -DWIFI_PASSWORD="Your_Password" ..
make -j4

Copy the generated smart_fan.uf2 to your Raspberry Pi Pico 2 W in BOOTSEL mode.


📡 Modbus TCP Documentation

The device acts as a Modbus TCP server listening on port 502.

Address Register Type Access Description Values
100 Holding Register (0x03, 0x06, 0x10) Read / Write Fan Speed 0: Off
1: Speed 1
2: Speed 2
3: Speed 3
100 Input Register (0x04) Read-only Last Change Source 0: None
1: Rotary switch
2: Web interface
3: Modbus