I have an application in which I want to write serial output to an LCD (20x4) or OLED display and have it act just like the serial monitor, i.e Write the first line, then the 2nd line, then the third line etc. and when all lines have been filled, have the contents of the screen all scroll up one line and write the new data on the last line and so on.
Writing the data to the display is easy (device.print statements), but getting all the scrolling of lines (which involved clearing the display, moving the lines up and writing the new line) is a bit complex. I'm wondering if a function like this is part of any Arduino library, or if anyone knows of a published sketch that goes all this. I'd rather not reinvent the wheel if I don't have to!
I guess what I'm looking for is a essentially a vertical scrolling function. I haven't found such a function in any of the display libraries I've looked at so far.
The application currently writes short (20 character) lines to the IDE serial monitor. I just want to replace that with an LCD or OLED so I don't need to be hooked up to the PC.
As far as I know, the standard LCD works the way you want. Look at the example sketch called SerialDisplay.pde. You may have to rename it to SerialDisplay.ino. Give it a try.
You have to write that functionality yourself as part of your sketch.
You can use a two-dimensional character array; e.g. for a display with four rows of 16 characters
char displayBuffer[4][17];
You fill that array row by row and display each row of the array on the associated row of the display.
If the array is full and you want to add new information to display, you copy row 1 in the buffer to row 0, row 2 to row 1, row 3 to row 2 and next overwrite row 3 in the buffer with new data.
Next clear the display and write the array content row by row to the display.
Thanks for the ideas and confirming that this isn't part of some library that I haven't found. The use of a 4 x 20 matric of characters as the basis for vertical scrolling sound like a good way to go.
While the 2004 LCD driven by the LiquidCrystal_IC2 does have some crude work wrap, it's certainly not capable of displaying typical serial data as would be sent to something like the serial monitor screen of the IDE. Sometimes it may wrap onto the "wrong" line, as it can do when it fills up the bottom line). The library used makes the LCD display thing like the newline character as a character and not read it as a command to start a new line.
These things can be dealt with in a sketch that drives the LCD, but then you are writing new code which tells the display when to start a new line, what to do with the old line etc. which means storing things in buffers. moving lines around, dealing with lines longer than 20 characters etc. I was hoping that someone had put something like this in a library for these LCDs, but it doesn't look like they have.
It's probably easier to write the code for the program sending the serial data formatted in such a way that it makes it easy to read translate it into something compatible with the a 20 character LCD display. It's not hard to filter out the \n newline characters and use them in the program to make the display switch to a new line. If each "frame" sent via the serial link is 4 lines of 20 characters, life gets easier for the programmer,
There doesn't seem to be any code out there that will turn an Arduino + LCD/OLED display into a terminal emulator (albeit one with a short line length!).
If I was seriously going to try to do this for the general case, I'd probably do it for one of the 240x360 pixel TFT displays since you can get 40 characters and 45 lines (though the text is pretty small on a 1.9 or even a 2.3" display) or rotation to give 30 lines of 60 characters if the libraries can do either orientation.
That is caused by the hardware driving the LCD, generally an HD44780 or compatible chip. The lines on a 20 x 4 display wrap 0 > 2 > 1 > 3 instead of 0 > 1 > 2 > 3 because of the way the buffer memory in the driver chip is mapped to the display. The hd44780 library by Bill Perry does have an option to wrap the lines in the correct order, but does not implement any processing of the end of line characters.
It's literally 10 minutes work to bash out a simple terminal program that understands character wrapping, carriage return, backspace and form feed.
I know this because I just did it. Uno R3 and a LCD20x4 with an I2C backpack. It's absolutely the ugliest code, but it does the job. And no, I have no intention of showing it; it's that ugly. I just did it to prove to myself that an LCD terminal could be knocked out in 10 minutes.
Here's the bit of the code that handles scrolling when the last line wraps or CR is pressed on the last line. This is one of the least ugly bits of the code, believe it or not!