Programming an ESP32 PLC board: Setting up PlatformIO IDE on Visual Studio Code

March 12, 2024 by
Programming an ESP32 PLC board: Setting up PlatformIO IDE on Visual Studio Code
Boot & Work Corp. S.L., Frances Nosàs Moliner


In this Blog we'll learn how to set up the PlatformIO extension for VSCode in order to write code for an ESP32 PLC. This add-on offers a comfortable interface in VSCode to manage projects.


Before we start, however, be aware that any board version below 2.1.6 does NOT support PlatformIO.



1. Installing PlatformIO IDE in Visual Studio Code


We first need to have Visual Studio Code installed. If you don't have it, here's where to start: 


https://code.visualstudio.com/download


Once installed, we need to install the PlatformIO extension. Search for "Platformio IDE" on the extensions search tab of VSCode. Click install and wait until it's done. VSCode might ask of you to restart the app in order for the extension to be correctly updated.

 



2. Starting a new project


Follow the steps on the following link:


https://docs.platformio.org/en/latest/integration/ide/vscode.html#quick-start


You can choose any board you want, since we'll be changing it later manually.




3. Project configuration


3.1. Edit platformio.ini


We'll copy the following code onto platformio.ini. This is the bare minimum we need.


[env]
platform_packages=
framework-industrialshields-esp32@https://apps.industrialshields.com/main/arduino/boards/industrialshields-boards-esp32-X.X.X.tar.bz2

[env:board]
platform = https://github.com/Industrial-Shields/platform-industrialshields-esp32.git
board = esp32plc_57aar
custom_version = 3 ; or 1 custom_click1 = None ; or GPRS custom_click2 = None ; or GPRS
framework = arduino


3.1.1. Choose platform packages


We'll have to edit the link on the variable platform_packages with the board version we're using. We can consult all available packages in the following link: 


https://apps.industrialshields.com/main/arduino/boards/


Remember, it has to be 2.1.6 or above.




3.1.2. Choose board


Edit the variable board with the board we're using. We can consult all the compatible boards in the following link:


https://github.com/Industrial-Shields/platform-industrialshields-esp32/tree/main/boards





3.1.3. Change build flags


The variable build_flags calls the python file we added earlier. It's a shell command executing the python file, in which we can add some variables.

  • custom_version: an integer specifying the ESP32 PLC version. It's either 3 or 1. The usual version is 3, in very few situations you'll be using version 1.
  • custom_click1 and custom_click2: a string specifying the clicks used in the board. If a click is not being used, it must be set to "None".





With this, the project is set up and ready to code in.



4. Run examples


A set of examples are available in the GitHub Repository: 


https://github.com/Industrial-Shields/platform-industrialshields-esp32/tree/main/examples


4.1. Possible issues


99-platformio-udev.rules

If you're using Linux, VSCode might warn that you're missing the udev rules. To download this extension, write the following command on your terminal:

	​$ curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules

More information on 99-platformio-udev.rules



​Search in our Blog

Programming an ESP32 PLC board: Setting up PlatformIO IDE on Visual Studio Code
Boot & Work Corp. S.L., Frances Nosàs Moliner March 12, 2024
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>