Look for in our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

RS-485 test on Ardbox HF Family


Introduction


In this post it is showed how to test the RS-485 on Ardbox HF version.


Requirements


20 IOs PLC:          Ardbox Family Products


RS-485 Library:             Industrial Shields RS-485 Library (Github)


Configuration


The first thing that you need to know is that the  RS-485 HF version have half duplex and full duplex communication. Controlling the dip switch you must select if you want to work on full or half duplex. 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.

If you are working half duplex or full duplex the mapping is:

Max485Arduino Pins
RX (RO)RX Serial1 (0)
TX (DI)TX Serial1 (1)
RE (inverted logic)11
DE10

 

Software


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 with comment or uncomment “#define” command.

In half duplex sketch:

For transmitting:

#define TEST_RS485_TX
//#define TEST_RS485_RX

For receiving:

//#define TEST_RS485_TX
#define TEST_RS485_RX


Next it is showed the test code for full duplex:

int _rs485DE = 10;
int _rs485RE = 11;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
  Serial.println("Ardbox Analog HF RS-485 test started");
  
  Serial1.begin(9600L);
  pinMode(_rs485RE, OUTPUT);
  digitalWrite(_rs485RE, LOW);
  pinMode(_rs485DE, OUTPUT);
  digitalWrite(_rs485DE, LOW);
}
//////////////////////////////////////////////////////////////////////////////
void loop() {
  digitalWrite(_rs485DE, HIGH);
  Serial1.write(0x12);
  Serial1.flush();
  digitalWrite(_rs485DE, LOW);
  delay(1000);

  if (Serial1.available()) {
    if (Serial1.read() == 0x12) {
      Serial.println("RX");
    }
   }
}

 

Next it is showed the test code for half duplex:

int _rs485DE = 10;
int _rs485RE = 11;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600L);
  Serial.println("Ardbox Analog HF RS-485 test started");
  
  Serial1.begin(9600L);
  pinMode(_rs485RE, OUTPUT);
  digitalWrite(_rs485RE, LOW);
  pinMode(_rs485DE, OUTPUT);
  digitalWrite(_rs485DE, LOW);
}
//////////////////////////////////////////////////////////////////////////////
void loop() {
  digitalWrite(_rs485RE, HIGH);
  digitalWrite(_rs485DE, HIGH);
  Serial1.write(0x12);
  Serial1.flush();
  digitalWrite(_rs485DE, LOW);
  digitalWrite(_rs485RE, LOW);
  delay(1000);

  if (Serial1.available()) {
    if (Serial1.read() == 0x12) {
      Serial.println("RX");
    }
   }
}

See also:

 Ardbox Relay RS-485 Help Page 

Ardbox Analog RS-485 Help Page

RS-485 test on M-Duino plus

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