Browsed by
Category: Uncategorized

How to create a web server to read a SD card in our PLC

How to create a web server to read a SD card in our PLC

This is an example it is explain how to read a SD card into the PLC through Ethernet connection. In this post we will see how create a server that when there is a request through a browser, you can see the directories and the files of the SD card in your browser.

The PLC has to be connected the Ethernet connection and the SD card correctly, check this post how to do it.

Once it is all connected correctly the next step is make the right configuration of the Ethernet port and create the server:

 

/*
   Copyright (c) 2017 Boot&Work Corp., S.L. All rights reserved

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <MDUINO.h>
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>


#define SD_SS_PIN 3


File root;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80);

/////////////////////////////////////////////////////////////////////////////////
void setup() {
	Serial.begin(115200L);

  // Init Ethernet and TCP server
  Serial.println("Starting Ethernet ...");
  Ethernet.begin(mac);
  server.begin();

  // Init SD card
  Serial.println("Starting SD card ...");
  if (!SD.begin(SD_SS_PIN)) {
    Serial.println("initialization failed!");
    return;
  }

  Serial.print("IP address: ");
  Serial.println(Ethernet.localIP());
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  EthernetClient client = server.available();
  if (client) {
    char lastC = 0;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if ((c == '\n') && (lastC == '\n')) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println("Connection: close");
          client.println();
          client.println("SD card files:");

          root = SD.open("/");
          printDirectory(root, client);

          break;
        }
        if (c != '\r') {
          lastC = c;
        }
      }
    }
    delay(50);
    client.stop();
  }
}

////////////////////////////////////////////////////////////////////////////////
void printDirectory(File dir, Stream &stream) {
  while (true) {
    File entry = dir.openNextFile();
    if (!entry) {
      // no more files
      break;
    }

    stream.print(entry.name());
    if (entry.isDirectory()) {
      stream.println("/");
    } else {
      // files have sizes, directories do not
      stream.print(" [");
      stream.print(entry.size(), DEC);
      stream.println("]");
    }
    entry.close();
  }
}

See also:

How to connect a SD card to a PLC, How to connect the Ethernet port using W5100 library

 

Ardbox Relay Communication pinout configuration

Ardbox Relay Communication pinout configuration

plc-arduino-arbox-relay-20-dinArdbox Relay Communications pinout configuration

Ardbox Relay PLC integrates the following communications.

  • USB: Intrinsically available.
  • I2C: Enable SCL and SDA connections (actual Arduino pins) with configuration switches. I0.0 and I0.1 not available. In order to implement this communication a 4.7kΩ pull-up resistor (IS.ACI2C-4.7K) is required.
  • RS232: Enable RX and TX connections with configuration switches. 2 and I0.3 not available.
  • RS485: Enable RE/DE/DI and RO internal pins with configuration switches. R1, R2, R5 and R6 not available. The defined Arduino Mega pins are showed in the chart below.

RS485 pinout

Function

Arduino Pin

DI

10

RO

11

RE

4

DE

7

  • SPI: Enable pin 7, 4, 3 or 2. I2C or RS485 not available.

In LEFT Zone and TOP Zone  switches  the communications for Ardbox Relay can be enabled

See:

Ardbox Relay Switch Configuration

 

*NOTE: 

LEFT ZONE. To enable communication connections the switchs must be set to “OFF”. Set to “ON” position to enable I/Os  PLC connection.  Communications and I/Os on the chart can not work simultaneously. For exemple if DE is enabled (OFF),  R1 will not work. OFF position provides direct connection to Arduino Pin (NOT for TX and RX), so they can be programmed according to Arduino pin features.

TOP ZONE. Communications and relays can not work simultaneously. If R6 is enabled RO must be disabled and conversly.

Go to plc-arduino-arbox-relay-20-dinArdbox Relay Store page.

See also:
Communication ports, analog input, digital input, interrupt input, analog output, relay output.
Control of soil humidity in an irrigation installation

Control of soil humidity in an irrigation installation

This newsletter is really interesting because control soil humidity in irrigation installations makes saving water, time and money.  Continue reading… sch0   Hardware

Hardware selection is very important when you try to develop projects where sensors, actuators and PLC´s must talk each other. For this project, with chosen the following equipment:

  • PLC: Any PLC from IndustrialShields is a good option. We have chosen the M-Duino PLC Arduino 21 I/Os Analog/Digital because we think it has different communication options to be communicated with other systems (Ethernet, RS232, I2C…).
  • Panel PC: For this project, we are going to visualize and control our installation with the HummTouch 10.1” Linux panel pc.
  • Humidity sensor: Probably, when you try to develop an application like we are trying to, the most important selection is the sensor itself. There are a lot of humidity sensors available around the market completely compatible with Arduino based hardware. We´ve chosen the SHT10 sensor from Adafruit because it includes a temperature sensor as well, it comes with an intermetal mesh encasing, which is weatherproof and because it is designed to be submersible in water.
  •  Others: A relay to activate the irrigation system, a 24Vdc power supply, a good enclosure to protect the equipment and cables are important things to keep in mind too.

Software

To develop the project, the first thing to do is to ensure that we have the proper software and libraries. As we are going to use the SHT10 sensor, we will use the SHT1x library that you can download in the following link: https://github.com/practicalarduino/SHT1x. SHT10 uses a two wire communication interface similar to I2C. As usual, we will use the Arduino IDE to develop the software. You can download it here: http://www.arduino.cc/en/Main/Software. You can see the code in the following file: 2014111_arduino_code   Key benefits   There are a lot of benefits to implement a humidity control in an irrigation system. Let´s see the most important:

  • Saves Time: Automation does the job for you, so you can go on holidays knowing that your flowers will be maintained when you come back.
  •  Saves Money: No more water wasted, automation guarantees efficiency: water is used when is needed.
  •  Improves Growth: An irrigiation system guarantees flowers waterd with proper amount of water. In a reasonable time, you will have a greener garden.

  Contact us!

Do you have a process to be automated? Contact Industrialshields to buy the proper hardware and Opiron to implement the entire solution.

How to connect a 4-20mA to 0-10Vdc Analog Inputs

How to connect a 4-20mA to 0-10Vdc Analog Inputs

Have you got any analog signal 4-20mA? See the diagram below to know how to connect a 0-10Vdc Analog input.

  • Ardbox Analog or Ethernet PLC family products have some configurable Analog/digital input.conect4-20mA-to-0-10Vdc It is necessary to connect an impedance of 500 ohms between the 4-20mA analog signal and the ground signal. If you do that, the Analog value will be changed.

How is changing the Arduino input value

When you have a 4-20mA for 10bits you get these values:

4-20mA signal

10 bits

4mA

0 value

20mA

1023 value

but, if you convert this signal to 0-10Vdc, the results are:

4-20mA

0-10Vdc 10 bits
4mA 2Vdc

204 value* (aproximately)

20mA 10Vdc

1023 value

(*) As you can see, the result value of 4mA (i.e. 2Vdc), is about 204. You note that the line graph contains the result value. VdcValue

 

Contact us! Do you have a process to be automated? Contact Industrialshields to buy the right open source scalable hardware and to implement the entire solution.

HVAC System activated through an SCADA

HVAC System activated through an SCADA

Introduction

As a continuation of the Air-conditioning system post, in today´s newsletter Opiron suggests to expand the HVAC system controlled through the Touchberry Pi Panel PC and Ardbox Relay from IndustrialShields. As the last post, the suggested SCADA that will run on the Touchberry Pi is the following: myscadatechnologies.com PanelPcSummarizing the previous post, we designed a system that was able to activate the air conditioning with a relay. In order to expand the system, we will include the following sensors to have a complete automatic HVAC system:

  • Inside temperature.
  • Outside temperature.
  • PID development in order to control the inside temperature (the relay will be controlled by the PID loop).

Additionally, the air conditioning system will be integrated into a complete home automation solution where the Scada will give us access to a light system control, open and close windows, and security cameras. Software and code: Inputs and outputs definition

What are inputs and outputs from the coding point of view? As inputs we will consider the inside and outside temperature. As output, the relay that activates the air conditioning that we already programmed in the last post. As mentioned in the last post, the SCADA is owned by myscadatechnologies.com. Its main advantages are that is Open Source based, and very easy to be used. We will use I2C to communicate the SCADA and the Ardbox PLC. The code to be uploaded is the next one: 2014111_arduino_code SCADA design: Control Screen

Once we have already defined PLC programming, it is time to define the screen we will make the interaction between man and machine (HMI). Designing SCADAs really forces us to simplify and decide what’s most important- what needs to stay on the screen. As we want to implement an easy to use temperature control screen, we will show a thermometer with the actual temperature inside, and 4 big windows to see the basic features of the system. The first window with the temperatures inside and outside, at right, the system status window to have an easy access to alarms and other parameters, and below the temperature PID´s,  one for the day and the other one for the night. At the left of the screen we will have a menu to access to the other parts of the system (lighting, temperatures, windows, cameras and service). image12 Key Benefits

The main benefits of the this suggested solution are:

  • Automatic temperature regulation: The relay is now controlled by the PID!
  • Scalable system: The purposed system permits to connect multiple devices to the Touchberry Pi.
  • Open Source based: This feature means big flexibility, big availability of resources on the internet in case of failures or change implementations, etc.
  • Remote control: Control climate conditions through an HMI panel.
Contact us!

Do you have a process to be automated? Contact Industrialshields to buy the proper hardware and Opiron to implement the entire solution.

Developing a packaging machine based on Arduino hardware

Developing a packaging machine based on Arduino hardware

Abstract

Packaging machines are used to enclose and protect products for distribution, sale, and use. They are very popular in industry because they are safe, reliable, and usually integrated into the process line. They guarantee a big productivity.

In this project, Opiron Electronics will develop a basic packaging machine based on the Open Source Hardware PLC´s from IndustrialShields. Ardbox RelaySystem

Our packaging machine will have three basic control functions: HMI( the Human Machine Interface), PLC (the logic part of the control), and the Motion Control functionality. The main idea of the Project is to develop a reliable and flexible machine. We will make use of an Ardbox Relay as the main processor of the system, but, as packaging machines need to be integrated into more complex systems, as we saw in the Feeding a packaging machine with a frequency driver  post,  we will make use of an M-Duino PLC, which has Ethernet connectivity which can send data to an SCADA. The detailed hardware can be found at IndustrialShields the website.

packaging_machine_industrial_shields

 

Hardware and Operation

In this newsletter we are going to show just a part of the packing machine. This is a feeder and the lifter. The feeder consists of a piston, when a product is in front of the feeder, the feeder moves forward and the lifter downs a level. When the lifter is at the lower level, the entire product can be sent to the packaging part. PLC Programming Packing Machine_industrial_shields   The hardware components will be:

  1. Five mechanical switches (Reverse, forward, upper switch, middle switch and lower switch).
  2. 4 relays which are based in Arduino. 2 of them for the feeder (forward and reverse movement) and 2 more for the lifter (up and down movement).

Software and coding

As described above, the system works in six steps. Furthermore, the code has an additional but interesting feature: the capability to receive commands from another PLC (M-Duino), if an operator wants to stop the process remotely. Download the Arduino source code in the link below:   2014111_arduino_code    

Key benefits

  • Remotely control from another PLC capability.
  • Open Source hardware based, which it means reliable, cheap and expandable.
  • Easy to be installed.