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

12 de marzo de 2024 por
Programming an ESP32 PLC board: Setting up PlatformIO IDE on Visual Studio Code
Boot & Work Corp. S.L., Francesc Nosas


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



Buscar en nuestro blog

Programming an ESP32 PLC board: Setting up PlatformIO IDE on Visual Studio Code
Boot & Work Corp. S.L., Francesc Nosas 12 de marzo de 2024
Compartir

¿Estás buscando tu Controlador Lógico Programable ideal?

Echa un vistazo a esta comparativa de producto de varios controladores industriales basados en Arduino.

Comparamos entradas, salidas, comunicaciones y otras especificaciones con las de los equipos de otras marcas destacadas.


Industrial PLC comparison >>>