A comprehensive, step-by-step guide to building, deploying, and debugging your ESP8266 + MPU6050 seismometer project entirely in Visual Studio Code.
- Prerequisites
- Repository Overview
- Setting Up Visual Studio Code
- Configuring the Arduino/ESP8266 Environment
- Client Sketch (ESP8266 MPU6050 Code)
- Server Setup (Flask API)
- Working with the Serial Monitor
- Debugging and Deployment
- Troubleshooting Common Issues
- License
- Visual Studio Code installed on your system
- Python 3.7+ (for Flask server)
- NodeMCU (ESP8266) board & MPU6050 sensor module
- USB cable for flashing ESP8266
ESP8266_MPU6050_Seismometer/
├── lib/ # Third-party Arduino libraries
├── src/ # Client .cpp sketch
│ └── ESP8266_MPU6050_Seismometer.cpp
├── server/ # Flask server files
│ ├── .env
│ ├── install.bat
│ ├── requirements.txt
│ ├── server.py
│ └── startup.bat
├── platformio.ini # PlatformIO project config
├── .gitignore
└── LICENSE
- Download the installer from Visual Studio Code and follow the standard installation process.
- Launch VS Code once installed.
Install these from the Extensions view (Ctrl+Shift+X
):
- PlatformIO IDE for embedded development with ESP8266 citeturn2search0
- C/C++ Extension Pack for IntelliSense and debugging citeturn2search8
- Python (ms-python.python) for Flask and scripting citeturn3search1
- Open Settings (
Ctrl+,
). - Enable PlatformIO › IDE: Toolbar to see Build/Upload icons.
- Set
python.pythonPath
to your interpreter (e.g.,${workspaceFolder}/.venv/bin/python
).
- Verify
platformio.ini
is present at the root. - Open the folder in VS Code—look for the PlatformIO alien-head icon.
- Use PlatformIO: Build (checkmark) to compile, and PlatformIO: Upload (arrow) to flash citeturn2search1turn2search2.
[platformio]
default_envs = nodemcuv2
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
lib_deps =
jrowberg/I2Cdev @ ^1.1.0
adafruit/MPU6050 @ ^1.4.3
default_envs
sets the environment for builds.board
andplatform
define toolchains for NodeMCU citeturn2search7.lib_deps
auto-downloads I2Cdev and MPU6050 libraries.
- Place local libraries in
lib/
, or uselib_deps
inplatformio.ini
. - After editing
platformio.ini
, PlatformIO fetches/update dependencies automatically when building.
See src/ESP8266_MPU6050_Seismometer.cpp
for:
- Wi-Fi Connection & MAC ID report
- MPU6050 Initialization & calibration
- Event Detection (
minor
,moderate
,severe
) - Health Check every 60s with HTTP GET to
ROOT_URL?id=<MAC>
- JSON POST of events to server endpoint
- Change into
server/
directory. - Copy
.env.example
to.env
and setPORT
,LOG_FILE
,MAX_LOG_BYTES
. - Run
install.bat
(Windows) or:python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt
- Start server:
python server.py
orstartup.bat
.
- PlatformIO Monitor: click the plug icon or run
PlatformIO: Monitor
. citeturn2search3 - Serial output shows real-time accelerometer Y,Z and boot/health messages.
- Set breakpoints in
server.py
and press F5 to run Flask in debug mode. - Use Debug Console to inspect variables during runtime.
- COM Port Access Denied: close other serial monitors or run VS Code as Administrator.
- Long Path Errors: move project to a shorter path (e.g.,
C:\Projects\ESPSeismo
) or enable Windows long paths via Group Policy citeturn3search10.
This project is licensed under the Apache-2.0 License.