Industrial IoT controller · ESP32 or MKR WiFi 1010 · Wi-Fi and Bluetooth · 13 I/O
WIS-PLC industrial IoT controller: technical features
Complete technical reference of the WIS-PLC compact industrial IoT controller: power supply, DIP switches, analog and digital I/O, Ethernet, Wi-Fi, Bluetooth, RS-485, UART, SPI, I2C, RTC, microSD and multifunction pins, with wiring diagrams and Arduino IDE code.
- Power supply
- 12 to 24 Vdc, at least 0.8 A
- Programming
- Arduino IDE (ESP32 or SAMD package)
- Communications
- Ethernet, Wi-Fi, Bluetooth, RS-485 or UART, I2C, SPI
- Extras
- RTC (DS3231), microSD, multifunction pins, LoRa or NB-IoT variants
WIS-PLC overview
What is the WIS-PLC industrial IoT controller#
The WIS-PLC (brand name Weidos) is the compact industrial IoT controller range from Industrial Shields, built on an ESP32 or an Arduino MKR WiFi 1010. It is designed for IoT sensor nodes, remote monitoring and distributed wireless applications, with Wi-Fi and Bluetooth as standard. It is not a full-size PLC: it has 13 I/O points and is optimised for connectivity and low power.
It runs bare metal, with no operating system, and is programmed in C and C++ with the Arduino IDE. It includes Ethernet, Wi-Fi, Bluetooth, RS-485 or UART (selected by DIP switch), I2C, SPI, a microSD slot and a real-time clock. LoRa and NB-IoT are available as variants.
Certifications: CE, RoHS, LVD, EMC, RED and IEC 62311. When more than 13 I/O points or full machine control are needed, the ESP32 PLC is the larger option, from 14 to 61 I/O points on DIN rail.
Variants and I/O#
All variants have the same 13 I/O points. The analog inputs are convertible: they can be configured as 0-10 V or 4-20 mA.
| I/O type | Count |
|---|---|
| Analog / convertible inputs | 4 |
| Digital inputs | 4 |
| Digital outputs | 4 |
| Analog outputs | 1 |
| Total I/O | 13 |
| Variant | CPU | Connectivity |
|---|---|---|
| WIS ESP32 | ESP32 | Wi-Fi, Bluetooth, Ethernet |
| WIS MKR1010 | Arduino MKR WiFi 1010 | Wi-Fi, Bluetooth, Ethernet |
| WIS ESP32 LoRa | ESP32 | Standard plus LoRa |
| WIS MKR1010 LoRa | Arduino MKR WiFi 1010 | Standard plus LoRa |
| WIS ESP32 NB-IoT | ESP32 | Standard plus NB-IoT cellular |
| WIS MKR1010 NB-IoT | Arduino MKR WiFi 1010 | Standard plus NB-IoT cellular |
The LoRa and NB-IoT variants are available on request. See the WIS family page or download datasheets and user guides from the technical documentation.
Installation and setup
Programming with the Arduino IDE#
Arduino IDE is the original platform to program Arduino boards. This cross-platform application is available on Windows, macOS and Linux under the GNU General Public License. Arduino IDE supports C and C++ code structuring. In order to program the WIS-PLC in this environment, Industrial Shields provides a boards package with the necessary libraries and tools.
We recommend using the Legacy Arduino IDE (1.8.X) to program it, although other compatible software could be used. The Arduino 1.8.X IDE can be downloaded from the official Arduino software page.
After downloading and installing the Arduino IDE, install the industrialshields-wis-esp32 or the industrialshields-wis-samd boards package depending on the CPU of your PLC. This can be done by following this tutorial and selecting the corresponding package in step number 6.
Power supply: 12 to 24 Vdc#
The PLC needs an external power supply providing a voltage between 12 and 24 Vdc. Caution! Although at first glance it may seem like the PLC works when powered with the USB port, this is not the case. The usage of an external power supply is mandatory for the PLC to perform properly.
The measured consumption of the PLC is between 40 mA and 74 mA, but a supply of at least 0.8 A is recommended for good performance.
PSU specifications:
- Voltage: between 12 and 24 Vdc.
- Current: at least 0.8 A.
The diagram below shows the power connections: Vin+ on terminal 21 and Vin- on terminal 22.
Device overview and pinout#
Quick overview of the PLC pinout:
Left view:
Right view:
DIP switches SW1 and SW2#
Weidos devices have two DIP switches (SW1 and SW2) on one side. They select the operating mode of the RS-485/UART serial connector and the voltage of the multifunction pins.
To use the serial port as RS-485 or as UART, configure the switches this way:
To set the multifunction pins signal to 3.3 V or 5 V, configure the switches like this:
The positions of pins not shown in the table are not relevant.
Attention: disconnect the PLC from the power supply before changing the DIP switch configuration.
Power consumption#
Measured consumption of the PLC at idle and at full workload.
| Current (mA) | Power (W) | |
|---|---|---|
| Idle | 51,34 | 1,23 |
| Full workload | 73,9 | 1,77 |
WIS-PLC inputs and outputs
Digital inputs: 5 to 24 Vdc#
Digital inputs are used to capture signals that exist in one of two states: high or low, true or false, etc. The WIS-PLC digital inputs interpret as high values of 5 Vdc or higher, up to 24 Vdc, whereas values lower than 3.3 V are interpreted as low.
The digital input pins (DI_4 to DI_7) are on the following connector:
Typical wiring of a digital input using the voltage of the main power supply:
The digital inputs do not need to be configured in the setup part of the code. They can be read using the "digitalRead()" function, with the input name as its parameter. For example, DI_4:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(digitalRead(DI_4));
}
Analog/digital inputs: 0 to 10 Vdc#
The use of these inputs as analog or digital is selected via software by programming with the built-in functions analogRead() or digitalRead(). They do not depend on any external switch or additional hardware configuration. As Digital Inputs, these pins will detect HIGH state between 5 and 24 Vdc, in the same way as in the opto-isolated digital inputs. As Analog Inputs, these pins will detect the analog signal between 0 and 10 Vdc with a resolution of 12 bits by default (lower resolution can be set via software).
Typical wiring connection:
The maximum value of analogRead() is 4095, which represents 10 V. This is how to read them as both digital and analog:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Digital: ");
Serial.println(digitalRead(ADI_0));
Serial.print("Analog: ");
Serial.println(analogRead(ADI_0));
delay(1000);
}
Related: analog inputs of an industrial PLC, 4-20 mA calculator.
Digital outputs: up to Vin#
The PLC digital outputs can provide a low (0 Vdc) or high (up to Vin - 1) value. The high value comes from the voltage that is supplied to the PLC through Vin+, which can range from 11.4 V to 25.4 V. These outputs are labelled DO_X and are located on the following connector:
Typical wiring connection:
Example blink code:
void setup() {
}
void loop() {
digitalWrite(DO_0, HIGH);
delay(500);
digitalWrite(DO_0, LOW);
delay(500);
}
Related: digital outputs of an industrial PLC.
Analog output: 0 to 10 V#
The PLC has a single analog output, AO_0, that ranges from 0 V to 10 V. This is where it is located:
Typical wiring connection:
When coding in Arduino IDE, the values will range between 0 and 1023. This example code outputs a 5 V signal:
void setup() {
}
void loop() {
analogWrite(AO_0, 512);
}
Related: analog outputs of an industrial PLC.
Communications: Ethernet, Wi-Fi, Bluetooth, RS-485
Ethernet (W5500)#
Ethernet is the most commonly used technology in wired local area networks (LANs).
A LAN is a network of computers and other electronic devices that covers a small area such as a room, office, or building. It is used in contrast to a wide area network (WAN), which spans much larger geographical areas. Ethernet is a network protocol that controls how data is transmitted over a LAN. Technically it is referred to as the IEEE 802.3 protocol. The protocol has evolved and improved over time to transfer data at the speed of a gigabit per second.
The WIS-PLC incorporates an Ethernet port, using the W5500 controller, which communicates with the CPU using SPI. The W5500 is a Hardwired TCP/IP embedded Ethernet controller that provides easier Internet connection to embedded systems. This chip enables users to have Internet connectivity in their applications by using the single chip in which TCP/IP stack, 10/100 Ethernet MAC and PHY are embedded. With this chip users can integrate Ethernet into their applications.
Hardware setup
Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes an "Ethernet" library, intended to facilitate the use of this protocol. Various examples are included with the library, you can check them out going to File > Examples > Examples for WIS -> ETHERNET inside the Arduino IDE.
Call Ethernet.init(ETHERNET_CS) first, or the connection will not work. This is the StaticIPconfig example, which initializes the Ethernet shield and connects to the network with a static IP. It also checks for the presence of the Ethernet controller and whether the cable is connected. If properly configured, it periodically prints the IP address:
#include
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 110); // user defined Static IP
IPAddress myDns(8, 8, 8, 8);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200); // begin Serial
while(!Serial){} // wait for the Serial to be opened.
Serial.println("Example will run after 5 seconds.");
delay(5000);
Serial.println("Trying to connect. It can take a while!");
Ethernet.init(ETHERNET_CS); // initialize Ethernet with WIS Ethernet Chips Select.
Ethernet.begin(mac, ip, myDns, gateway, subnet);
// check if Ethernet hardware is present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware!");
while (true){}; //do nothing
}
else delay(2000);
if (Ethernet.linkStatus() == LinkOFF) Serial.println("Ethernet cable is not connected.");
}
void loop() {
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
delay(3000);
}
Related: HTTP requests to a server, MQTT client as an I/O module, Modbus TCP slave library, Modbus TCP master, Ethernet test.
Wi-Fi#
Similarly to other wireless connection types like Bluetooth, Wi-Fi is a radio transmission technology built upon a set of standards to allow high-speed and secure communications between a wide variety of digital devices, access points and hardware. It makes it possible for Wi-Fi capable devices to access the internet without the need for wires and it can operate over short and long distances, be locked down and secured, or open and free. This makes Wi-Fi versatile and easy to use.
Hardware setup
In case of using the MKRESP32 CPU, connect an antenna to the AN1 port. Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes a "WiFi" library, intended to facilitate the use of this protocol. Various examples are included with the library, you can check them out going to File > Examples > Examples for WIS -> WiFi inside the Arduino IDE.
This is the WiFiScan example, which scans for WiFi networks:
#include "WiFi.h"
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
}
void loop()
{
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}
Serial.println("");
// Wait a bit before scanning again
delay(5000);
}
RS-485 (half duplex)#
RS-485, also known as TIA-485(-A) or EIA-485, is a standard defining the electrical characteristics of drivers and receivers for use in serial communications systems. The PLC features half-duplex RS-485.
If you want to know more about RS-485, read Basics about RS-485 of an industrial PLC.
Hardware setup
To use RS-485 with the PLC, make sure the DIP switches are configured correctly: see DIP switches SW1 and SW2.
The RS485 pins on the PLC are 11 for A and 12 for B, which need to be properly connected to the device the PLC is communicating with. Attention! Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes an "RS485" library, intended to facilitate the use of this protocol. Various examples are included with the library, you can check them out going to File > Examples > Examples for WIS -> RS485 inside the Arduino IDE.
This is the RS485_send example:
#include
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 110); // user defined Static IP
IPAddress myDns(8, 8, 8, 8);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200); // begin Serial
while(!Serial){} // wait for the Serial to be opened.
Serial.println("Example will run after 5 seconds.");
delay(5000);
Serial.println("Trying to connect. It can take a while!");
Ethernet.init(ETHERNET_CS); // initialize Ethernet with WIS Ethernet Chips Select.
Ethernet.begin(mac, ip, myDns, gateway, subnet);
// check if Ethernet hardware is present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware!");
while (true){}; //do nothing
}
else delay(2000);
if (Ethernet.linkStatus() == LinkOFF) Serial.println("Ethernet cable is not connected.");
}
void loop() {
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
delay(3000);
}
This is the R485_recieve example:
#include
#define BAUDRATE 115200
void setup() {
Serial.begin(115200); //Begin Serial Monitor
while (!Serial); //Wait for the Serial Monitor
RS485.begin(BAUDRATE); //Begin RS485 with baudrate = BAUDRATE (115200)
RS485.setPins(RS485_TX, RS485_DE, RS485_RE); //Set WIS RS485 pins.
RS485.receive(); // enable reception, can be disabled with: RS485.noReceive();
}
void loop() {
if (RS485.available()) { //If there is data in the RS485 interface:
Serial.write(RS485.read()); //Read from the RS485 and print it to the Serial Monitor.
}
}
Related: RS-485 with Arduino and ESP32 based PLCs, RS-485 troubleshooting guide.
UART#
UART (Universal Asynchronous Receiver/Transmitter) is a widely used communication protocol in serial communication systems. It is commonly employed for transmitting data between microcontrollers, sensors, and other electronic devices over short distances, typically within a single circuit board or between nearby components. Unlike protocols that rely on synchronization, UART sends data asynchronously, meaning it does not use a shared clock signal. Data is transmitted one bit at a time at a set baud rate, with start and stop bits ensuring proper data alignment.
Hardware setup
To use UART with the PLC, make sure the DIP switches are configured correctly: see DIP switches SW1 and SW2.
The UART pins on the PLC are 11 for Tx and 12 for Rx. Attention! Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes a "UART" library, intended to facilitate the use of this protocol. Various examples are included with the library, you can check them out going to File > Examples > Examples for WIS -> UART inside the Arduino IDE.
This is the UART_send example:
void setup() {
UART.begin(115200);
}
uint8_t data[10] = {0,1,2,3,4,5,6,7,8,9};
void loop() {
for(int i = 0; i<10; i++){
UART.write(data[i]);
}
delay(5000);
}
This is the UART_recieve example:
void setup() {
Serial.begin(115200);
UART.begin(115200);
}
void loop() {
if(UART.available())
{
Serial.println(UART.read());
}
}
Bluetooth#
Bluetooth is a wireless technology standard. It was developed as a way to exchange data over a short range and it operates in the 2400-2483.5 MHz range within the ISM 2.4 GHz frequency band. Data is split into packets and exchanged through one of the 79 designed Bluetooth channels (each of which with a 1 MHz bandwidth).
In the PLC, the signal is switched between Wi-Fi and Bluetooth, so both cannot be used at the same time.
Hardware setup
In case of using the MKRESP32 CPU, connect an antenna to the AN1 port. Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes a "Bluetooth" library, intended to facilitate the use of this protocol, but it is still under development. Examples will be included with the library under File > Examples > Examples for WIS -> Bluetooth inside the Arduino IDE.
This example shows how to read and send bytes through Bluetooth using BluetoothSerial. The Serial port is used to send and receive data from the PC. To communicate with the PLC through Bluetooth a mobile app like "Serial Bluetooth Terminal" can be used. To do so, establish the Bluetooth connection with the PLC and select the device on the app.
void setup() {
UART.begin(115200);
}
uint8_t data[10] = {0,1,2,3,4,5,6,7,8,9};
void loop() {
for(int i = 0; i<10; i++){
UART.write(data[i]);
}
delay(5000);
}
SPI#
The Serial Peripheral Interface (SPI) is a synchronous serial communication interface specification used for short-distance communication, primarily in embedded systems. SPI devices communicate in full duplex mode using a master-slave architecture, usually with a single master. Three pins are used with SPI communication: SCLK, MOSI, MISO. Additionally, one extra pin for each slave, called chip select (CS) or slave select (SS) is used to select the slave that is being talked to in the bus.
The PLC features one SPI port. Its pins are 51:MISO, 52:MOSI, 53:SCK, 54:CS.
Hardware setup
Remember to power the PLC with a 12 to 24 Vdc power supply.
Software setup
The Industrial Shields boards package includes an SPI library, based on the Arduino SPI library. This library allows programming the PLC as an SPI master.
This program shows how to set up the PLC as a master in SPI communication, and send and receive data. In this case the character "0" is sent, and the received data is stored in the corresponding variable (SPI transfer is based on a simultaneous send and receive) and printed through the serial port.
#include
// Set pin as the slave select:
const int slaveSelectPin = CS;
volatile byte receivedData;
void setup() {
Serial.begin(9600);
// Set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
// Initialize SPI:
SPI.begin();
}
void loop() {
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));
digitalWrite(slaveSelectPin, LOW); // Start of transmission: set chip select LOW
receivedData = SPI.transfer('0');
digitalWrite(slaveSelectPin, HIGH); // End of transmission: set chip select HIGH
SPI.endTransaction();
Serial.println("rev");
Serial.println((char)receivedData);
delay(100);
}
Related: SPI bus on Industrial Shields PLCs.
I2C: 3.3 V#
I2C is a serial communications protocol. It is a master-slave synchronous protocol and 2 cables are used, one for the clock (SCL) and one for the data (SDA). The master controls the bus and creates the clock signal, and uses addressing to communicate with the slaves. It is widely used in industry, mainly to communicate microcontrollers and their peripherals in integrated systems, normally located in the same PCB. The speed is 100 Kbit/s in standard mode.
Hardware setup
The PLC has one I2C port, which has SCL and SDA pins. Other devices can be connected to this bus as slaves. When connecting other devices, keep in mind the following specifications:
- The I2C port works at 3.3 V. Higher voltage levels might damage the PLC.
- The I2C pins, SCL and SDA, are pulled up to 3.3 V.
The I2C pins are 61:SDA and 62:SCL. Also, remember to properly power the PLC with a suitable 12 to 24 Vdc power supply.
Software setup
The I2C can be used with the library "Wire". Check the following example which implements an I2C scanner that searches the bus for any connected devices. When a device is detected, it will be reported to the serial monitor. Note that if you connect the I2C pins (SDA and SCL) to another device, it should appear in the scan.
#include "Wire.h"
void setup() {
Serial.begin(115200);
Wire.begin();
}
void loop() {
byte error, address;
int nDevices = 0;
delay(5000);
Serial.println("Scanning for I2C devices ...");
for(address = 0x01; address < 0x7f; address++){
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
Serial.printf("I2C device found at address 0x%02X\n", address);
nDevices++;
} else if(error != 2){
Serial.printf("Error %d at address 0x%02X\n", error, address);
}
}
if (nDevices == 0){
Serial.println("No I2C devices found");
}
}
Related: I2C bus for industrial automation, set up external I2C.
Extra features: RTC, microSD, FreeRTOS
Real-time clock (DS3231)#
RTC stands for real-time clock, an electronic device that measures the passage of time. Although keeping time can be done without an RTC, using one has benefits such as:
- Maintaining the time without needing to set it again after a reboot, shutdown, etc.
- Low power consumption (important when running from alternate power).
- Frees the main control system for time-critical tasks.
- Sometimes more accurate than other methods.
The WIS-PLC includes a DS3231 RTC module, which communicates with the microcontroller using I2C. The DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted.
In order to power the RTC when the PLC is not connected, the PLC includes a 3.3 V CR1220 lithium coin cell battery which can be used to supply the RTC.
No hardware setup is needed in order to use the RTC, the only requirement is for the PLC to be properly powered using a 12 to 24 Vdc power supply, and to have a lithium coin cell battery to maintain the time when the PLC has no power.
Software setup
The RTClib library, included with our boards package, can be used to interact with the RTC. Check the following code example where time is read from the RTC and printed to the serial monitor.
Remember to make sure you have the industrialshields-wis-esp32/samd board package properly installed in your Arduino IDE.
#include
#include
RTC_DS3231 rtc; // Declare RTC DS3231
void printErrorNoRTC();
void setup () {
Serial.begin(115200);
while(!Serial){}
Serial.println("Example will run after 5 seconds.");
delay(5000);
// Check RTC is connected
if (! rtc.begin()) {
while (1) printErrorNoRTC();
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.day());
Serial.print('/');
Serial.print(now.month());
Serial.print('/');
Serial.print(now.year());
Serial.print(" ");
Serial.print(now.hour());
Serial.print(':');
Serial.print(now.minute());
Serial.print(':');
Serial.print(now.second());
Serial.println();
delay(1000);
}
unsigned long prevTime = 0;
void printErrorNoRTC(){
if(millis()-prevTime>3000){
Serial.println("No RTC Module");
prevTime = millis();
}
}
ESP32 dual core#
The WIS programmable logic controller can come with an ESP32-WROOM-32UE CPU, which allows dual core workloads. When we run code on Arduino IDE, by default, it runs on core 1, as we can check with this simple program:
void setup() {
Serial.begin(115200);
Serial.print("setup() running on core ");
Serial.println(xPortGetCoreID());
}
void loop() {
Serial.print("loop() running on core ");
Serial.println(xPortGetCoreID());
}
However, we can also use the second core, for better performance and efficiency. In order to work with the second core, we just need to define a second loop function, called "loop1()". The code inside this function will be executed by core 0, whereas the code inside the usual "loop()" function is executed by core 1. This way we can define different tasks for each core:
#include
// Task handles
TaskHandle_t Task1;
TaskHandle_t Task2;
// Function that runs on Core 0
void Task1code(void * parameter) {
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
for(;;) {
Serial.println("Hello from Task1");
delay(1000); // Simulate some work
}
}
// Function that runs on Core 1
void Task2code(void * parameter) {
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for(;;) {
Serial.println("Hello from Task2");
delay(1000); // Simulate some work
}
}
void setup() {
// Start serial communication
Serial.begin(115200);
delay(1000);
// Create Task1 on Core 0
xTaskCreatePinnedToCore(
Task1code, // Function to be called
"Task1", // Name of the task
10000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
&Task1, // Task handle
0); // Core 0
// Create Task2 on Core 1
xTaskCreatePinnedToCore(
Task2code, // Function to be called
"Task2", // Name of the task
10000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
&Task2, // Task handle
1); // Core 1
}
void loop() {
// Do nothing here
}
Organizing the program like this we can take advantage of the 2 cores. Some considerations need to be made when using the dual core, though, as concurrency problems may appear: for example if both try to use the Serial at the same time. To avoid these problems mechanisms such as semaphores might be used.
Related: how to use the ESP32 PLC dual core.
FreeRTOS#
FreeRTOS is a popular open-source real-time operating system (RTOS) designed for microcontrollers and small embedded systems. It provides a lightweight, scalable, and portable operating system kernel, along with a range of software components and tools to support the development of embedded applications.
With FreeRTOS, you can create multiple tasks in your sketch, each with its own priority, and use synchronization mechanisms like semaphores and mutual exclusion to coordinate the tasks. This can be useful for real-time applications that require precise timing and coordination of tasks.
There is no need to include any library to use FreeRTOS when using the MKRESP32 WIS-PLC, since it is integrated into ESP-IDF as a component (Arduino leverages ESP-IDF).
One of the most useful features of FreeRTOS are tasks, schedulable pieces of code. In order to create a task the function xTaskCreate() is used.
Software setup
This program creates 2 tasks to periodically set HIGH and LOW two digital outputs:
TaskHandle_t Task1;
TaskHandle_t Task2;
void setup() {
Serial.begin(115200);
pinMode(DO_0,OUTPUT);
pinMode(DO_1,OUTPUT);
xTaskCreate(Task1code,"Task1",10000,NULL,1,&Task1);
delay(500);
xTaskCreate(Task2code,"Task2",10000,NULL,1,&Task2);
delay(500);
}
void Task1code( void * parameter ){
Serial.print("Task1 is running on core ");
Serial.println(xPortGetCoreID());
for(;;){
digitalWrite(DO_0, HIGH);
delay(500);
digitalWrite(DO_0, LOW);
delay(500);
}
}
void Task2code( void * parameter ){
Serial.print("Task2 is running on core ");
Serial.println(xPortGetCoreID());
for(;;){
digitalWrite(DO_1, HIGH);
delay(1000);
digitalWrite(DO_1, LOW);
delay(1000);
}
}
void loop() {}
Related: FreeRTOS for multitasking with an Arduino based PLC.
MicroSD card#
Secure Digital (SD) cards are non-volatile memory storage devices that use flash memory technology. Designed for portable electronic devices, SD cards provide a reliable and compact solution for data storage.
The PLC incorporates an SD card slot with the following specifications:
- MicroSD slot.
- Up to 32 GB of storage (higher capacity cards can be used, but only the first 32 GB are accessible).
- FAT32 and FAT16 allowed as file system architectures.
The SD slot communicates with the PLC using SPI, and there is no hardware configuration needed. Remember to power the PLC with a 12 to 24 Vdc power supply.
The SD slot can be found on the upper plate of the PLC:
Software setup
The industrialshields-wis-esp32/samd boards package includes an SD library to facilitate its usage. Check the following example, which initializes the SD card and prints the contents of its root directory through the serial port.
#include
Sd2Card card;
SdVolume volume;
SdFile root;
void setup() {
Serial.begin(115200);
while (!Serial){}
delay(5000);
Serial.print("\nInitializing SD card...");
if (!card.init(SPI_QUARTER_SPEED)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
Serial.println();
Serial.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
}
Serial.print("Clusters: ");
Serial.println(volume.clusterCount());
Serial.print("Blocks x Cluster: ");
Serial.println(volume.blocksPerCluster());
Serial.print("Total Blocks: ");
Serial.println(volume.blocksPerCluster() * volume.clusterCount());
Serial.println();
uint32_t volumesize;
Serial.print("Volume type is: FAT");
Serial.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster();
volumesize *= volume.clusterCount();
volumesize /= 2;
Serial.print("Volume size (Kb): ");
Serial.println(volumesize);
Serial.print("Volume size (Mb): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Gb): ");
Serial.println((float)volumesize / 1024.0);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop() {
Serial.println("SD Info example has ended!");
Serial.print("If you have not seen the result printed in the Serial Monitor ");
Serial.println("run again the example and open the Serial Monitor within 5 seconds after the reset.");
delay(3000);
}
Multifunction pins: 3.3 or 5 V#
The multi-function pins accept different operational modes. They can be used as digital inputs, digital outputs, interrupts or PWM signals (defined in software with pinMode()).
MF pins operate at 3.3 Vdc or 5 Vdc (selected by switch). It is very important to check the configuration of the switches for the use of the multi-function pins before making the connection to verify the voltage in which they are configured.
Please check the following table to select the desired signal voltage level:
As described in the table above, only DIP switches 1, 2 and 3 of SW1 set the voltage of the multifunction pins. If they are all in the ON position, the pins operate at 3.3 Vdc, while if all switches are in the OFF position, they operate at 5 Vdc.
Multifunction pins are located in the following Weidos connector:
Software setup
The industrialshields-wis-esp32/samd boards package includes examples to facilitate its usage. Check the following example, which initializes the two multifunction pins as digital outputs:
void setup(){
Serial.begin(115200);
pinMode(pin41, OUTPUT);
pinMode(pin42, OUTPUT);
}
void loop() {
//Turn on LED's using connector pin number (pinXX)
digitalWrite((pin41), HIGH);
delay(2000);
digitalWrite((pin42), HIGH);
delay(2000);
//Turn off LED's using WIS pin names (MF_X)
digitalWrite((MF_0), LOW);
delay(2000);
digitalWrite((MF_1), LOW);
delay(2000);
}
Projects and resources
Courses, examples and documents#
- Free courses: First steps with MQTT, First steps with LoRa
- Interactive simulators: wireless sensor network, remote site telemetry, all simulators
- PLC solution library: choosing an industrial controller, 4-20 mA calculator
- Tutorials: WIS-ESP32 pinout time response, WIS-MKR1010 performance and time response
- Documents: WIS datasheets, user guides and certificates
Industrial IoT controller FAQ#
What is the WIS-PLC?
The WIS-PLC (Weidos) is a compact industrial IoT controller from Industrial Shields, built on an ESP32 or an Arduino MKR WiFi 1010. It has 13 I/O points and native Wi-Fi and Bluetooth, for IoT sensor nodes, remote monitoring and distributed field devices.
How do you program the WIS-PLC?
With the Arduino IDE in C and C++, after installing the industrialshields-wis-esp32 or the industrialshields-wis-samd boards package, depending on its CPU.
What power supply does the WIS-PLC need?
An external 12 to 24 Vdc supply of at least 0.8 A. The measured consumption is between 40 and 74 mA. USB power alone is not enough for the PLC to work properly.
Which I/O does the WIS-PLC industrial IoT controller have?
13 I/O points: 4 analog or convertible inputs, 4 digital inputs, 4 digital outputs and 1 analog output, plus 2 multifunction pins that work at 3.3 or 5 V.
Which communications does the WIS-PLC support?
Ethernet, Wi-Fi, Bluetooth, RS-485 or UART selected with DIP switches, I2C and SPI. LoRa and NB-IoT are available as variants.
When should I use an ESP32 PLC instead of a WIS-PLC?
When more than 13 I/O points are needed or the application is a full machine control system. The ESP32 PLC range offers 14 to 61 I/O points on DIN rail.
No section matches your search. Try a pin name, a protocol or a component.















