Jump to content

Uploading IoT Application From Command Line: Difference between revisions

From cognifront
Pooja (talk | contribs)
No edit summary
Pooja (talk | contribs)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Upload Code to NodeMCU (ESP8266) Using CMD ==
== 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 (Check "Add Python to PATH")
# Install Python from: https://www.python.org/downloads
# Install required tools:
  - 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 pyserial
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 the sketch in Arduino IDE
# Open your `.ino` sketch in the Arduino IDE.
# Select board: <code>NodeMCU 1.0 (ESP-12E Module)</code> under Tools → Board
# Go to:
# Go to Sketch → Export Compiled Binary
<code>
# A <code>.bin</code> file will be generated in the sketch folder
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: Find the COM Port ===
=== Step 2: Identify the COM Port ===
# Plug in NodeMCU
# Connect your NodeMCU via USB.
# Open Command Prompt and type:
# Open the command prompt and type:
<code>
<code>
mode
mode
</code>
</code>
# Look for a line like <code>Status for device COM3:</code>
# 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 ===
# Open CMD and go to the folder where the .bin file is located:
# 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>
# Upload the binary to NodeMCU:
# 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 Upload ===
=== (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 ===
* Make sure the COM port matches the one detected
* 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

  1. Install Python from: https://www.python.org/downloads
 - Make sure to check "Add Python to PATH" during installation.
  1. Open a command prompt and install the required Python packages:

pip install esptool

  1. Install the Arduino IDE from: https://www.arduino.cc/en/software

Step 1: Compile the Sketch

  1. Open your `.ino` sketch in the Arduino IDE.
  2. Go to:

Tools → Board → NodeMCU 1.0 (ESP-12E Module)

  1. Then export the compiled binary:

Sketch → Export Compiled Binary

  1. The binary file (e.g., MySketch.ino.bin) will appear in the same folder as your sketch.

Step 2: Identify the COM Port

  1. Connect your NodeMCU via USB.
  2. Open the command prompt and type:

mode

  1. 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

  1. Navigate to the folder where your `.bin` file is saved:

cd "C:\Users\YourName\Documents\Arduino\MySketch"

  1. 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

  1. 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 esptool or miniterm is not recognized, make sure Python's Scripts folder is added to your system PATH.
  • USB-to-Serial drivers such as CH340 or CP210x may be required depending on your NodeMCU model.