0% found this document useful (0 votes)
16 views8 pages

ESP32 BMS Dashboard - PlatformIO Build & Flash Guide

This document provides a comprehensive guide for building and flashing an ESP32 BMS Dashboard using PlatformIO. It includes prerequisites, project setup instructions, hardware connections, troubleshooting tips, and methods for building and uploading the firmware. Additionally, it outlines first boot configurations and offers scripts for quick flashing on Windows and Linux/Mac systems.

Uploaded by

wongsuwan.punya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

ESP32 BMS Dashboard - PlatformIO Build & Flash Guide

This document provides a comprehensive guide for building and flashing an ESP32 BMS Dashboard using PlatformIO. It includes prerequisites, project setup instructions, hardware connections, troubleshooting tips, and methods for building and uploading the firmware. Additionally, it outlines first boot configurations and offers scripts for quick flashing on Windows and Linux/Mac systems.

Uploaded by

wongsuwan.punya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ESP32 BMS Dashboard - PlatformIO Build & Flash Guide

Prerequisites

1. Install Required Software


VSCode: Download from https://code.visualstudio.com/
PlatformIO Extension: Install from VSCode Extensions marketplace

CP210x USB Driver: For ESP32 communication (if needed)

2. Hardware Requirements
ESP32 Development Board (ESP32-WROOM-32)

MAX485 Module
USB Cable (Type-A to Micro-USB or USB-C depending on your ESP32)

Project Setup

1. Create New PlatformIO Project


1. Open VSCode

2. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac)

3. Type "PlatformIO: New Project"

4. Configure project:
Name: ESP32_BMS_Dashboard

Board: Espressif ESP32 Dev Module

Framework: Arduino

Location: Choose your preferred directory

2. Project Structure

ESP32_BMS_Dashboard/
├── src/
│ └── main.cpp # Main source code
├── platformio.ini # Project configuration
└── README.md

3. Configure platformio.ini
Replace the contents of platformio.ini with:
ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600

; Libraries
lib_deps =
emelianov/modbus-esp8266@^4.1.0
bblanchon/ArduinoJson@^6.21.3
tzapu/WiFiManager@^0.16.0

; Build flags
build_flags =
-DCORE_DEBUG_LEVEL=3
-DCONFIG_ARDUHAL_LOG_COLORS=1

; Monitor configuration
monitor_filters =
esp32_exception_decoder
time

; Flash settings
board_build.flash_mode = dio
board_build.flash_size = 4MB
board_build.partitions = default.csv

; Upload settings
upload_port = AUTO
monitor_port = AUTO

Building and Flashing

Method 1: Using PlatformIO GUI

Build Project:

1. Open the project in VSCode

2. Copy the Arduino code into src/main.cpp

3. Click the PlatformIO icon in the left sidebar

4. Under "PROJECT TASKS" → "esp32dev":


Click "Build" to compile the project
Wait for compilation to complete

Flash to ESP32:

1. Connect ESP32 to computer via USB


2. Press and hold BOOT button on ESP32

3. Click "Upload" in PlatformIO tasks


4. Release BOOT button when upload starts

5. Wait for upload completion

Method 2: Using PlatformIO Terminal Commands

Open Terminal:

In VSCode: Terminal → New Terminal

Make sure you're in the project directory

Build Commands:

bash

# Clean previous build


pio run -t clean

# Build project
pio run

# Build and upload


pio run -t upload

# Monitor serial output


pio device monitor

# Build, upload, and monitor (all in one)


pio run -t upload && pio device monitor

Method 3: Generate .bin File

Create .bin file:


bash

# Build project and generate .bin


pio run

# The .bin file will be located at:


# .pio/build/esp32dev/firmware.bin

Manual Flash using esptool:

bash

# Install esptool (if not already installed)


pip install esptool

# Flash the .bin file (replace COM3 with your port)


esptool.py --chip esp32 --port COM3 --baud 921600 write_flash 0x10000 .pio/build/esp32dev/firmw

# Full flash with bootloader (recommended for first flash)


esptool.py --chip esp32 --port COM3 --baud 921600 --before default_reset --after hard_reset wri

 

Hardware Connections

ESP32 to MAX485 Wiring:

ESP32 Pin → MAX485 Pin


GPIO4 → DE/RE (Direction Control)
GPIO16 → RO (Receiver Output)
GPIO17 → DI (Driver Input)
3.3V → VCC
GND → GND

MAX485 to BMS Wiring:

MAX485 Pin → BMS Modbus


A → A+ (Positive)
B → B- (Negative)

Troubleshooting

Common Issues:

1. Upload Failed
bash

# Solutions:
- Hold BOOT button during upload
- Try different baud rate: upload_speed = 115200
- Check USB cable and driver
- Verify COM port in Device Manager

2. Library Errors

bash

# Update libraries:
pio lib update

# Clean and rebuild:


pio run -t clean
pio run

3. Port Detection Issues

bash

# List available ports:


pio device list

# Specify port manually in platformio.ini:


upload_port = COM3 # Windows
upload_port = /dev/ttyUSB0 # Linux
upload_port = /dev/cu.usbserial-* # Mac

Debugging:

Monitor Serial Output:

bash

# Start serial monitor


pio device monitor

# Monitor with specific baud rate


pio device monitor --baud 115200

# Exit monitor: Ctrl+C

Enable Debug Output:


Add to platformio.ini :

ini

build_flags =
-DCORE_DEBUG_LEVEL=5
-DDEBUG_ESP_PORT=Serial
-DDEBUG_ESP_WIFI
-DDEBUG_ESP_HTTP_CLIENT

First Boot Configuration

1. WiFi Setup:
1. After flashing, ESP32 will create WiFi hotspot: "BMS_Monitor_Config"

2. Connect to this network with your phone/laptop


3. Browser will open configuration page automatically

4. Enter your WiFi credentials

5. ESP32 will connect and display IP address in serial monitor

2. Access Dashboard:
1. Note the IP address from serial monitor

2. Open browser and go to: http://[ESP32_IP_ADDRESS]

3. Dashboard will show BMS data if connected

3. API Endpoints:
Main Dashboard: http://[IP]/

JSON Data: http://[IP]/api/data

System Info: http://[IP]/api/system

Quick Flash Script


Create a batch file for Windows ( flash.bat ):
batch

@echo off
echo Building ESP32 BMS Dashboard...
pio run -t clean
pio run

echo.
echo Flashing to ESP32...
echo Please hold BOOT button on ESP32 now!
timeout /t 3
pio run -t upload

echo.
echo Starting serial monitor...
pio device monitor

For Linux/Mac ( flash.sh ):

bash

#!/bin/bash
echo "Building ESP32 BMS Dashboard..."
pio run -t clean
pio run

echo ""
echo "Flashing to ESP32..."
echo "Please hold BOOT button on ESP32 now!"
sleep 3
pio run -t upload

echo ""
echo "Starting serial monitor..."
pio device monitor

Production Build
For final deployment:
bash

# Build optimized release


pio run -e esp32dev --target upload

# Generate release files


mkdir release
cp .pio/build/esp32dev/firmware.bin release/
cp .pio/build/esp32dev/partitions.bin release/
cp .pio/build/esp32dev/bootloader.bin release/

The firmware will automatically scan for BMS devices on IDs 0-15 and display the detected BMS ID in the
web interface.

You might also like