Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteris

Learning the basics about RS485 of an industrial PLC

Introduction

RS-485, also known as EIA-485, is defined as a differential multi-point bus system; it is perfect to transmit data with high speed to ranges until 12m. One of its most important characteristics is that the twisted pair of cables reduce the noise induced in the transmission line. Multiple receivers may be connected to such a network in a linear, multi-drop bus. These characteristics make RS-485 useful in industrial control systems and similar applications.

Our PLCs for industrial automation have insinde the integrated circuit MAX485. This one is a low power transceiver used for the communication RS-485 that works with a single power supply of 5V and the average current is 300μA. Using half-duplex communication to convert the TTL level in RS-485 level, it can reach the maximum speed of transmission of 2.5Mbps. Internally we can find a half duplex transceiver MAX485 and also a MAX485, in the way that, if we are in full duplex, it will use the half duplex MAX485 to receive data and the transmitter MAX485 will send it.


Previous reading

We recommend you to read the following posts in order to understand the program of this blog. We used the following blog posts to do this example:


Requirements

In order to work with RS-485 protocol, you will need any of our industrial PLC controllers for industrial automation:

Configuring the switches and jumpers

We have 2 families of PLCs: Mduino and Ardbox. 
On the Mduino family you will always have activated the RS-485 by default, so you will not need to activate it using any switch. The only thing is that you need to select between Full-Duplex and Half-Duplex, using the last switch (FD/HD).
 
For the Ardbox family programmable logic controllers, we have the two subfamilies:

In this one, we need to choose between RS-232 and RS-485 using the switches and jumpers as we show in the following image.

IMPORTANT : THE CONFIGURATION OF THE COMMUNICATION IS ALREADY DONE, YOU JUST NEED TO CHOOSE IT WHEN YOU BUY THE DEVICE 

Ardbox Analog HF+ 

 






Jumper zone 1: RS-232 / RS-485 HW.

Jumper zone 2: RS-232 SW / Q0.8 and Q0.9.

Ardbox Relay HF+ 


Jumper zone 1: RS-485 FD / A0.0 and A0.1.

Jumper zone 2: RS-232 SW / I0.2 and I0.3.

Jumper zone 3: RS-232 / RS-485.


Hardware

The first thing we need to do is to be sure that the industrial arduino PLC is supplied with 12-24Vdc.

Mduino family :
The pins of the PLC that we have to use for RS-485 communication.
 
 

 Ardbox family  :

Ardbox Analog HF+ :


Ardbox Relay HF+ :

 



Software

The first step is downloading the  Arduino based PLC boards for Arduino IDE.
After making the hardware configuration, we need to continue with the software configuration and also how we use it. To begin this process, it is necessary to include the library RS485.h  founded in our website. After this, in the function setup, please take care to do the right implementation of your communication

For all families:

Software configuration


#include <RS485.h>


To check the RS-485 activation you only have to use the serial monitor from the Arduino IDE using the right sentence inside the setup() function.

Serial.begin(9600); 


It is also important to implement the initialization on the setup() function.

RS485.begin(38400);

IMPORTANT : CHECK THE SPEED OF TRANSMISSION OF PLC-LAPTOP AND PLC-DEVICES .

Basic example of writing in the RS-485: 

// 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 example of reading of the RS-485: 

// 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 Full-duplex example of RS-485: 

Before start the test, connect A,B (receivers) to the Y, X (transmitters).

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

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.

Send