mirror of
https://github.com/dustinbrun/ESP32_Modbus_RTU_Power_Meter.git
synced 2026-07-05 09:00:38 +00:00
188 lines
5.8 KiB
Markdown
188 lines
5.8 KiB
Markdown
# ESP32 Modbus RTU Power Meter
|
||
|
||
## Overview
|
||
|
||
This project implements a compact **ESP32 C3 Super Mini-based Modbus RTU power meter interface** designed for monitoring electrical measurements from Modbus-compatible energy meters. The system has been developed and tested using the **Chint DDSU666 Single-Phase Power Meter**, although it is intended to work with any Modbus RTU compliant power meter after appropriate configuration.
|
||
|
||
The device continuously reads measurement values from the power meter via an RS485 interface and provides multiple methods for visualizing the data:
|
||
|
||
- Local display using a 128 × 32 OLED screen
|
||
- Integrated Wi-Fi access point with a web interface
|
||
- Historical data visualization
|
||
- CSV export of recorded measurements
|
||
|
||
The compact enclosure is designed to fit inside a **1TE DIN rail distribution box**, making it suitable for electrical installations where space is limited.
|
||
|
||
<img src="pictures/device_1.jpg" width="600px">
|
||
|
||
<img src="pictures/device_2.jpg" width="600px">
|
||
|
||
|
||
### Features
|
||
|
||
- ESP32-C3 Super Mini based implementation
|
||
- Modbus RTU communication over RS485
|
||
- Compatible with the Chint DDSU666 and other Modbus RTU power meters
|
||
- Local real-time display on a 128 × 32 OLED
|
||
- Integrated Wi-Fi Access Point
|
||
- Web interface for monitoring live measurements
|
||
- Historical data visualization
|
||
- CSV export functionality
|
||
- Compact DIN rail enclosure (1TE)
|
||
|
||
|
||
### Power Meter
|
||
|
||
Developed and tested with:
|
||
|
||
- Chint DDSU666 Single-Phase Power Meter
|
||
|
||
The software should also operate with other Modbus RTU compatible power meters after adjusting the communication parameters and register definitions if necessary.
|
||
|
||
#### Modbus RTU Configuration
|
||
|
||
The following communication parameters must be configured on the power meter:
|
||
|
||
| Parameter | Value |
|
||
| -------------- | -------------------------- |
|
||
| Baud Rate | 9600 (DDSU666: **BAUD-3**) |
|
||
| Data Format | 8N1 |
|
||
| Device Address | 008 |
|
||
|
||
These settings can also be modified in the source code if different communication parameters are required.
|
||
|
||
### User Interface
|
||
|
||
#### OLED Display
|
||
|
||
The OLED display continuously shows the measured electrical values and is sized to fit within the 1TE enclosure.
|
||
|
||
<img src="pictures/display.jpg" width="400px">
|
||
|
||
|
||
#### Web Interface
|
||
|
||
The ESP32 operates as a Wi-Fi Access Point with the following default configuration:
|
||
|
||
- **SSID:** `PWR_METER`
|
||
- **Password:** None (open network)
|
||
- **Web Interface:** `http://192.168.4.1`
|
||
|
||
The web interface provides:
|
||
|
||
- Real-time measurements
|
||
- Historical graphical visualization
|
||
- CSV export of measurement data
|
||
|
||
<img src="pictures/webpage.png" width="600px">
|
||
|
||
|
||
## Hardware
|
||
|
||
### Schematic
|
||
|
||
The complete wiring schematic is shown below.
|
||
|
||
<img src="hardware/RS485_OLED_Schaltplan.png" width="600px">
|
||
|
||
### Enclosure
|
||
|
||
The original enclosure design is based on the following Thingiverse project:
|
||
|
||
**D1 Mini DIN Rail Case 1TE, RS485** by Hoich - https://www.thingiverse.com/thing:3337686
|
||
The original design is licensed under: **Creative Commons Attribution – NonCommercial – ShareAlike**
|
||
|
||
The enclosure has been modified to accommodate the OLED display. Additionally, a second flat enclosure variant has been created for applications where the OLED display is not required.
|
||
|
||
The modified enclosure is licensed under **CC BY-NC-SA 4.0**, while the original enclosure design remains subject to its original Creative Commons license.
|
||
|
||
<img src="case/1TE_Case_cleaned.png" width="400px">
|
||
|
||
<img src="case/1TE_Case_Flat-Case.png" width="400px">
|
||
|
||
### Assembly
|
||
|
||
The design does not require a dedicated printed circuit board (PCB).
|
||
|
||
All components are interconnected using point-to-point wiring inside the 3D-printed enclosure according to the schematic shown above.
|
||
|
||
<img src="pictures/wiring_1.jpg" width="600px">
|
||
|
||
<img src="pictures/wiring_2.jpg" width="600px">
|
||
|
||
|
||
## Software
|
||
|
||
### Software Architecture
|
||
|
||
The software consists of two independent parts:
|
||
|
||
1. **Firmware**
|
||
|
||
- Executes on the ESP32
|
||
- Reads Modbus RTU measurements
|
||
- Updates the OLED display
|
||
- Hosts the web server
|
||
|
||
2. **Web Resources**
|
||
|
||
- HTML
|
||
- CSS
|
||
- JavaScript
|
||
- -> These files are stored in the ESP32 LittleFS filesystem and served by the embedded web server.
|
||
|
||
The external libraries used by the project are referenced directly in the source code.
|
||
|
||
### Programming the ESP32
|
||
|
||
Both the firmware and the web resources must be uploaded.
|
||
|
||
1. **Step 1 – Upload the LittleFS Filesystem**
|
||
|
||
Install the LittleFS extension for Arduino IDE.
|
||
|
||
- Download the `.vsix` extension from: https://github.com/earlephilhower/arduino-littlefs-upload/releases/
|
||
- Copy the downloaded file into:
|
||
```
|
||
C:\Users\<USERNAME>\.arduinoIDE\plugins
|
||
```
|
||
(Create the folder if it does not already exist.)
|
||
|
||
Upload the filesystem:
|
||
|
||
- Press **CTRL + SHIFT + P**
|
||
- Select:
|
||
|
||
```
|
||
Upload LittleFS to Pico/ESP8266/ESP32
|
||
```
|
||
|
||
2. **Step 2 – Upload the Firmware**
|
||
|
||
Upload the ESP32 firmware using the standard **Upload** button in the Arduino IDE.
|
||
|
||
|
||
### Software Configuration
|
||
|
||
If required, the following parameters can be modified in the source code:
|
||
|
||
- Modbus slave address
|
||
- Baud rate
|
||
- Serial communication settings
|
||
- Supported Modbus register mapping
|
||
- Wi-Fi configuration
|
||
- Display behavior
|
||
|
||
|
||
## Sources/Useful Links
|
||
|
||
- ESP32-C3 Super Mini Pinout: https://sigmdel.ca/michel/ha/esp8266/super_mini_esp32c3_en.html
|
||
- Chint DDSU666 User Manual: https://chint.it/wp-content/uploads/product-docs/iStoragE/Manuali/iStoragE%20Meter%20DDSU666%20User%20Manual%20EN.pdf
|
||
|
||
- LittleFS support: https://randomnerdtutorials.com/arduino-ide-2-install-esp32-littlefs/
|
||
- The ESP32 firmware and web interface are based on examples from:
|
||
- https://randomnerdtutorials.com/esp32-websocket-server-sensor/
|
||
- https://randomnerdtutorials.com/esp32-web-server-gauges/
|
||
- https://github.com/ChartsCSS/charts.css
|
||
|