I'm having two maybe simple issues with my LCD.
-
I'm receiving carriage return and line feed symbols from my responding device (which I can not change) but I'm getting some weird symbols instead of the actual "" on the lcd screen. I've tried making some custom characters with an online generator but I'm unsure how to implement these into my code... The code is attached below.
-
Another issue after printing the "H FCM" command to the LCD, I should just be receiving back "*MICBAC" but I'm getting the command in my response too. this may be confusing for someone who comes to use the device in the future. I'm also not sure how to stop this from happening. (I'm guessing the Arduino is pulling the command from the serial port again and printing it out, is there away to stop/filter this out?). Video Attached - https://photos.app.goo.gl/9SvTbsxtTkiyDmLb8
//RS232 TA TOILET PROGRAM
#include <LiquidCrystal.h> //lcd library
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7; //lcd pinout
uint8_t p[] = { 0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02, 0x00 };
uint8_t h[] = { 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x00 };
uint8_t u[] = { 0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e, 0x00 };
uint8_t r[] = { 0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11, 0x00 };
uint8_t l[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f, 0x00 };
uint8_t f[] = { 0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10, 0x00 };
int button_h_fcm = 10; //sets H FCM button as digital pin #2
int button_d1 = 11; // sets D1 button as digital pin #3
int button_right = 12;
int button_left = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() { //starts Comms, lcd and button pinouts.
pinMode(button_h_fcm, INPUT); //sets pintype to input with an internal pull-up resistor
pinMode(button_d1, INPUT); //sets pintype to input with an internal pull-up resistor
lcd.begin(16, 2); //starts lcd and screen sizing
lcd.createChar(0, p);
lcd.createChar(1, h);
lcd.createChar(2, u);
lcd.createChar(3, r);
lcd.createChar(4, l);
lcd.createChar(5, f);
Serial.begin(9600); //starts comms and sets baudrate on serial monitor/usb
Serial1.begin(9600, SERIAL_7O2); //starts comms and sets baudrate on rs485 bus
}
void loop() {
if (Serial.available() > 0) { //prints incoming serial data and name tag to LCD and Serial monitor (for testing)
String rx = Serial.readString();
Serial.print("TOILET: ");
Serial.println(rx);
delay(3000);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("TOILET: ");
lcd.setCursor(0, 1);
lcd.print(rx);
}
if (Serial1.available() > 0) { //prints incoming serial1 data and name tag to LCD and Serial monitor (for toilet bus)
String rx1 = Serial1.readString();
Serial.print("TOILET: ");
Serial.println(rx1);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("TOILET: ");
lcd.setCursor(0, 1);
lcd.print(rx1);
}
if (digitalRead(button_h_fcm) == HIGH) { //prints specific command plus name tag to serial1, serial monitor and lcd.
Serial.println("H FCM");
Serial1.println("H FCM");
lcd.clear();
lcd.setCursor(4, 0);
lcd.write("COMMAND: ");
lcd.setCursor(5, 1);
lcd.write("H FCM");
delay(500);
}
if (digitalRead(button_d1) == HIGH) { //prinD1 startaddress stopaddress");
Serial1.println("D1 startaddress stopaddress");
lcd.clear();
lcd.setCursor(4, 0);
lcd.write("COMMAND: ");
lcd.setCursor(0, 1);
lcd.write("D1 startaddress stopaddress");
delay(500);
}
if (digitalRead(button_right) == HIGH) { //scrolls the lcd to the right
for (int pos = 0; pos < 15; pos++)
;
lcd.scrollDisplayRight();
lcd.setCursor(0, 1);
delay(200);
}
if (digitalRead(button_left) == HIGH) { //scrolls the lcd to the left
for (int pos = 0; pos < 15; pos++)
;
lcd.scrollDisplayLeft();
lcd.setCursor(0, 1);
delay(200);
}
}