Uploading IoT Application From Command Line: Difference between revisions
Appearance
No edit summary |
|||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | == 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 === | === Prerequisites === | ||
# Install Python from https://www.python.org/downloads | # 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: | |||
<code> | <code> | ||
pip install esptool | pip install esptool | ||
</code> | </code> | ||
# Install Arduino IDE: https://www.arduino.cc/en/software | # Install the Arduino IDE from: https://www.arduino.cc/en/software | ||
=== Step 1: Compile the Sketch === | === Step 1: Compile the Sketch === | ||
# Open | # Open your `.ino` sketch in the Arduino IDE. | ||
# | # Go to: | ||
# | <code> | ||
# | Tools → Board → NodeMCU 1.0 (ESP-12E Module) | ||
</code> | |||
# Then export the compiled binary: | |||
<code> | |||
Sketch → Export Compiled Binary | |||
</code> | |||
# The binary file (e.g., <code>MySketch.ino.bin</code>) will appear in the same folder as your sketch. | |||
=== Step 2: | === Step 2: Identify the COM Port === | ||
# | # Connect your NodeMCU via USB. | ||
# Open | # Open the command prompt and type: | ||
<code> | <code> | ||
mode | mode | ||
</code> | </code> | ||
# Look for a line | # Look for a line similar to: | ||
<code> | |||
Status for device COM3: | |||
</code> | |||
- Note the COM port (e.g., COM3), which will be used in later steps. | |||
=== Step 3: Flash the Code === | === Step 3: Flash the Code to NodeMCU === | ||
# | # Navigate to the folder where your `.bin` file is saved: | ||
<code> | <code> | ||
cd "C:\Users\YourName\Documents\Arduino\MySketch" | cd "C:\Users\YourName\Documents\Arduino\MySketch" | ||
</code> | </code> | ||
# | # 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>MySketch.ino.bin</code> with the correct filename if different. | |||
=== (Optional) Erase Flash Before | === (Optional) Erase Flash Before Uploading === | ||
# If you want to erase previous data on the chip before uploading new code: | |||
<code> | <code> | ||
python -m esptool --port COM3 erase_flash | python -m esptool --port COM3 erase_flash | ||
</code> | </code> | ||
=== Notes === | === Notes === | ||
* | * Close the Arduino IDE's serial monitor before using the command-line monitor to avoid port conflicts. | ||
* If the command <code>esptool</code> or <code>miniterm</code> is not recognized, make sure Python's <code>Scripts</code> folder is added to your system PATH. | |||
* | * USB-to-Serial drivers such as CH340 or CP210x may be required depending on your NodeMCU model. | ||
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.