|| Back to Support & Help Documentation ||

WiFi PLC 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. Electrical signaling is balanced, and multipoint systems are supported.

Our Arduino Based PLCs incorporate the integrated circuit MAX485.

MAX485 is a low-power and slew-rate-limited transceiver used for RS-485 communication. It works at a single +5V power supply and the rated current is 300 μA. Adopting half-duplex communication to implement the function of converting TTL level into RS-485 level, it can achieve a maximum transmission rate of 2.5Mbps. MAX485 transceiver draws supply current of between 120μA and 500μA under the unloaded or fully loaded conditions when the driver is disabled. 

There is internally installed a half duplex MAX485 and MAX485 transmitter. If you are working on full duplex you will use the MAX485 half duplex to receive data and MAX485 transmitter to send the data.











MAX485 pin configuration and Typical Operating Circuit

Hardware

Check the WIFI PLC Family products now!

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

Switch configuration

For the RS-485 communication protocol there is only one switch that affects in this communication. The RS-485 protocol will be always enabled, the only switch that affects is the one called "FD rs-485 HD". This switch makes the choosing between RS-485 Half Duplex or RS-485 Full Duplex (RS-422).

Switch configuration 

"FD rs-485 HD" ON"FD rs-485 HD" OFF
Half DuplexFull Duplex

Used pins

For RS-485 communication protocol the defined Arduino Mega pins are showed in the chart below:

FUNCTION (MAX485)ARDUINO MEGA PIN
DI (TX)14 (TX Serial3)
RO (RX)15 (RX Serial3)
RE (Inverted logic)11
DE46

You can access easily to RS-485 pins in our Ethernet PLCs, you can see their position in the following image:

Connections

Connections will be different depending on whether we want to use RS-485 in half-duplex or full-duplex.

To do the full duplex test you must connect the A, B (receivers) to the Y, X(transmitters). For half duplex you must connect with another device with RS-485 and select if you want to transmit or receive data by Software (shown below).

Software

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

Software Configuration:
Once the hardware configuration is done, it's possible to proceed with the software configuration and also its usage. Firstable it's necessary to include the RS485.h library provided in our boards.

#include <RS485.h>

    To check if the RS-485 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(9600);

Then don’t forget to implement the proper initialization of your communication on the setup() function

RS485.begin(38400);

NOTE: Check the velocity of transmission between the PLC and the Laptop and from the PLC to the device connected by RS-485.

RS-485 Library - Functions

* Remember that all the devices have to communicate at the same baudrate.



RS485.begin(baud); //sets the baud rate for RS485 data transmision
RS485.read(); //reads incoming RS485 data
RS485.write(byteToSend); //write binary data to RS485 port
RS485.write(dataToSend, dataLength); //write binary data to RS485 port
RS485.available() //returns the number of bytes available for reading on RS485 port


 This is all it’s necessary to know to use RS-485 on Industrial Shields equipments. Finally it is showed an example using RS-485.


Example Codes


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:

* Remember that to do the full duplex test you must connect the 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);

  }

}

By following these steps carefully, you will be able to achieve the use of the RS-485 protocol using the Industrial Shields equipments.


1 Star 2 Star 3 Star 4 Star 5 Star