167 lines
4.0 KiB
Markdown
167 lines
4.0 KiB
Markdown
# ESP32-C6 Arduino Project
|
|
|
|
Arduino IDE project for ESP32-C6 Home Assistant integration.
|
|
|
|
## Arduino IDE Setup
|
|
|
|
### 1. Install ESP32 Board Support
|
|
|
|
1. Open Arduino IDE
|
|
2. Go to **File → Preferences**
|
|
3. Add this URL to "Additional Boards Manager URLs":
|
|
```
|
|
https://espressif.github.io/arduino-esp32/package_esp32_index.json
|
|
```
|
|
4. Go to **Tools → Board → Boards Manager**
|
|
5. Search for "esp32" by Espressif Systems
|
|
6. Install **esp32** (version 3.0.0 or later for ESP32-C6 support)
|
|
|
|
### 2. Board Configuration
|
|
|
|
In Arduino IDE, select:
|
|
- **Board**: "ESP32C6 Dev Module"
|
|
- **Upload Speed**: 921600
|
|
- **USB CDC On Boot**: **Enabled** ⚠️ **CRITICAL for serial output!**
|
|
- **Flash Size**: 4MB
|
|
- **Flash Mode**: DIO
|
|
- **Flash Frequency**: 80MHz
|
|
- **Partition Scheme**: Default 4MB
|
|
- **Port**: `/dev/ttyACM0` (ESP32-C6 typically uses ACM, not USB)
|
|
|
|
### 3. Open Project
|
|
|
|
1. Open **esp32_arduino.ino** in Arduino IDE
|
|
2. The IDE will create a folder with the same name automatically
|
|
|
|
### 4. Upload
|
|
|
|
1. Connect your ESP32-C6 board via USB
|
|
2. Check available ports: `ls -la /dev/ttyACM* /dev/ttyUSB*`
|
|
3. Select the correct **Port** in Tools menu (usually `/dev/ttyACM0`)
|
|
4. Click **Upload** button (→)
|
|
5. Wait for compilation and upload
|
|
6. Open **Serial Monitor** (Ctrl+Shift+M) and set to **115200 baud**
|
|
7. **Press the RESET button** on your board to see output
|
|
|
|
**Important**: If you see no serial output:
|
|
- Verify **USB CDC On Boot** is set to **Enabled**
|
|
- Press the physical RESET button on the board
|
|
- Make sure Serial Monitor is set to 115200 baud
|
|
|
|
## WiFi Configuration
|
|
|
|
WiFi credentials are already set in the code:
|
|
```cpp
|
|
const char* ssid = "Buon-Gusto_Nou";
|
|
const char* password = "arleta13";
|
|
```
|
|
|
|
## Features
|
|
|
|
### Web Interface
|
|
After upload, open your browser to the IP shown in Serial Monitor:
|
|
- Control panel with buttons
|
|
- Real-time status
|
|
- API documentation
|
|
|
|
### REST API Endpoints
|
|
|
|
#### Get Device Status
|
|
```bash
|
|
curl http://<ESP32_IP>/api/status
|
|
```
|
|
|
|
Response:
|
|
```json
|
|
{
|
|
"temperature": 25.3,
|
|
"wifi_rssi": -45,
|
|
"chip": "ESP32-C6",
|
|
"free_heap": 280000,
|
|
"uptime": 123,
|
|
"ip": "192.168.1.100",
|
|
"relay1": false,
|
|
"led": false
|
|
}
|
|
```
|
|
|
|
#### Control Relay
|
|
```bash
|
|
# Turn ON
|
|
curl -X POST http://<ESP32_IP>/api/relay/relay_1/on
|
|
|
|
# Turn OFF
|
|
curl -X POST http://<ESP32_IP>/api/relay/relay_1/off
|
|
|
|
# Get Status
|
|
curl http://<ESP32_IP>/api/relay/relay_1/status
|
|
```
|
|
|
|
#### Control LED
|
|
```bash
|
|
# Turn ON
|
|
curl -X POST http://<ESP32_IP>/api/led/led/on
|
|
|
|
# Turn OFF
|
|
curl -X POST http://<ESP32_IP>/api/led/led/off
|
|
```
|
|
|
|
## GPIO Pins
|
|
|
|
- **LED_PIN**: GPIO 8 (onboard LED)
|
|
- **RELAY_1_PIN**: GPIO 2 (relay control)
|
|
|
|
Modify these in the code if your board uses different pins.
|
|
|
|
## Troubleshooting
|
|
|
|
### Board Not Found in Arduino IDE
|
|
- Make sure you installed ESP32 board support (minimum version 3.0.0)
|
|
- Restart Arduino IDE after installation
|
|
|
|
### Upload Fails
|
|
- Check USB cable connection
|
|
- Select correct port in Tools → Port
|
|
- Try pressing BOOT button during upload
|
|
- Reduce upload speed to 115200
|
|
|
|
### WiFi Connection Fails
|
|
- Verify SSID and password
|
|
- Check if WiFi is 2.4GHz (ESP32-C6 doesn't support 5GHz)
|
|
- Check Serial Monitor for connection messages
|
|
|
|
### Can't See Serial Output
|
|
- Set Serial Monitor baud rate to **115200**
|
|
- Enable "USB CDC On Boot" in board settings
|
|
- Some boards need GPIO 0 held LOW during boot to enter programming mode
|
|
|
|
## Serial Monitor Output
|
|
|
|
Expected output after successful upload:
|
|
```
|
|
=================================
|
|
ESP32-C6 Home Assistant Device
|
|
=================================
|
|
GPIO initialized
|
|
Connecting to WiFi: Buon-Gusto_Nou
|
|
..........
|
|
✓ WiFi connected!
|
|
IP address: 192.168.1.100
|
|
RSSI: -45 dBm
|
|
MAC: AA:BB:CC:DD:EE:FF
|
|
|
|
✓ HTTP server started on port 80
|
|
|
|
=================================
|
|
Ready! Try these endpoints:
|
|
http://192.168.1.100/api/status
|
|
=================================
|
|
```
|
|
|
|
## Next Steps
|
|
|
|
1. Upload the code to your ESP32-C6
|
|
2. Note the IP address from Serial Monitor
|
|
3. Test the web interface in your browser
|
|
4. Integrate with Home Assistant using the custom component at `../custom_components/olimex_esp32_c6/`
|