The code below displays the digits 0-99 in a OLED 128 x 32 size display. But the numeric are not are very appealing. Is there a way to change the font so that the numbers are rendered with a smooth curved profile ( will be good to look at !!)
Or is there is a different library with this option ?? Thanks !!
/*********************************************************************
Code for Monochrome OLEDs based on SSD1306 drivers
( 128x32 size display using I2C to communicate )
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
void setup()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(0, 0);
char message[5];
int number ;
for ( int count = 0; count < 100 ; count++)
{
sprintf( message, " %3u", count);
display.print(message);
display.display();
delay(500);
display.clearDisplay();
display.setCursor(0, 0);
}
}
void loop() {
}
johnwasser:
Using Fonts | Adafruit GFX Graphics Library | Adafruit Learning System
Very good .. looks like the exact one that I wanted. But while I was able to change the program to add the new fonts I guess I need to some more home work before I can start showing them on the 128 x 32 OLED that I have. I am now seeing only the base line of the number on the top edge of the screen !!
Looks like these fonts have a different "origin "which is not the Top-Left point as a normal font. And needs a workaround to shift this.
But before I do that a query : These new fonts come in 9,12,18,24 sizes only. Even if I shift the origin will the 9 size atleast fit on the 128 x 32 screen ??
1 Like
Well, if the fonts are named for their height in pixels I would expect to get about 3 lines of 9-pixel or two lines of 12-pixel.
johnwasser:
Well, if the fonts are named for their height in pixels I would expect to get about 3 lines of 9-pixel or two lines of 12-pixel.
Well I used the "FreeSans24pt7b" to get absolutely rounded and lovely fonts . All that was required to display them was to shift the cursor suitably. This did the trick :
display.setCursor(0, 31);
Of course I got what I wanted but not sure how the 24pt in the name of the font correlates with the display. With 32 pixels on the Y-Axis, I would have expected some free space at the top ( about 8 pixels ? ) but I find the character is fitting tight with no free space on top.
Not that I am complaining as I got what I want but just curious !!
Thanks Johnwasser.
Mogaraghu:
Looks like these fonts have a different "origin "which is not the Top-Left point as a normal font. And needs a workaround to shift this.
Perhaps you should re-read the pages an using fonts. You apparently missed this part the first time:
"Some text attributes behave a little differently with these new fonts. Not wanting to break compatibility with existing code, the “classic” font continues to behave as before.
For example, whereas the cursor position when printing with the classic font identified the top-left corner of the character cell, with new fonts the cursor position indicates the baseline — the bottom-most row — of subsequent text. Characters may vary in size and width, and don’t necessarily begin at the exact cursor column (as in below, this character starts one pixel left of the cursor, but others may be on or to the right of it).
When switching between built-in and custom fonts, the library will automatically shift the cursor position up or down 6 pixels as needed to continue along the same baseline."
Mogaraghu:
Of course I got what I wanted but not sure how the 24pt in the name of the font correlates with the display. With 32 pixels on the Y-Axis, I would have expected some free space at the top ( about 8 pixels ? ) but I find the character is fitting tight with no free space on top.
So you missed this part, too: "fontconvert expects at least two arguments: a font filename (such as a scalable TrueType vector font) and a size, in points (72 points = 1 inch; the code presumes a screen resolution similar to the Adafruit 2.8" TFT displays). "
The pitch on that display is 0.18mm (.007", 141DPI) A little under 2 pixels per point. That would mean that a 24-point font would be 48 pixels high. Most characters won't take up all 48 pixels because many don't go below the baseline.
Thanks for the pointer John. Yes it does fall in place now...its always the issue with RTFM !! In the eagerness to get the get the project going fast, I normally skim through the manual and only later come back to it for removing glitches or improving the basic.
Anyway now that I have seen the OLED display, the plain old 1 line / 16Character LCD looks dull and boring.
I am looking at he various options of colour displays from Adafruit ( no need to search for libraries then ). I already have a Gameduino2 shield - maybe I can go back to it ... its collecting dust http://excamera.com/sphinx/gameduino2/
You have any recommendations on a good colour LC display for displaying many lines of Alphanumerics ? I would like to have different sized fonts for each line which is not possible with the 4lx20C display !
Thanks for your time.
Mogaraghu:
You have any recommendations on a good colour LC display for displaying many lines of Alphanumerics ? I would like to have different sized fonts for each line which is not possible with the 4lx20C display !
So you need a color graphics display with lots of pixels. I don't see anything out there better than 800x480. You may want to switch to something like a Raspberry Pi which has HDMI output. You'll need to learn to program Linux.
johnwasser:
Using Fonts | Adafruit GFX Graphics Library | Adafruit Learning System
John;
I haven't played around with programming the SD1306 128X64 oled in about 2 years. I have a sketch for GPS display that works great. I recently upgraded to IDE 1.8.4 and updated all the libraries and decided to tweak the code. After uploading I noticed what was crisp text, now looks more like dot matrix fonts and don't seem to be scalable. Was there a change in the header files?
Meanwhile, I'm going to play around with the fonts mentioned in the above link.
Thanks. Nick