I am in the process of optimizing the program. I'm moving some of the messages to EEPROM and using the EEPROM library Each text in EEPROM is a block of 20 characters, and the text string is terminated with zero (``x00`), e.g.
const char menuView[] = {
// +-- string termination
// v v- filled by space
"Current\0 "
"Minimum\0 "
"Average\0 "
"Maximum\0 "
};
I created myself a simple procedure that fetches the content into a global variable char str[32] , whose parameter is the starting address (of the EEPROM). I retrieve the text as a structure, using EEPROM.get(adr,str);
I have a problem with unwanted characters when displaying text on the LCD screen after using the eprint procedure. The following appear at the end of the displayed text: a blank character and (probably) a x01 character. I say probably, because I just happen to have this character defined as my own (using lcd.createChar().
In a nutshell, it looks like the above. Of course, there is more data input
I rule out such a situation because it happens in different parts of the code.
I think I have stumbled upon the cause.
1 In the code presented in the first post, responsible for displaying the string (procedure eprint), a small error crept in. Instead of lcd.println(str); I gave lcd.print(str);.
2 Namely, when it uses lcd.println(str); additional characters appear on the LCD screen.
I conclude that this is a bug in the LiquidCrystal library, which uses the Print class. In this class, there is a println method that adds println codes to the end of the displayed text. Perhaps, instead of the null and x01 characters I assumed, these were the characters.
3 However, after changing in my code from lcd.println to lcd.print, the problem of unwanted characters disappeared.
Unfortunately, the way the Print class works, the lower level library that uses the Print class has no knowledge that println() is called.
The lower level class write() function in the library using the Print (LiquidCrystal in this case) is called for each individual character, which includes CR and LF/NL when println() is called.
The LiquidCrystal library can't tell if println() was called or if the sketch intentionally sent 0xd and 0xa
And since the neither the LiquidCrystal library nor the hd44780 chipset supports line endings, the 0d and 0a characters will map to custom characters 5 and 2
since 0x08 to 0x0f are the same as 0x00 to 0x07 custom characters.
The "bug" is technically in the way the Print class is defined and implemented and it can't be fixed in other libraries like LiquidCrystal
There are some potential work arounds for this.
The hd44780 library does some gcc foo inside its classes to force an error to break the compile if sketch code attempts to call println() to prevent the user from using it.
At some point the hd44780 library will support line endings by doing line wrapping and scrolling in the library code. When line endings are supported, println() will be enabled.