TKK_E32231213/edasmart_esp32/README.md

117 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# EdaSmart ESP32 Firmware
Kode ini adalah firmware untuk ESP32 yang mengendalikan:
- **Mesin Press** (naik/turun/tahan dengan limit switch & sonar HC-SR04)
- **Mesin Penggiling** (timer + RPM via Hall Effect sensor)
- **LCD 20×4 I2C** sebagai UI utama
- **PCF8574** untuk ekspansi I/O (tombol & limit switch)
- **MQTT over TLS** ke HiveMQ Cloud
- **OTA firmware update** via Access Point
---
## Struktur File
```
edasmart_esp32/
├── edasmart_esp32.ino ← kode utama Arduino
├── config.h ← konfigurasi MQTT & pin (edit di sini)
└── README.md
```
---
## Konfigurasi
Edit `config.h` sebelum upload:
```cpp
// WiFi (bisa diset lewat UI LCD langsung)
// MQTT
#define MQTT_SERVER "8dd0d24eadfb4eb0b1e6fd87628f0f4e.s1.eu.hivemq.cloud"
#define MQTT_PORT 8883
#define MQTT_USER "Edasmart"
#define MQTT_PASS "KentangBalado1"
```
---
## Topik MQTT
### Publish (ESP32 → Backend)
| Topic | Nilai | Keterangan |
|--------------------------|---------------|--------------------------------|
| `edasmart/press/status` | `ON` / `OFF` | Status mesin press |
| `edasmart/press/phase` | `TURUN` dst | Fase gerakan press |
| `edasmart/press/sisa` | integer detik | Sisa waktu tahan |
| `edasmart/giling/status` | `ON` / `OFF` | Status mesin penggiling |
| `edasmart/giling/rpm` | integer | RPM penggiling (Hall sensor) |
| `edasmart/giling/sisa` | integer detik | Sisa waktu penggiling |
| `edasmart/estop` | `TRIGGERED` / `RELEASED` | Status emergency stop |
| `edasmart/device` | `ONLINE` | Device menyala (retained) |
### Subscribe (Backend → ESP32)
| Topic | Nilai | Keterangan |
|------------------------|--------|-------------------------|
| `edasmart/cmd/press` | `STOP` | Hentikan mesin press |
| `edasmart/cmd/giling` | `STOP` | Hentikan mesin penggiling |
---
## Library Arduino yang Dibutuhkan
Install via **Arduino Library Manager**:
- `PubSubClient` by Nick O'Leary
- `LiquidCrystal I2C` by Frank de Brabander
- `PCF8574` by Rob Tillaart
- `WiFi` (built-in ESP32)
- `Preferences` (built-in ESP32)
- `WebServer` (built-in ESP32)
- `Update` (built-in ESP32)
---
## Pin Mapping
| Fungsi | Pin ESP32 |
|------------------|-----------|
| SDA (I2C) | 21 |
| SCL (I2C) | 22 |
| ENA (Motor A PWM)| 32 |
| ENB (Motor B PWM)| 33 |
| IN1 | 25 |
| IN2 | 26 |
| IN3 | 27 |
| IN4 | 14 |
| RELAY_PRESS | 16 |
| RELAY_PENGGILING | 17 |
| BUZZER | 23 |
| LED BUILTIN | 2 |
| HALL SENSOR | 34 |
| TRIG HC-SR04 | 18 |
| ECHO HC-SR04 | 19 |
**PCF8574 (I2C, addr 0x20):**
| Fungsi | Pin PCF |
|--------------|---------|
| BTN_OK | P1 |
| BTN_BACK | P0 |
| BTN_UP | P3 |
| BTN_DOWN | P2 |
| BTN_ESTOP | P6 (NC) |
| BTN_LS_ATAS | P4 (NC) |
| BTN_LS_BAWAH | P5 (NC) |
---
## Upload
1. Buka `edasmart_esp32.ino` di Arduino IDE
2. Board: `ESP32 Dev Module`
3. Upload speed: `115200`
4. Setelah upload, set WiFi lewat menu **Setting → WiFi → Scan WiFi** di LCD