2018/08/31

How to develop Arduino ESP8266 firmware using VS Code and PlatformIO - Part 2

This is the 2nd part of a 4-part series on how to use VS Code and PlatformIO to develop for Arduino ESP8266.

Before proceeding further, be sure to follow the info. at http://wei48221.blogspot.com/2018/08/how-to-develop-arduino-esp8266-firmware.html to complete the installation of VS Code and PlatformIO.

Testing the Environment

1. Enter the code as shown below in "main.cpp".


2. Click on "platformio.ini" and enter the code from line 16 to line 20. Note that the code from Line 16 to Line 19 are for reference only. They are commented out by adding the ";' mark before them.

PlatformIO detects the port number automatically; hence, there is no need to specify the port number. However, the baud rate needs to be specified specifically using "monitor_speed = ". In this case, it's set to 115200 to match the baud rate in "main.cpp".


3. Click on the build icon to compile the code.


4. Click on the upload icon to upload to the ESP8266 NodeMCU board.


Below is the output message during the upload.

> Executing task in folder ESP8266 Arduino Projects: C:\Users\WeiHsiungHuang\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
--------------------------------------------------------------------------------------------
PackageManager: Installing tool-mkspiffs @ ~1.200.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
PackageManager: Installing tool-espotapy @ ~1.1.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 8266 > NodeMCU 1.0 (ESP-12E Module)
SYSTEM: ESP8266 80MHz 80KB RAM (4MB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 26 compatible libraries
Scanning dependencies...
No dependencies
Retrieving maximum program size .pioenvs\nodemcuv2\firmware.elf
Checking size .pioenvs\nodemcuv2\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [===       ]  34.8% (used 28500 bytes from 81920 bytes)
PROGRAM: [==        ]  24.8% (used 259144 bytes from 1044464 bytes)
Configuring upload protocol...
Looking for upload port...
Auto-detected: COM7
Uploading .pioenvs\nodemcuv2\firmware.bin
Uploading 263296 bytes from .pioenvs\nodemcuv2\firmware.bin to flash at 0x00000000
................................................................................ [ 31% ]
................................................................................ [ 62% ]
................................................................................ [ 93% ]
..................                                                               [ 100% ]
=============================== [SUCCESS] Took 44.54 seconds ===============================

Terminal will be reused by tasks, press any key to close it.

5. Click on the Serial Monitor icon to check the serial monitor output result.


--------------------------------------------------------------------------------------------------------------------------

Alternatively, instead of using the icons on the bottom, the commands could be issued from Command Palette. Click "View" then "Command Palette.." to invoke it.


Enter "platformio" for a list of all the commands available to PlatformIO. For example, enter "platformio: build" will compile the code in "main.cpp".


--------------------------------------------------------------------------------------------------------------------------

In case PIO Home is closed, it could either be opened by clicking on the home icon.


Or, launch a new terminal and open from there by:

1. Click on the "+" icon;

2. Select the project folder;


3. Enter "pio home" then hit enter in the new terminal.


In my case, an error occurs with the message "pio" is not recognized as an internal or external command, executable program or batch file.


Note to self: This seems to be path setting issue. Will find time to deal with it later.

Click here to go to part 3 of this series.

Reference:

#2 Working with PlatformIO - An IDE for IoT Apps
https://www.youtube.com/watch?v=fhEermOCrMo

No comments:

Post a Comment