Technical Details

​PLC Arduino Ardbox Analog & Ardbox Relay


Initial installation

Arduino IDE

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 Arduino IDE to program Arduino Based PLC’s, but any Arduino 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’s.

Download the Arduino IDE:

Official Arduino IDE page

Install Industrial Shields units to Arduino IDE:

How to install Industrial Shields Boards

Ardbox Version:

The Ardbox family consists of 2 main models:

Ardbox Analog

Ardbox Relay


In these models you can add communications (to choose at the time of purchase) such as:

  • WIFI & Bluetooth
  • GPRS
  • DALI
  • LoRa

And you can choose whether to have RS485 or RS232 communication, at the time of purchase.


The difference between these two PLCs is that, in the Relay model, a series of Relays are added while in the Analog model, analog pins are added.

Power supply


All Arduino based PLC's can be powered between 12-24V. Ardbox family, have a consumption between 700mA and 1500mA.


So, the recommended power supply is 2A or higher. Any Industrial power supply will be a good choice to power supply them.

REMEMBER:
Out units are designed to be powered between 12-24V. Just powering them with the USB, the unit will not be able to perform their features. USB is just to program the PLC's not to power them.

If, for some reason, you would like to use a power supply lower than 1.5A, contact Industrial Shields technical support to ensure that your system will complete your functionalities without any power issue.


Next is shown a simple diagram to see how to power supply any Industrial Shields unit.

Ardbox_Power_Supply

Switch ARDBOX ANALOG

Ardbox Analog has three different switch areas:

 LEFT Zone (Communication SWITCH):

SWITCH

ON

OFF

1 - SCL/Q0.6

Q0.6

SCL

2 - SDA/I0.0

I0.0

SDA

3 - RS485 RE/I0.9

I0.9

RS485 RE

4 - I0.9/RS485 RE

RS485 RE

I0.9

5 - RS485 DE/I0.8

I0.8

RS485 DE

6 - I0.8/RS485 DE

RS485 DE

I0.8

TOP Zone (RO-DI SWITCH):

SWITCH

ON

OFF

1 - Q0.8

Q0.8

RS (RS485)

2 - RS (RS485)

RS (RS485)

Q0.9

3 - Q0.9

Q0.9

RS (RS485)

4 - RS (RS485)

RS (RS485)

Q0.8

You cannot use both at the same time, therefore, if the outputs are ON, the RS (RS485) must be OFF and vice versa.

RIGHT Zone (D/A OUT SWITCH):

SWITCH

ON

OFF

1 - HD - FD

HALF DUPLEX

FULL DUPLEX

2 - Q0.6

DIGITAL (Q0.6)

ANALOG (A0.6)

3 - Q0.5

DIGITAL (Q0.5)

ANALOG (A0.5)

4 - Q0.4

DIGITAL (Q0.4)

ANALOG (A0.4)

1 - Q0.3

DIGITAL (Q0.3)

ANALOG (A0.3)

2 - Q0.2

DIGITAL (Q0.2)

ANALOG (A0.2)

3 - Q0.1

DIGITAL (Q0.1)

ANALOG (A0.1)

4 -Q0.0

DIGITAL (Q0.0)

ANALOG (A0.0)

The right zone configures the outputs. If the switch is set to "ON" the Q0.X will have the behavior of a digital output. If it is set to “OFF” it will be analog. There is also a switch for switching between Half and Full Duplex. It is “ON” for Half Duplex and “OFF” for Full Dupplex


Switch ARDBOX RELAY

Ardbox Relay has two different switch areas:

TOP Zone:

SWITCH

ON

OFF

1 - RS (RS485)

RS (RS485)

R8

2 - R8

R8

RS (RS485)

3 - RS (RS485)

RS (RS485)

R7

4 - R7

R7

RS (RS485)

RIGHT Zone:

SWITCH

ON

OFF

1 - NC

-

-

2 - HD-FD

HALF DUPLEX

FULL DUPLEX

3 - R5/SCL

R5

SCL

4 - I0.0/SDA

I0.0

SDA

1 - RE-RS485

RE-RS485

I0.4

2 - I0.4

I0.4

RE-RS485

3 - DE-RS485

DE-RS485

I0.5

4 - I0.5

I0.5

DE-RS485

Power consumption

Ardbox analog:


Current (mA)

Power (W)

