IMPLEMENTED SO FAR

- Support for 4x20 LCD Display and large number display
- Brightness and contrast adjustment with remote
- (OPUS/Wolfson WM8741) DAC volume control: remote and rotary encoder
- (OPUS/Wolfson WM8741) DAC random filter selection 1 to 5 with remote
- (OPUS/Wolfson WM8741) DAC upsampling selection (L, M, H -this is the OSR setting)
- I2C level shifting (5V to 3.3V)
- Optimized power-up sequence

Saturday, May 23, 2009

Arduino LCD Custom Fonts, Large Numbers



Couldn't see well the standard size text of the display from the listening position (partly due to old age and old glasses :-)). So I did some research in the Arduino forums and found some code for using custom characters to display large numbers. Also used the example sketch that came with the LCD libraries.

The numbers I created are 9X the standard text size (3X3). Each number is composed of 9 custom characters.

The numbers can display very fast if you change the built-in delays in the library to zero with lcd.setDelay(0,0). The movie shows the speed with this setting.

The programming is very simple. First the custom characters are defined. In the LCD I am using you can define only up to 8 custom characters. For example, the following code defines one custom character where all the pixels are turned on:
uint8_t cc1[8] = { // Custom Character 1
B8(11111),
B8(11111),
B8(11111),
B8(11111),
B8(11111),
B8(11111),
B8(11111),
B8(11111)
};
NOTE: B8 is a macro defined in "macro.h" - Binary constant generator macro by Tom Torfs and included in the sample code that comes with the LCD library -there may be an easier/different way to define the characters, but I did not try...

Then you load the custom characters into the LCD's memory. The library for the web4robot LCD has a function to load the custom characters. For example, the following call loads custom character 1 into location 1:
lcd.load_custom_character(1,cc1);
In order to print custom character 1, the function lcd.write(1) is used. In order to facilitate the printing of the composite larger characters, a "bit map" is created with arrays as follows:
//___________0_____1_____2...
char bn1[]={1,2,1, 3,1,4, 2,2,1,...};
char bn2[]={1,4,1, 4,1,4, 7,6,5,...};
char bn3[]={1,3,1, 3,1,3, 1,3,3,...};
In other words, the number 1 is created by writing custom charters 3,1 and 4 in row 1, custom characters 4,1 and4 in row 2 and custom characters 3,1 and 3 in row 3. The following function does precisely that.
void printOneNumber(uint8_t digit)
{
// Print position is hardcoded

// Line 1 of the one digit number
lcd.setCursor(1,0);
lcd.write(bn1[digit*3]);
lcd.write(bn1[digit*3+1]);
lcd.write(bn1[digit*3+2]);

// Line 2 of the one-digit number
lcd.setCursor(2,0);
lcd.write(bn2[digit*3]);
lcd.write(bn2[digit*3+1]);
lcd.write(bn2[digit*3+2]);

// Line 3 of the one-digit number
lcd.setCursor(3,0);
lcd.write(bn3[digit*3]);
lcd.write(bn3[digit*3+1]);
lcd.write(bn3[digit*3+2]);
}

The complete code can be found here.

6 comments:

dweeb4 said...

Another stride forward - I admire your work - "lazy engineer" is a misnomer, I feel

Anonymous said...

dweeb4, thanks for your kind words. Lazy means I'm too lazy to think it through myself, so I copy code from here and there :-)

dweeb4 said...

That's called "standing on the shoulders of giants" in modern psycho babble that passes for business speak but it seems particularly appropriate here!

Anonymous said...

Cool. Have you posted it at the Arduino pages also? I think people outside Hifiduino (like me) whould like the idea to have an easy place to find such a good example too.
/Gunnar

Custom Paper Writing said...

Many institutions limit access to their online information. Making this information available will be an asset to all.

Andy from Workshopshed said...

Thanks for your examples I used it along with some shapes from the Arduino to get 2x3 characters on my display.

Double Height Letters on Arduino LCD