No description
- C 92.4%
- CMake 7.2%
- HTML 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .clangd | ||
| .gitignore | ||
| CMakeLists.txt | ||
| README.md | ||
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_PATHenvironment 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: Off1: Speed 12: Speed 23: Speed 3 |
| 100 | Input Register (0x04) |
Read-only | Last Change Source | 0: None1: Rotary switch2: Web interface3: Modbus |