Example Code for Arduino-USB to RS485 Transformation

The article provides a detailed guide on transforming Arduino USB to RS485, including hardware and software preparation, wiring diagrams, and sample code for seamless implementation.

Hardware Preparation

Please refer to the hardware connection above(but there is no need to install library).

Software Preparation

Wiring Diagram

Hardware Connection

Sample Code


*
This code realizes the function to transform Leonardo USB to 485. And you can also test it with other DF USB to 485 tools.
*/
void setup() {
  Serial.begin(19200); //Initializing Serial (i.e. USB serial)
  Serial1.begin(19200);//Initializing Serial
}
void loop() {
  while (Serial1.available()) {
    Serial.write(Serial1.read());//If Serial1 receives data, then Serial will output it.
  }
  while (Serial.available()) {
    Serial1.write(Serial.read());//If Serial receives data, then Serial1 will output it.
  }
  delay(1);//Short delay to avoid USB-COM instability
}

Host Computer Software

Click to download TC01 measurement tool.

Visual Display

Was this article helpful?

TOP