Published © GPL3+

Raspberry Pi with Codesys PLC UI Controlling an Arduino

Use a Raspberry Pi with Codesys to control the LED on the EtherCAT Arduino Shield by Esmacat attached to an Arduino Uno.

BeginnerProtip1 hour8,218

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
Raspberry Pi to be used as EtherCAT Master with free open-source EtherCAT master code provided by Esmacat
Raspberry Pi Power Supply
Esmacat Master S
Optional EtherCAT Master
Esmacat Master C
Optional EtherCAT Master
Arduino UNO
Arduino UNO
EtherCAT Arduino Shield by Esmacat (EASE)
Ethernet Cable, Cat6a
Ethernet Cable, Cat6a
Power over Ethernet (POE) Injector
DC Adapter
For powering the POE injector

Software apps and online services

Arduino IDE
Arduino IDE
Software to program the Master PLC.


Read more


Physical Hardware Connection schematic

hardware setup after final connections

Hardware Setup Schematic

Schematic of the connection used in the tutorial



Code to be uploaded to Arduino board with EASE
  Codesys Onboard LED Control

  This sketch does the following:
  1) Controls the onboard led in Arduino using input from the EtherCAT master (Pi) using Codesys.
  2) Depending on the value updated in one of the EASE registers it does the following
      2.1) If the register value is 0 the led is turned off.
      2.2) If the register value is greater than 0, the led is turned on.      

  created 27 Jan 2020
  by Harmonic Binonics Inc. (  

#include <Esmacatshield.h>      //Include the Esmacat Arduino Library

# define ARDUINO_UNO_SLAVE_SELECT 10      // The chip selector pin for Arduino Uno is 10 

Esmacatshield ease_test(ARDUINO_UNO_SLAVE_SELECT);      // Create a slave object and specify the Chip Selector Pin

// Required variables Initialization
int led_state = 0,led_pin = 8,delay_time = 1000;
int ease_registers[8];   // EASE 8 registers

void setup() 
//  Serial.begin(9600);   // Begin Serial communication at the specified baud rate
  ease_test.start_spi();   // Start SPI for EASE

void loop()
  ease_test.get_ecat_registers(ease_registers);   // Update EASE registers with new data
  led_state = ease_registers[0];   // Assign register 0 value to variable
  delay_time = ease_registers[1];  
//  Serial.print("LED State is ");   
//  Serial.print(led_state);   // Print variable to the Serial monitor (for debugging)
  if(led_state == 1)

EtherCAT Master Code

Code to be run on Raspberry Pi using codesys (.project file)
No preview (download only).

EtherCAT Arduino Shield by Esmacat (EASE) Arduino Library

Esmacat Arduino Library




11 projects • 14 followers
Esmacat is an easy yet powerful EtherCAT solution for robotics. Our EtherCAT tech allow users to run EtherCAT applications in minutes!