Idle

41,3

0,99

Full workload

76,7

1,84

Ardbox relay:


Current (mA)

Power (W)

Idle

31,83

0,76

Full workload

149

3,57


Inputs & Outputs

Analog inputs

The analog inputs have a tolerance of 0 to 10 Vac with 10 bits of resolution, they are also isolated and sharing the internal GND. In Digital and Analog I/O there’s self insulation, so its posible to connect them in a different power supply than 24 Vdc. 

Ardbox Analog - Inputs: 6 or 8 Analog (0-10Vdc) configurable by Software.

If RS485 communication is used, which is configured by default, you will only have 6 analog inputs. If you want to have 8 analog inputs it must be configured in the left switch of the PLC, set I0.8 and I0.9 to ON and RS485 to OFF.

  int IO2 = analogRead(I0_2);
  int IO3 = analogRead(I0_3);
  int IO4 = analogRead(I0_4);
  int IO5 = analogRead(I0_5);
  int IO6 = analogRead(I0_6);
  int IO7 = analogRead(I0_7);
  int IO8 = analogRead(I0_8);
  int IO9 = analogRead(I0_9);

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.  

Ardbox Analog - Inputs:  8 or 10 Digital (5-24Vdc).

If RS485 communication is used, which is configured by default, you will only have 6 analog inputs. If you want to have 10 analog inputs it must be configured in the left switch of the PLC, set I0.8 and I0.9 to ON and RS485 to OFF.

  int IOO = digitalRead(I0_0);
  int IO1 = digitalRead(I0_1);
  int IO2 = digitalRead(I0_2);
  int IO3 = digitalRead(I0_3);
  int IO4 = digitalRead(I0_4);
  int IO5 = digitalRead(I0_5);
  int IO6 = digitalRead(I0_6);
  int IO7 = digitalRead(I0_7);
  int IO8 = digitalRead(I0_8);
  int IO9 = digitalRead(I0_9);

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. 

Ardbox Analog - Inputs:  (1x) Interrupt Inputs (5-24Vdc). “Can work like Digital Input (24Vdc)”.

Ardbox PinArduino Leornardo PinSwitch
I0.0 (INT0)2SDA/I0.0 at ON Position


In this example we activate INT0 using pin I0_0.

  #define INTERRUPT I0_0 // other pins: I0_3, I0_2, I0_1

  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;
  }

Analog outputs

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.  

Ardbox Analog - Outputs: 7 Analog 0-10V output and can convert 7 digital outputs to analog outputs, configurables by Right Switch.

  analogWrite(A0_0, 255);
  analogWrite(A0_1, 10);
  analogWrite(A0_2, 0);
  analogWrite(A0_3, 240);
  analogWrite(A0_4, 124);
  analogWrite(A0_5, 100);
  analogWrite(A0_6, 200);
  analogWrite(A0_7, 20);

  // CONFIGURE THE RIGHT SWITCH WITH ALL OUTPUT AS ANALOG(OFF)
  analogWrite(Q0_0, 182);
  analogWrite(Q0_1, 30);
  analogWrite(Q0_2, 50);
  analogWrite(Q0_3, 10);
  analogWrite(Q0_4, 0);
  analogWrite(Q0_5, 100);
  analogWrite(Q0_6, 255);

Digital outputs

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. 

Ardbox Analog - Outputs:  10 Digitals (5 to 24Vdc) and 7 of that 10 digital outputs can provide PWM (5 to Vdc).

  // CONFIGURE THE RIGHT SWITCH WITH ALL OUTPUT AS DIGITAL(ON)
  digitalWrite(Q0_0, HIGH);
  digitalWrite(Q0_1, LOW);
  digitalWrite(Q0_2, HIGH);
  digitalWrite(Q0_3, LOW);
  digitalWrite(Q0_4, HIGH);
  digitalWrite(Q0_5, HIGH);
  digitalWrite(Q0_6, LOW);
  digitalWrite(Q0_7, LOW);
  digitalWrite(Q0_8, LOW);
  digitalWrite(Q0_9, HIGH);

Relays

A relay is an electromagnetic switch controlled by an electric signal. In Industrial Shields units these devices are already integrated in their boards and can be accessible directly with the function digitalWrite(RX, HIGH). Industrial Shields relays are normally open and can handle a max current of 5A for max voltage 250Vac and 3A for a max DC voltage of 30Vdc.

