Technical Details

M-DUINO PLC Arduino Ethernet 38R I/Os Relay/Analog/Digital PLUS

BACK TO THE PRODUCT

Initial Installation

ARDUINO IDE

Industrial controller Arduino IDE is the Original platform to program Arduino boards. This cross-platform application is available on Windows, macOS and Linux and under the GNU General Public License.
Arduino IDE supports C and C++ code structuring. Industrial Shields recommend using Industrial Arduino automation IDE to program Arduino Based PLC’s, but any Arduino industrial automation control system compatible software are compatible with Industrial Shields Controllers.

Apart from that, Industrial Shields bring the possibility to select your Arduino based PLC into your Arduino IDE and compile your sketches for
the different PLC controller (programmable logic controller)

Download the Arduino IDE 1.8.6:    

Windows Installer

MAC OSX

Install Industrial Shields units to Arduino IDE:

Industrialshields boards

Inputs & Outputs

ANALOG INPUTS

Voltage variation between –Vcc (or GND) and +Vcc, can take any value. An analog input provides a coded measurement in the form of a digital value with an N-bit number.  In Digital and Analog I/O there’s self insulation, so its posible to connect them in a different power supply than 24 V.  

Inputs:  (8x) 10bit – Analog (0-10Vdc) / Digital (7-24Vdc) configurable by software. 

To know more about analog inputs... 

TYPICAL CONNECTION

Arduino PLC Analog Imputs Typical Connection

DIGITAL INPUTS

Voltage variation  from  –Vcc (or GND)  to  +Vcc, with no intermediate values. Two states: 0 (-Vcc or GND) and 1 (+Vcc).  In Digital and Analog I/O there’s self insulation, so its posible to connect them in a different power supply than 24 V.  

Inputs:  (8x) 10bit – Analog (0-10Vdc) / Digital (7-24Vdc) configurable by software. 

All digital inputs are PNP.

To know more about digital inputs...


TYPICAL CONNECTION


- Digital Isolated Input


Arduino PLC Digital Isolated Imput Typical Connection 

- Digital no Isolated Input

Arduino PLC Digital No Isolated Imput Typical Connection

INTERRUPT INPUTS

Interrupt Service Rutine.  A mechanism that allows a function to be associated with the occurance of a particular event. When the event
occurs the processor exits immediately from the normal flow of the program and runs the associated ISR function ignoring any other task. 


Inputs:  (4x) Interrupt Input (7-24Vdc). “Can work like Digital Input (7-24Vdc)”.  


Interrupt Arduino Mega Pin M-Duino Pin
INT0 2 I0.0
INT1 3 I0.1
INT4 19 I1.1
INT5 18 I1.0

    - I0.0 and I0.1 also as Pin3 and Pin2. Enable Interrupts turning ON the switches number 3 and 4 of down communication switches.
    - I1.0 and I1.0 also as Tx1 and Rx1. Enable Interrupts turning ON the switches number 1 and 2 of up communication switches.

To know more about interrupt inputs...

TYPICAL CONNECTION

 Arduino PLC Interrupt Service Rutine TYPICAL CONNECTION


EXAMPLE

In this example we activate INT0 using pin I0_0 from M-duino board. When there’s a change  

#define INTERRUPT I0_0 //other pins: I0_1, I0_6, I2_6, I2_5, I1_6, I1_5 (M-Duino) I0_0, I0_3, I0_2, I0_1 (Ardbox)

volatile bool state = false;

void setup() {
  pinMode(INTERRUPT, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT), function_call_back, CHANGE);
}

void loop() {
  if (state == true){
    Serial.println("Interrupt activated");
    state = false;
  }
}

void function_call_back(){ //Change led state
  state = true;
}

Communications

Ethernet

Ethernet is the technology that is most commonly used 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.

Our M-Duino family incorporate the integrated W5500 IC.

WX5500 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. The W5500 chip embeds the 32Kb internal memory buffer for the Ethernet packet
processing. With this chip users can implement the Ethernet application by adding the simple socket program. SPI is provided for
easy integration with the external microcontroller.

Hardware  

Hardware configuration

*IMPORTANT: Make sure that your Ethernet PLC is powered (12-24Vdc). Just with USB is insufficient power to power up the
Ethernet communication.

 

Switch configuration

For the Ethernet communication protocol there isn’t any switch that affects it. So it does not matter the configuration of the
switches to implement Ethernet communication.

Used pins

For Ethernet communication protocol, the defined Arduino Mega pin is pin 10 , which is connected and already internally
assembled to the WX5500 Ethernet controller. W5500 IC communicates to the Mega board via SPI bus already assembled too.
You can
access easily to Ethernet port in our Ethernet PLCs, it is located at the top of the communications layer.

Ethernet hardware configuration must be plug and play.

Software

 

