2018/09/04

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

This is the last of a 4-part series on how to develop Arduino ESP8266 firmware using VS Code and PlatformIO. This part deals with installing library, using the installed library in the main code, and compiling the main code.

To follow this part, be sure to follow Part 1 ~ 3 to create a project folder that has no space in its folder name.

Part 1 - https://wei48221.blogspot.com/2018/08/how-to-develop-arduino-esp8266-firmware.html

Part 2 - https://wei48221.blogspot.com/2018/08/how-to-develop-arduino-esp8266-firmware_31.html

Part 3 - https://wei48221.blogspot.com/2018/09/how-to-develop-arduino-esp8266-firmware.html

Install the library

1. Click on the "Install" button to install the library.


2. The library is now installed under the "PubSubClient_ID89" folder.


On my computer, the library is installed at the path below.

C:\Users\WeiHsiungHuang\Documents\PlatformIO\Projects\ESP8266_Arduino_Projects\.piolibdeps\PubSubClient_ID89


Create an entry for the newly installed library

1. Click on the "Installation" tab .


2. Scroll down to find the find the semantic versioning rules.


3. Copy the part highlighted in blue.


Paste the copied part to "platformio.ini".

Note that the spaces before "# Using a library name" and "PubSubClient" are important and they should not be removed. If they are removed, it will cause error during compilation time.

lib_deps =
  # Using a library name
  PubSubClient


Using the library in the code

1. Include the library in "main.cpp" by adding "#include <PubSubClient.h>".


2. Click on the "PlatformIO: Build" icon to start compiling the code. If all goes well, a "SUCCESS' message will appear after awhile.


Note,

If the library is removed from the folder but the content of  "lib_deps" still exists in "platformio.ini", PlatformIO will download the library then build the code.


Reference:

https://www.youtube.com/watch?v=_pSVzV4PdiA

No comments:

Post a Comment