Ardunio (soft serial) connect to Smart LCD
background

- Smart LCD mainly provide RS-232C as interface terminal.
- Arduino board hardware UART with level-shifter (eg.MAX3232) can connect Smart LCD in standard way.
- But the connections conflicts with Arduino Serial Monitor for debugging.
- Where, it can use a soft_serial for Smart LCD command instead. (Soft_serial on Arduino UNO cannot run 115200bps.)
how to
- Config the Smart LCD RS-232C terminal as 38400bps (the highest speed of Arduino UNO soft_serial baud rate)
- Use the following Arduino UNO code for communication example
<code>// TOPWAY Smart LCD interface with Arduino UNO // Arduino UNO code used in video (for reference only) #include SoftwareSerial mySerial(10, 11); // RX=10, TX=11 (SW) // RX=0, TX=1 (HW) int temp_h=0; int temp_l=0; int writeback_h=0; int writeback_l=0; int packet_OK=0; void setup() { // put your setup code here, to run once: // start serial port at 115200 bps: Serial.begin(115200); while (!Serial) { ;} // wait for serial port to connect. Needed for native USB port only // set the data rate for the SoftwareSerial port mySerial.begin(38400); }
void loop() { // put your main code here, to run repeatedly: while (mySerial.available()) {char dummy=mySerial.read();}// clear serial buffer mySerial.write((byte)0xaa); // packet head mySerial.write((byte)0x3e); // VP_N16 read command mySerial.write((byte)0x00); // VP_N16 address mySerial.write((byte)0x08); mySerial.write((byte)0x00); mySerial.write((byte)0x00); mySerial.write((byte)0xcc); // packet tail mySerial.write((byte)0x33); // packet tail mySerial.write((byte)0xc3); // packet tail mySerial.write((byte)0x3c); // packet tail
while (!mySerial.available()) {} if (mySerial.read()==0xaa) { // packet head packet_OK=1; while (!mySerial.available()) {} if (mySerial.read()==0x3e) { // packet command while (!mySerial.available()) {} temp_h=mySerial.read(); // read back value high byte while (!mySerial.available()) {} temp_l=mySerial.read(); // read back value low byte while (!mySerial.available()) {} if (!(mySerial.read()==0xcc)) {packet_OK=0;} // packet tail while (!mySerial.available()) {} if (!(mySerial.read()==0x33)) {packet_OK=0;} // packet tail while (!mySerial.available()) {} if (!(mySerial.read()==0xc3)) {packet_OK=0;} // packet tail while (!mySerial.available()) {} if (!(mySerial.read()==0x3c)) {packet_OK=0;} // packet tail } else {packet_OK=0;} } else {packet_OK=0;} if (packet_OK){ Serial.print(temp_l,DEC); Serial.print("\n"); writeback_h=temp_h; writeback_l=temp_l; mySerial.write((byte)0xaa); // packet head mySerial.write((byte)0x3d); // VP_N16 write command mySerial.write((byte)0x00); // VP_N16 address mySerial.write((byte)0x08); mySerial.write((byte)0x00); mySerial.write((byte)0x02); mySerial.write((byte)writeback_h); // VP_N16 data high byte mySerial.write((byte)writeback_l); // VP_N16 data low byte mySerial.write((byte)0xcc); // packet tail mySerial.write((byte)0x33); // packet tail mySerial.write((byte)0xc3); // packet tail mySerial.write((byte)0x3c); // packet tail } for (int i = 0; i<=20; i++) {delayMicroseconds(1000);} }>/code>
note.
- It is suggested to use hardware serial for production application
- mySerial.write(0x00); and Serial.write(0x00); may not correctly compile mySerial.write((byte)0x00); and Serial.write((byte)0x00); can be correct
- Clear UNO's serial buffer before send command can improve working efficiency
downloads
- Example Model: HMT070ATA-1C
- Example Video: youtu.be/9lg5i9_ERBk (2:28)
- Example Project: SDM-22-0003(SmartLCD_RW_w_ArduinoUNO_sw_serial)(UNO_code_inside)(forYT).zip