Uploading IoT Application From Command Line: Difference between revisions
Appearance
| (One intermediate revision by the same user not shown) | |||
| Line 43: | Line 43: | ||
# Run the following command to upload the binary: | # Run the following command to upload the binary: | ||
<code> | <code> | ||
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin | python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin</code> | ||
</code> | |||
- Replace <code>COM3</code> with your actual COM port. | - Replace <code>COM3</code> with your actual COM port. | ||
- Replace <code>MySketch.ino.bin</code> with the correct filename if different. | - Replace <code>MySketch.ino.bin</code> with the correct filename if different. | ||
| Line 54: | Line 53: | ||
python -m esptool --port COM3 erase_flash | python -m esptool --port COM3 erase_flash | ||
</code> | </code> | ||
=== Notes === | === Notes === | ||
Latest revision as of 09:39, 6 June 2025
Uploading Code to NodeMCU (ESP8266) via Command Line
This guide explains how to compile and upload code to a NodeMCU (ESP8266) board using the command line, and how to monitor its serial output without using the Arduino IDE interface.
Prerequisites
- Install Python from: https://www.python.org/downloads
- Make sure to check "Add Python to PATH" during installation.
- Open a command prompt and install the required Python packages:
pip install esptool
- Install the Arduino IDE from: https://www.arduino.cc/en/software
Step 1: Compile the Sketch
- Open your `.ino` sketch in the Arduino IDE.
- Go to:
Tools → Board → NodeMCU 1.0 (ESP-12E Module)
- Then export the compiled binary:
Sketch → Export Compiled Binary
- The binary file (e.g.,
MySketch.ino.bin) will appear in the same folder as your sketch.
Step 2: Identify the COM Port
- Connect your NodeMCU via USB.
- Open the command prompt and type:
mode
- Look for a line similar to:
Status for device COM3:
- Note the COM port (e.g., COM3), which will be used in later steps.
Step 3: Flash the Code to NodeMCU
- Navigate to the folder where your `.bin` file is saved:
cd "C:\Users\YourName\Documents\Arduino\MySketch"
- Run the following command to upload the binary:
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin
- Replace COM3 with your actual COM port.
- Replace MySketch.ino.bin with the correct filename if different.
(Optional) Erase Flash Before Uploading
- If you want to erase previous data on the chip before uploading new code:
python -m esptool --port COM3 erase_flash
Notes
- Close the Arduino IDE's serial monitor before using the command-line monitor to avoid port conflicts.
- If the command
esptoolorminitermis not recognized, make sure Python'sScriptsfolder is added to your system PATH. - USB-to-Serial drivers such as CH340 or CP210x may be required depending on your NodeMCU model.