I've run into a problem with a library I'm using, I'm guessing it's just a little detail to fix, but I'm at a loss.
Normally, with most LCDs and libraries, I would do something like this:
LCD.println(F("HELLO WORL"));
I have this lcd/keyboard controller that comes with a library the manufacturer wrote. It all works well (so far) except I can't save text to the flash memory via F(). An example would be:
I'm using I2C, and THE LIBRARY IS HERE, which he wrote. I talked to him about it, and he wasn't familiar with the Flash () function.
Is it hard to implement this into his library? I have a lot of text to display and will have to have the F() function.
Thanks,
No… although I haven’t looked at the code, because I won’t download from external sites. If you attach it to your post, I would take a look. There are probably two easy ways:
1) Derived his class from the Print class. You must make sure the single-character write method is overridden in his class:
virtual size_t write(uint8_t c);
The Print class will use that method to provide all the other print methods (int, float, char *, etc.).
2) Add a method to his class, using Print.cpp as an example:
size_t LCDclassName::print(const __FlashStringHelper *ifsh)
{
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
if (write(c)) n++;
else break;
}
return n;
}
The F macro result is of type const __FlashStringHelper *, so that’s the method you need to provide.
The first technique is best, as you may be able to eliminate a bunch of code from his library, duplicating what the Print class is already providing. The second technique may quicker for you if you aren’t familiar with C++ classes.
Cheers,
/dev
P.S. The Print class source code, Print.h and Print.cpp, is in the Arduino install directory, under hardware/arduino/avr/cores/arduino.
I looked at both those files, .cpp and .h, but I can't make sense of what was recommended to fix the problem. Can someone point me in the right direction? I'd sure appreciate it.
Thanks so much! I'll check this out tomorrow. I normally like to fully understand everything I get help with on the forum, but I this library stuff is SO over my head, I know I won't. Thanks from me, and I'll forward to update to the library developer.
Cheers,
if you left the AVR behind and used some other processor, all the proprietary progmem kludes in AVR libC to get around the AVR h/w architecture incompatibilities with C would vanish.
i.e. with other micro-controllers const just works as was intended and required by C.