3.9 1 1 1 1 1 1 1 1 1 1 Rating 3.90 (15 Votes)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

 CodesysRelease

 

Substantially, downloading the Codesys ISO image and installing it into the Raspberry SD card, it's possible to transform your PI into a PLC controller. And it's for free! (you can buy the "fully licensed version for 35€, anyway the demo version run fully featured for 2 hours).

So I though to realize a cheap fully working distributed architecture where:

  • Raspberry PI= PLC Controller (Codesys 3.5 SP
  • Arduino Mega 2560= 1st remote I/O
  • Arduino Uno=  2nd remote I/O
  • Modbus TCP/IP: communication protocol

CoDeSys+ Raspberry+ArduinoLogo+Banner-Modbus= (PLC + remote I/O) 

 

 Here following the hardware architecture (Fritzing diagram):Layout1

 Layout2

This is the breadboard's detail:

LayoutDetails

 

  • Arduino Mega 2560 + Ethernet Shield (IP:192.168.1.10) : remote I/O running as Server Modbus TCP
    • Out 2 is connected to Lamp 1
    • Out 3 is connected to Lamp 2
    • Out 4 is connected to Lamp 3
    • Analog Input 0 acquire 10k Thermistor

The video shows Lamps 1,2,3 turning On/Off depending of temperature (acquired by 10k Thermistor) OR by HMI (webVisu) push buttons

This is the Arduino Mega Code:

#include <Ethernet.h>
#include <SPI.h>
#include <Mudbus.h>
#include <avr/pgmspace.h>
#define THERM_PIN  0  // 10ktherm & 10k resistor as divider.
Mudbus Mb;

//Lamps
int Out2 = 2;
int Out3 = 3;
int Out4 = 4;

void setup() {   byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; // Define MAC address   byte ip[] = { 192, 168, 1, 11 }; // Define IP address   byte subnet[] = { 255, 255, 255, 0 }; // Define Subnet mask   Ethernet.begin(mac, ip, subnet); // Assign MAC, IP, and subnet mask   pinMode(Out2, OUTPUT); // assign Pin 2 as Output   pinMode(Out3, OUTPUT); // assign Pin 3 as Output   pinMode(Out4, OUTPUT); // assign Pin 4 as Output }void loop() {   Mb.Run(); // start MbTcp subroutine   // Digital OUT 2 (as Modbus Coil 1)   if (Mb.C[0] == HIGH) {     digitalWrite(Out2, HIGH);   }   else {     digitalWrite(Out2, LOW);   }   // Digital OUT 3 (as Modbus Coil 2)   if (Mb.C[1] == HIGH) {     digitalWrite(Out3, HIGH);   }   else {     digitalWrite(Out3, LOW);   }   // Digital OUT 4 (as Modbus Coil 3)   if (Mb.C[2] == HIGH) {     digitalWrite(Out4, HIGH);   }   else {     digitalWrite(Out4, LOW);   } }

 

  • Arduino Uno + Ethernet Shield (IP:192.168.1.11): remote I/O running as Server Modbus TCP
    • Out 2 is connected to Lamp 4
    • Out 3 is connected to Lamp 5
    • Out 4 is connected to Lamp 6

 

The video shows lamps 4,5,6 turning On/Off sequentially depending on Raspberry PI's Codesys Project

This is the Arduino Uno Code:

#include <Ethernet.h>
#include <SPI.h>
#include <Mudbus.h>
#include <avr/pgmspace.h>
#define THERM_PIN  0  // 10k therm & 10k resistor as divider.
Mudbus Mb;

//Lamps
int Out2 = 2;
int
Out3 = 3;
int Out4 = 4;

void setup() {   byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; // Define MAC address   byte ip[] = { 192, 168, 1, 11 }; // Define IP address   byte subnet[] = { 255, 255, 255, 0 }; // Define Subnet mask   Ethernet.begin(mac, ip, subnet); // Assign MAC, IP, and subnet mask   pinMode(Out2, OUTPUT); // assign Pin 2 as Output   pinMode(Out3, OUTPUT); // assign Pin 3 as Output   pinMode(Out4, OUTPUT); // assign Pin 4 as Output }void loop() {   Mb.Run(); // start MbTcp subroutine   // Digital OUT 2 (as Modbus Coil 1)   if (Mb.C[0] == HIGH) {     digitalWrite(Out2, HIGH);   }   else {     digitalWrite(Out2, LOW);   }   // Digital OUT 3 (as Modbus Coil 2)   if (Mb.C[1] == HIGH) {     digitalWrite(Out3, HIGH);   }   else {     digitalWrite(Out3, LOW);   }   // Digital OUT 4 (as Modbus Coil 3)   if (Mb.C[2] == HIGH) {     digitalWrite(Out4, HIGH);   }   else {     digitalWrite(Out4, LOW);   } }
  1. Raspberry PI (IP:DHCP) : Codesys 3.5-PLC controller running as Client Modbus TCP
    • Turns On/Off Lamps 1,2,3 depending of temperature (acquired by 10k Thermistor) OR by video (webVisu) push buttons
    • Tuns On/Off lamps 4,5,6 sequentially

      Codesys Code:

      • CodesysCode

        And HW configuration:

CodesysTree

 

 

Here follow I share the source code of the project hoping it can be hopeful for you!

Feel free to contact me if you have any questions or comments!

 

 

 

Attachments:
Download this file (Mega2560.7z)Merga2560_src[ ]0.8 kB4440 Downloads2014-10-17 20:36
Download this file (Raspberry.7z)Raspberry_src[ ]54 kB4031 Downloads2014-10-17 20:37
Download this file (Uno.7z)Uno_Src[ ]0.5 kB4211 Downloads2014-10-17 20:36