Bonezegei RS485 to UART Library
Batutay, Jofel ยท 2023/11/03

Bonezegei RS485 is an Arduino library that enables the use of RS485 to UART converter modules based on the MAX485 chip. The library allows bidirectional communication between RS485 and UART devices, as well as read and write operations on both interfaces. The library supports half-duplex and full-duplex modes, as well as automatic direction control and collision detection. The library is compatible with boards that use the Serial or Bonezegei_SoftSerial classes. Follow the installation steps at https://bonezegei.com on how to install bonezegei libraries on Arduino IDE (Batutay, 2023).

Disclaimer

The code and libraries provided by Bonezegei is intended for informational and educational purposes only. Bonezegei does not own or manufacture the hardware associated with the code. The code is provided "as is" without any warranty, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall Bonezegei be liable for any claim, damages, or other liability arising from the use of the code or the hardware. Users are solely responsible for ensuring that their use of the code complies with all applicable laws and regulations.


1. Send And Receive

Using Microcontroller Serial Port

/*
  Sample for Read and Write data on RS485 Module 
  Author: Bonezegei (Jofel Batutay)
  Date: August 2023 
  8 bit word 1 Stop bit
*/

#include <Bonezegei_RS485.h>
#include <Bonezegei_SoftSerial.h>
#define PIN_DIR 4

//Change the Serial port to be use
Bonezegei_RS485 rs485(Serial2, PIN_DIR);

void setup() {
  Serial.begin(9600);
  rs485.begin(9600);

  //write strring to RS485 module
  rs485.println("Hello RS485");
}

void loop() {
  if (rs485.available()) {    //check if RS 485 data is available
    char ch = rs485.read();   //read data
    Serial.write(ch);
  }

  if (Serial.available()) {
    char ch = Serial.read();
    rs485.write(ch);          //write data
  }
}

2. Using Bonezegei_SoftSerial

Using Bonezegei_SoftSerial to interface as serial port

/*
  Sample for Read and Write data on RS485 Module (usinf Bonezegei SoftSerial)
  Author: Bonezegei (Jofel Batutay)
  Date: August 2023 

  8 bit word 1 Stop bit
*/

#include <Bonezegei_RS485.h>
#include <Bonezegei_SoftSerial.h>

#define PIN_RX 2
#define PIN_TX 3
#define PIN_DIR 4

Bonezegei_SoftSerial softserial(PIN_RX, PIN_TX); 
Bonezegei_RS485 rs485(softserial, PIN_DIR);

void setup() {
  Serial.begin(9600);
  rs485.begin(9600);

  //write strring to RS485 module
  rs485.println("Hello RS485");
}

void loop() {
  if (rs485.available()) {    //check if RS 485 data is available
    char ch = rs485.read();   //read data
    Serial.write(ch);
  }

  if (Serial.available()) {
    char ch = Serial.read();
    rs485.write(ch);          //write data
  }
}

References

  1. Batutay, Jofel. (2023). Arduino Library Installation. Bonezegei. https://bonezegei.com/?c=resources/tutorial&&d=resources/tutorial/libraries/install&&nav=1

Cite this

  1. Batutay, Jofel. (2023). Bonezegei RS485 : Arduino Library for RS485 to UART Converter using MAX485. ResearchGate. https://doi.org/10.13140/RG.2.2.19211.46886.