Hello,
so I am using MQTT to publish a message on an LCD 20X4. I am having trouble displaying long texts, seems like if its too long it will begin printing on line 1 then continue onto line 3 and cut off some characters and print some on line 2.
How can I write a code for the 20x4 LCD that accepts an array of characters that I dont know the length of and displays it nicely?
Look at scrolling text.
The effect you are seeing is because the display memory(DDRAM) of the display is not linearly mapped to the physical lines on a 20x4 display.
You can not use the hd44780 shift left/right capabilities on a 20x4 display, that larryd mentions since all DDRAM is on the display.
Shifting the display will shift all 4 lines which doesn't work.
The shifting only works on smaller display and even then really only works on single line displays.
You will need to wrap long lines.
Use the hd44780 library and enable line wrapping by calling lineWrap().
It will automatically wrap the text to the appropriate next line on the display as desired.
The library is available in the IDE library manager.
See the LineWrap example for the appropriate i/o class for the h/w interface you are using.
The library includes documentation in a Documenation sketch.
You can also read more about it on the github page: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library
--- bill
This topic was automatically closed after 120 days. New replies are no longer allowed.