SerialDisplay

Notes on the 16x2 LCD Serial Display unit:

Arduino based soldered proto board. Has RS-232 tx/rx, VCC/gnd and two additional contacts (for I2C experiments)

Using Arduino RX/TX (USB Serial Monitor) for debug. Then will switch code to use MySerial routines on pins 8,9.

There are a couple of implementation options on the algorithm, based on how \n and \r are handled.

Note that the Hitachi 16x2 display prints "cr" (\r), "lr" (\n) and even "\" characters as graphic characters.

The Arduino Serial Monitor takes input one line at a time. It will collect a line of input until the "enter" key is pressed, then send it all to the serial port. Other devices may not do this.

For debug purposes, it could be very helpful to display the output as it arrives, one character at a time.

If the data is displayed one character at a time, it would be desirable to "write" the received characters to the second line of the display as they are received. When a \n or other terminator character is received, the second line is copied to the first line (replacing it), then the next character(s) continue filling in the second line, starting at position zero.

However, if all the data is sent at one time with a terminator, then the above algorithm would basically receive a line of data, printing each character as received, and then immediately scroll the received line UP to the top line, and wait printing nothing until the whole next line is sent in the next burst.

For this reason, we may need to have two algorithms - one that displays each character individually, and one that displays line at a time.

On the subject of terminator characters...

Note that sometimes using \n or \r, or even \r\n (Windows) as a line terminator can be problematic.

For control applications, it can be more convenient to treat \r and \n as whitespace characters and basically ignore them. Sentences can be terminated with the ';' (semicolon) character to make termination obvious.

For the display - especially if multiple termination characters are possible, the best possible alternative seems to be to accept the semicolon (";"), LF ("\n"), and CR ("\r") all as possible terminators. The semicolon is printed to the line. A line advance happens any time any of the following occurs:

    • CR ("\r")

    • LF ("\n")

    • Semicolon (";")

    • Character count exceeds 14

The previously printed buffer (including any possible semicolon) is copied to the top line.

All future whitespace and CR ("\r") or LF ("\n") characters are suppressed until the next non-whitespace character is seen. Then writing to the bottom line of the display continues until one of the above terminators is encountered.

= = = =

One option is to perform the line advance on the display with the first character that is any type of terminator. Then, suppress any whitespace charactors, including newline, cr, semicolon, or other terminator characters until a non-whitespace character appears.

An alternative to the above is to not perform the line advance on the display until AFTER a non-whitespace character is detected.

Display algorithm:

    • Loop getting characters

    • If /r - replace with "/" "r", and continue

    • If /n sent:

      • Copy line1 to line0

      • Pad extra spaces in buffer to " ", copy buffer to line1, clear buffer to all space. Set index back to 0.

    • If index hits 14:

      • Copy line1 to line0

      • Pad extra spaces in buffer to " ", copy buffer to line1, clear buffer to all space. Set index back to 0.