Updates‎ > ‎

Sparkfun Lcd_Library Fix

posted Apr 12, 2011, 9:35 PM by Daniel Hopkins   [ updated Aug 31, 2011, 12:50 PM ]
    While working with the Sparkfun Color LCD Shield for our enterprise project I ran into an obscure problem. While initializing our OBD chip the arduino would just stop responding. It got worse when I decided to print some debug strings to the screen. After 12+ hours of debugging and the help of some other teams that were using arduino, we traced the problem to the font table and to a lesser degree the way strings were stored.
    The font table and any strings that get sent to the screen get stored in ram with the original design of the library.  The font table by my estimation uses up somewhere around 1.2kb of the 2kb ram in the arduino 327. This was unnecessarily stored in ram because of its static nature and and is better stored in PROGMEM.  Using some examples and the arduino reference, I moved the font table to the PROGMEM, added several font sizes, and maintained backward comparability.

    The new library adds several new functions for strings and modifies the old ones to use the new fonts. I am missing a couple of features in one of the functions which I will add when I get time (Its almost finals week).

The new code is attached. If there are any mistakes leave a comment. I also didn't have much time so the comments could be missing something. I plan on adding more details later on when I get some free time.

Some of the new functions and their usage.
New functions
void LCDPutChar_P(char c, int x, int y, int size, int fColor, int bColor);
void LCDPutStr_P(char *pString, int x, int y, int fColor, int bColor);

LCDPutStr_P(PSTR("RPM :"), 16, 2, BLUE, BLACK);

LCDPutStr(str, 2, 2, GREEN, BLACK);

LCDPutStr_P(PSTR("Protocol:ISO9141"), 50, 2, GREEN, BLACK);

    sprintf_P(str, PSTR("%d CODE(S) IN ECU"), nb);
    LCDPutStr(str, 18, 2, WHITE, RED);

Added some protections to make sure it doesn't leave font memory. Prints out of range characters as "#"s.

Conversation Element

Daniel Hopkins,
Apr 14, 2011, 10:47 PM