Ardbox Relay - Outputs:  8 Relay outputs (220Vac – 5A). (R1, .. , R8)

  // Opens the relay switch
  digitalWrite(R1, HIGH);
  digitalWrite(R2, HIGH);
  digitalWrite(R3, HIGH);
  digitalWrite(R4, HIGH);
  digitalWrite(R5, HIGH);
  digitalWrite(R6, HIGH);
  digitalWrite(R7, HIGH);
  digitalWrite(R8, HIGH);

  delay(500);

  // Close the relay switch
  
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
  digitalWrite(R3, LOW);
  digitalWrite(R4, LOW);
  digitalWrite(R5, LOW);
  digitalWrite(R6, LOW);
  digitalWrite(R7, LOW);
  digitalWrite(R8, LOW);

PWM OUTPUT

Pulse Width Modulation. Activate a digital output for a while and keep it off for the rest. The average output voltage, over time, will be equal to the desired analogue value. The frequency between pulse is the same while the pulse width is changed.

A PWM Output gives a Vcc value during a certain time. 
Pay attention to the supply voltage, because the PWM output will have the same voltage difference.

Ardbox PinArduino Pin
Q0.63
Q0.55
Q0.46
Q0.39
Q0.210
Q0.111
Q0.013

    - Q0.0, Q0.1, Q0.2, Q0.3, Q0.4, Q0.5 and Q0.6 Digital/PWM out also as A0.0, A0.1, A0.2, A0.3, A0.4, A0.5 and A0.6 Analog out.

Module Pulses from Tools40 library

The Pulses module provides functions for starting and stopping a train of pulses at the desired frequency using PWM pins. The

startPulses(pin, frequency, precision)  function starts the train of pulses at the specified frequency and precision. The default frequency is 1kHz and the default precision is 3.

pinMode(3, OUTPUT);
startPulses(3, 2000, 3);

The  stopPulses(Pin)  function stops the train of pulses.

stopPulses(3);

IMPORTANT:
It is not possible to have different frequencies between the same TIMER Pin’s. Some outputs share the same timer, so they work at the same frequency.

CAUTION!!!
When the TIMER0 pins are used, all the time functions change their functionality as  delay() ,  millis() , micros() , delayMicroseconds()  and others.

Next it is showed recommended precision between different frequencies:

PrecisionFrequency Range (Hz)
130 - 150
2150 - 500
3500 - 4k
44k - 32k
532k - 4

To have a high precision on the desired frequency, it is recommended to use the closer precision to the values of the previous table.  Example Code 

In Ardbox RELAY there's no PWM Output.

Communication protocols

RS-485

 RS-485, also known as TIA-485(-A), EIA-485, is a standard defining the electrical characteristics of drivers and receivers for use in serial communications systems. The electrical signaling is balanced, and multi-point systems are supported.

Make sure you have your switches and jumpers configured properly before using this serial communication.

Example of use

Basic RS-485 write example (send):


// Include Industrial Shields libraries
#include <RS485.h>

//// IMPORTANT: check switches configuration

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
  Serial.begin(9600);

  // Begin RS485 port
  RS485.begin(38400);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait bytes in the serial port
  if (Serial.available()) {
    byte tx = Serial.read();

    // Echo the byte to the serial port again
    Serial.write(tx);

    // And send it to the RS-485 port
    RS485.write(tx);
  }
}

Basic RS-485 read example (receive):

// Include Industrial Shields libraries
#include <RS485.h>

//// IMPORTANT: check switches configuration

////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
  Serial.begin(9600);

  // Begin RS485 port
  RS485.begin(38400);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Print received byte when available
  if (RS485.available()) {
    byte rx = RS485.read();

    // Hexadecimal representation
    Serial.print("HEX: ");
    Serial.print(rx, HEX);

    // Decimal representation
    Serial.print(", DEC: ");
    Serial.println(rx, DEC);
  }
}

Basic RS-485 full-duplex example:

// Include Industrial Shields libraries
#include <RS485.h>
//// IMPORTANT: check switches configuration
//// IMPORTANT: Full duplex mode is only available when device supports it
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
  Serial.begin(9600);
  // Begin RS485 port
  RS485.begin(38400, FULLDUPLEX);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait bytes from the RS-485
  if (RS485.available()) {
    byte tx = RS485.read();
    // In full-duplex mode it is possible to send and receive data
    // at the same time in a secure way
    RS485.write(tx);
    // Echo the byte to the serial port
    Serial.write(tx);
  }
}

