Port to ESP32

This commit is contained in:
2026-01-05 21:01:26 +01:00
parent 5f69141a86
commit 05be118dd1
21 changed files with 4025 additions and 29 deletions

194
README.md
View File

@ -1,38 +1,174 @@
# WS2812B-LED-RC-Controller
WS2812B Controller for RC plane night flying with spotlight
# ESP32 LED Controller for Model Aircraft
#### Fast overview: Video will come soon.
Professional LED controller firmware for ESP32 with Web-BLE configuration interface. Designed for model aircraft with WS2812B LED strips.
[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi//0.jpg)]
(https://www.youtube.com/watch?v=)
## Features
## 1.Hardware:
- Atmel Atmega328p
- WS2812B stirp (got mine from https://www.banggood.com/5M-45W-150SMD-WS2812B-LED-RGB-Colorful-Strip-Light-Waterproof-IP65-WhiteBlack-PCB-DC5V-p-1035640.html)
- 3W 12V LED
- Transistor 2N3904
- Capacitors - 10uF/25V
- Socket for Atmega
- Some servo wires
- Crystal 16MHz
- Capacitor Ceramic 22pF
- PCB of your choice
### Hardware Support
- **ESP32 DevKitC** and **ESP32-C3 MINI** Development Board
- Dual WS2812B LED strip support (configurable GPIOs)
- PWM signal input for RC control
- Real-time LED animation at 60 FPS
## 2.Software:
- get your isp-programmer (ex. USBasp) working, linux is your friend
- install latest Arduino IDE and drivers
- install FastLED https://github.com/FastLED/FastLED
### Animation Modes
1. **Black** - All LEDs off
2. **Red** - Solid red
3. **Blue** - Solid blue
4. **Green** - Solid green
5. **White** - Solid white
6. **Rainbow** - Smooth rainbow gradient
7. **Rainbow with Glitter** - Rainbow with sparkles
8. **Confetti** - Random colored speckles
9. **Sinelon** - Sweeping colored dot with trails
10. **BPM** - Pulsing stripes at 33 BPM
11. **Navigation** - Aviation lights (red left, green right)
12. **Chase (Red)** - Red dot chase effect
13. **Chase (RGB)** - RGB cycling chase effect
14. **Random** - Random LED colors
## 3.Libraries used in this project:
- FastLED from https://github.com/FastLED/FastLED
### Web-BLE Configuration
- **Pin Configuration**: Set GPIO pins for LED strips and PWM input
- **BLE Auto-Off**: Configure timeout (Never/1min/5min)
- **Manual Control**: Select animation modes from web interface
- **PWM Emulation**: Test mode switching without RC signal
- **OTA Firmware Update**: Upload new firmware via Bluetooth
### Installation:
1. prepare Hardware. Ground to Ground and the rest like the schematics (comming soon).
2. Upload the sketch to the Arduino with the ISP-Programmer.
3. Set the switches on your RC control for the two channels.
7. Power everything up.
8. Enjoy your WS2812B-LED-RC-Controller
## Project Structure
Bug and Features: Please report bugs and wishes to me. Thanks!
```
led-controller-firmware/
├── main/
│ ├── main.c # Application entry point
│ ├── control.c/h # BLE, NVS, initialization
│ ├── led.c/h # WS2812B control (RMT driver)
│ ├── rcsignal.c/h # PWM signal reading
│ └── animation.c/h # LED animation patterns
├── webapp/
│ ├── index.html # Web-BLE interface
│ ├── app/app.js # BLE communication logic
│ ├── css/style.css # UI styling
│ └── data/favicon.ico
├── CMakeLists.txt
├── sdkconfig.defaults
└── partitions.csv # OTA-enabled partition table
```
## Build Instructions
### Prerequisites
1. Install ESP-IDF v5.0 or later
2. For ESP32-C3, ensure RISC-V toolchain is installed
### Building
```bash
cd led-controller-firmware
# For ESP32 DevKitC
idf.py set-target esp32
idf.py build
# For ESP32-C3 MINI
idf.py set-target esp32c3
idf.py build
```
### Flashing
```bash
idf.py -p /dev/ttyUSB0 flash monitor
```
Replace `/dev/ttyUSB0` with your serial port (COM3 on Windows).
## Hardware Setup
### Wiring
```
ESP32 Pin -> Component
----------- ----------
GPIO XX -> WS2812B Strip A Data
GPIO XX -> WS2812B Strip B Data
GPIO XX -> RC PWM Signal
GND -> Common Ground
5V -> LED Strip Power (if current < 500mA)
```
### LED Strips
- **WS2812B** strips require 5V power
- Each LED draws ~60mA at full white
- Use external power supply for >10 LEDs
- Add 100-500µF capacitor near strips
- Add 330Ω resistor on data line
### PWM Signal
- Standard RC PWM: 1000-2000µs pulse width
- 1500µs threshold for mode switching
- Rising edge >1500µs after <1500µs triggers next mode
## Web-BLE Configuration
### Access the Interface
1. Open `webapp/index.html` in Chrome, Edge, or Opera (Web Bluetooth required)
2. Click "Connect via BLE"
3. Select "LED-Controller" from device list
4. Configure settings and control LEDs
### Configuration Options
#### Pin Setup
- **LED Strip A GPIO**: -1 to disable, 0-48 for GPIO pin
- **LED Strip B GPIO**: -1 to disable, 0-48 for GPIO pin
- **PWM Input GPIO**: -1 to disable, 0-48 for GPIO pin
#### BLE Timeout
- **Never**: BLE stays on until manually disabled
- **1 Minute**: Auto-disable after 1 min of boot (unless connected)
- **5 Minutes**: Auto-disable after 5 min of boot (unless connected)
#### Firmware Update
1. Build firmware: `idf.py build`
2. Find binary: `build/led_controller.bin`
3. Upload via Web-BLE interface
4. Device restarts with new firmware (settings reset)
## Default Configuration
On first boot or after reset:
- All pins: **Not configured** (-1)
- BLE timeout: **Never**
- Animation mode: **Black** (off)
Configure via Web-BLE before use.
## Development
### Adding New Animations
1. Add mode to `animation_mode_t` enum in `animation.h`
2. Implement animation function in `animation.c`
3. Add case to `animation_update()` switch statement
4. Update `MODE_NAMES` array in `webapp/app/app.js`
### Modifying LED Count
Edit `DEFAULT_NUM_LEDS_A` and `DEFAULT_NUM_LEDS_B` in `control.c`. TODO
### Testing
```bash
# Build and flash
idf.py build flash
# Monitor output
idf.py monitor
# Exit monitor: Ctrl+]
```
## License
See [LICENSE](LICENSE)