Jump to content

Uploading IoT Application From Command Line: Difference between revisions

From cognifront
Pooja (talk | contribs)
Created page with "== Deploy NodeMCU (ESP8266) Code via Command Line == === Prerequisites === # Install Python: https://www.python.org/downloads # Install esptool: <code> pip install esptool </code> # Install Arduino IDE: https://www.arduino.cc/en/software # (Optional) Install USB-to-Serial Drivers: * CH340: https://sparks.gogo.co.nz/ch340.html * CP210x: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers === Step 1: Compile Code === # Open your sketch in Arduino IDE # Go to..."
 
Pooja (talk | contribs)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Deploy NodeMCU (ESP8266) Code via Command Line ==
== 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: https://www.python.org/downloads
# Install Python from: https://www.python.org/downloads
# Install esptool:
  - 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
# (Optional) Install USB-to-Serial Drivers:
* CH340: https://sparks.gogo.co.nz/ch340.html
* CP210x: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers


=== Step 1: Compile Code ===
=== Step 1: Compile the Sketch ===
# Open your sketch in Arduino IDE
# Open your `.ino` sketch in the Arduino IDE.
# Go to: <code>Sketch → Export Compiled Binary</code>
# Go to:
# Find the <code>.bin</code> file in your sketch folder (e.g., <code>MySketch.ino.bin</code>)
<code>
 
Tools → Board → NodeMCU 1.0 (ESP-12E Module)
=== Step 2: Identify COM Port ===
</code>
# Plug in NodeMCU
# Then export the compiled binary:
# Open Command Prompt and run:
<code>
<code>
mode
Sketch → Export Compiled Binary
</code>
</code>
# Note your device COM port (e.g., <code>COM3</code>)
# The binary file (e.g., <code>MySketch.ino.bin</code>) will appear in the same folder as your sketch.


=== Step 3: Flash Firmware ===
=== Step 2: Identify the COM Port ===
# Navigate to your compiled sketch folder:
# Connect your NodeMCU via USB.
# Open the command prompt and type:
<code>
<code>
cd "C:\Users\<YourName>\Documents\Arduino\MySketch"
mode
</code>
</code>
# Flash the firmware:
# Look for a line similar to:
<code>
<code>
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin
Status for device COM3:
</code>
</code>
- Note the COM port (e.g., COM3), which will be used in later steps.


=== Optional: Erase Flash Before Writing ===
=== Step 3: Flash the Code to NodeMCU ===
# Navigate to the folder where your `.bin` file is saved:
<code>
<code>
python -m esptool --port COM3 erase_flash
cd "C:\Users\YourName\Documents\Arduino\MySketch"
</code>
</code>
# Run the following command to upload the binary:
<code>
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin</code>
- Replace <code>COM3</code> with your actual COM port.
- Replace <code>MySketch.ino.bin</code> with the correct filename if different.


=== Step 4: View Serial Monitor Output ===
=== (Optional) Erase Flash Before Uploading ===
# Install pyserial (if not already):
# If you want to erase previous data on the chip before uploading new code:
<code>
<code>
pip install pyserial
python -m esptool --port COM3 erase_flash
</code>
# View Serial Monitor:
<code>
python -m serial.tools.miniterm COM3 115200
</code>
</code>
# Press <code>Ctrl + ]</code> to exit


=== Notes ===
=== Notes ===
* Ensure no other serial monitor (like Arduino IDE) is open when using miniterm.
* Close the Arduino IDE's serial monitor before using the command-line monitor to avoid port conflicts.
* Make sure baud rate matches your <code>Serial.begin()</code> setting.
* 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.