* Remember that to test the full duplex with your Ethernet PLC you must connect the A, B (receivers) to the Y, X(transmitters).

RS-232

RS-232, also known as TIA-232-F, EIA-232-F, or V.24, is a standard for serial communication transmission of data. It specifies the voltage levels, signal timing, and data protocol for communication between devices.

 

Make sure you have your switches and jumpers configured properly before using this serial communication.

Example of use

Basic RS-232 write example

// Include Industrial Shields libraries
#include <RS232.h>
//// IMPORTANT: check switches configuration
//////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  // Begin serial port
  Serial.begin(9600);
  // Begin RS232 port
  RS232.begin(38400);
}

///////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait bytes in the serial port
  if (Serial.available()) {
    byte tx = Serial.read();
    // Echo the byte to the serial port again
    Serial.write(tx);
    // And send it to the RS-232 port
    RS232.write(tx);
  }   
}

 Basic RS-232 read example

// Include Industrial Shields libraries
#include <RS232.h>

//// IMPORTANT: check switches configuration

//////////////////////////////////////////////////////////////////////////////////////////////

void setup() {

  // Begin serial port
  Serial.begin(9600);

  // Begin RS232 port
  RS232.begin(38400);

}

//////////////////////////////////////////////////////////////////////////////////////////////

void loop() {
  // Print received byte when available
  if (RS232.available()) {
    byte rx = RS232.read();

    // Hexadecimal representation
    Serial.print("HEX: ");
    Serial.print(rx, HEX);

    // Decimal representation
    Serial.print(", DEC: ");
    Serial.println(rx, DEC);
  }
}

I2C

I2C is a synchronous protocol that only uses 3 cables, one for the clock (SCL) and one for the data (SDA) and ground (GND). This means that the master and the slave send data through the same cable, which is controlled by the master, who creates the clock signal. I2C uses addressing to select slaves.

I2C is a serial communications bus. The speed is 100 kbit/s in standard mode, but also allows speeds of 3.4 Mbit/s. It is a very used bus in the industry, mainly to communicate microcontrollers and their peripherals in integrated systems, or to communicate integrated circuits that reside in a same PCB.

Make sure you have your switches and jumpers configured properly before using this serial communication.

Example of use

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

Simple example of scanning I2C:

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial); // Leonardo: wait for Serial Monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;
  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");
      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }

  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  
  delay(5000); // Wait 5 seconds for next scan
}

SPI

SPI is a synchronous communication protocol bus that has a master-slave architecture. Slave devices cannot initiate communication, nor exchange data with each other directly. Only the master can select to which slave will communicate with through the SS (slave select) pin.

Example of use

// include the SPI library:
#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode(slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 0; channel < 6; channel++) {
    // change the resistance on this channel from min to max:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, level);
      delay(10);
    }
    // wait a second at the top:
    delay(100);
    // change the resistance on this channel from max to min:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, 255 - level);
      delay(10);
    }
  }
}

void digitalPotWrite(int address, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin, LOW);
  // send in the address and value via SPI:
  SPI.transfer(address);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, HIGH);
}

Extra features

Direct Arduino Pins

If we want to use another Serial Port using your equipment, we can make use of some digital pins to create a Serial. The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality.  It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.

Only I/O 5V from Ardbox or M-Duino  boards can be used. 

M-Duino PinsLeonardo Pins
MISO14
MOSI16
SCK15


5VDC Signals

 These pins can be programmed according to Arduino features such as I/Os operating at 5V or any additional features present in the pins. 


    I2C Pins – SDA/SCL:

The I2C protocol is meant to work in a pull-up configuration. In this case it reads 5V when nothing is connected.

    SPI – MISO/MOSI/SCK:

These pins can only work as a 5V pins if the Ethernet protocol is not going to be used. As the Ethernet protocol uses the SPI to communicate with the Arduino board, both behaviours cannot happen at the same time as the Ethernet would not work.

    Pin2/Pin3:

These pins are only referred to the inputs I0.5/I0.6. If the switch configuration is in OFF position the pins Pin 2/Pin 3 will be available.