Library to interact with RS485 serial.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
1.1 KiB

/*
* Demonstrates how to use LCDisplay in conjunction with SoftRS485:
*
* The main _loop_ of this program listens on the RS485 bus.
* Whenever a message is received from the bus, it is displayed on the LCD.
*/
// include the library code:
#include <LiquidCrystal.h>
#include <SoftRS485.h>
// initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(115200);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("LCDReceive 1.0");
init485(2,3,8,9); // library initialization:
// connect pin 2 to RO of Max485
// connect pin 3 to ^RE of Max485
// connect pin 8 to DE of Max485
// connect pin 9 to DI of Max485
}
void loop() {
if (available485()) {
String s = get485message();
Serial.println(s);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(s);
if (s.length()>16) {
lcd.setCursor(0, 1);
s=s.substring(16);
s.trim();
lcd.print(s);
}
}
}