*IMPORTANT: Make sure to download the Arduino based PLC boards for Arduino IDE.

Software Configuration:

Once the hardware configuration is done, it is possible to proceed with the software configuration and also its usage. First it is necessary to include
the Ethernet2.h library provided by Industrial Shields (has the same functionality as Ethernet.h and also
the same usage).

#include <Ethernet2.h>
* Remember that for the V7 version or earlier versions you must use the <Ethernet.h> library.

Ethernet2 Library - functions.

* Ethernet2.h library has the same functions as Ethernet.h.


Example Codes:

Echo TCP Server:

Once the server is running, any client can connect to the server. On this example it is used an M-Duino to generate the server. The
example of TCP client showed before could be one of the clients.

Next it is showed the Arduino IDE code:

// use Ethernet.h if you have a M-Duino V7 version
#include <Ethernet2.h>
// mac address for M-Duino
byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Ip address for M-Duino
byte ip[] = { 192, 168, 1, 100 };
int tcp_port = 5566;
EthernetServer server = EthernetServer(5566);
void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip);
  // start server for listenign for clients
  server.begin();
}
void loop()
{
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client.available()) {
    // read bytes from the incoming client and write them back
    // to the same client connected to the server
    client.write(client.read());
  }
}

Echo TCP Client:

Once the server is running, M-Duino can connect to the server. On this example it is used an M-Duino to connect with the Node.js
server called server.js, the same as used on previous example link.

To configure the M-Duino, this post just follows the TCP example from Arduino web site with a few changes. To be able to connect to the server we must know the TCP server IP and the port where this server is listening.

Next it is showed the Arduino code:

#include <Ethernet2.h>
#include <SPI.h>
byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 100 };
byte server[] = { 192, 168, 1, 105 }; // Touchberry Pi Server
int tcp_port = 5566;
EthernetClient client;
void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  delay(1000);
  Serial.println("Connecting...");
  if (client.connect(server, tcp_port)) { // Connection to server.js
    Serial.println("Connected to server.js");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}
void loop()
{
  if (client.available()) {
    if(Serial.available()){
      char s = Serial.read();
      client.write(s); // Send what is reed on serial monitor
      char c = client.read();
      Serial.print(c); // Print on serial monitor the data from server
    }
  }
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;) ;
  }
}

Special Functions

RTC

 The term  real-time clock  is used to avoid confusion with ordinary hardware clocks which are only signals that govern digital electronics, and do not count time in human units. RTC should not be confused with real-time computing, which shares the acronym but does not directly relate to time of day.

Although keeping time can be done without an RTC, using one has benefits:

    - Low power consumption (important when running from alternate power
    - Frees the main system for time-critical tasks
    - Sometimes more accurate than other methods


There is a 3,3V  lithium coin cell  battery supplying the RTC.  M-Duinos RTC Module  is based on the  DS1307  Chip .  The  DS1307 serial real-time clock  (RTC) is a low-power, full binary-coded decimal  (BCD)  clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C , bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information.
The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.

To know more about the RTC...

Hardware Configuration


IMPORTANT:  Make sure that your Ethernet PLC is powered  (12-24Vdc) .

Switch configuration

RTC works with the  I2C  protocol communication, so it is required to have enabled the I2C protocol.  

4 switches  have to be configured in order to enable the  RTC features  and  I2C  communication: 


SWITCH ON OFF
NC - -
NC - -
RTC/SCL RTC -
RTC/SDA RTC -


RTC SCL  &  RTC SDA  must be set to ON mode to enable the I2C wires to the RTC. If they are in OFF mode, the Arduino won’t communicate with the RTC. 

Software Configuration


Once the hardware configuration is done, it's possible to proceed with the software configuration and also its usage. First it's necessary to include the RTC.h library provided in our boards (RTC.h includes I2C.h initialization, so it will not be necessary to initialize the I2C.h library): 

#include <RTC.h> 

To check if the RTC port is working it is easy to use the serial monitor from the Arduino IDE using the right sentence inside the setup() function: 

#Serial.begin(9600L) 

Example Code   

Basic RTC Test


// RTC library example
// by Industrial Shields
#include <RTC.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  if (!RTC.read()) {
    Serial.println("Read date error: is time set?");
    }
     else {
    Serial.print("Time: ");
    Serial.print(RTC.getYear());
    Serial.print("-");
    Serial.print(RTC.getMonth());
    Serial.print("-");
    Serial.print(RTC.getMonthDay());
    Serial.print(" ");
    Serial.print(RTC.getHour());
    Serial.print(":");
    Serial.print(RTC.getMinute());
    Serial.print(":");
    Serial.print(RTC.getSecond());
    Serial.print(" (");
    Serial.print(RTC.getTime());
    Serial.println(")");
  }
  delay(1000);
}