Better Fonts for the SSD1306 OLED Display

The Adafruit SSD1306 support library uses the 5×7 pixel fonts as default. That is a fine and compact font, but wouldn’t it be nice to have some pretty high-res fonts to take advantage of the memory and resolution we have to work with?

In the previous tutorial (Tutorial 9), the ip.py script worked straight away , as it has the default font set.

This tutorial will guide you through how to change the default font to something else. Lets have a look at the following example in details :

(ip.py)

The first line of the example code snipet is a Python Comment line to tell you what the line below does in English. The second line to define “default fonts being used”. The third and fourth lines also comment lines.

The fifth and sixth lines of the code also commented to disable that parts of the program to remove them temporarily. These lines also to define fonts, but custom fonts. Usually contains the full path, and the size of the fonts.

Here’s how you use comments in Python:

Python Comments

Python has two ways to annotate Python code.
One is by using comments to indicate what some part of the code does.
Single-line comments begin with the hash character (“#”) and are terminated by
the end of line.
Python is ignoring all text that comes after the # to the end of the line,
they are not part of the command.
Comments spanning more than one line are achieved by inserting a multi-line string
(with “”” as the delimiter one each end) that is not used in assignment or
otherwise evaluated, but sits in between other statements.
They are meant as documentation for anyone reading the code.

To change the default font to something different and something cool, we will need to get some new fonts. You can download the fonts used by EduBoard using the command:

Path we used /home/pi/Fonts , Make sure to download Fonts.zip to this location.

The terminal prompt should look like this: pi@raspberrypi ~ $

Unzip content

Once extracted, remove the .ZIP file using the following command:

Navigate to the Fonts folder:

List the content of the folder:

The output should look like this:

Capture_it_2.ttf chigger.ttf FFF_Tusj.ttf GrandHotel-Regular.otf LokiCola.ttf ostrich-bold.ttf ostrich-light.ttf ostrich-rounded.ttf PWShaded.ttf unlearn2.ttf
Capture_it.ttf Chunkfive.otf Fipps-Regular.ttf handwriting.ttf ostrich-black.ttf ostrich-dashed.ttf ostrich-regular.ttf Persona.ttf SEASRN__.ttf unlearne.ttf

Now you can test out all the EduBoard_examples for the OLED display. Navigate to the containing folder:

List the content of the folder:

callme.py display_test.py hellokitty.py iloveyou.py info_led_red.py info.py ip.py message.py reset.py text.py whatsup.py

For an example, execute whatsup.py:

Output:

IMG_5184

To clear the display, and turn off the LED use the reset.py script:

As we have some new fonts, we can go back to the ip.py script to change the default font to something else.

At the prompt type:

Find the following six lines in the script:

Comment out the second line by putting # in front.

Remove the # from the front of the sixth line.

Run the script. The output should look like this:

IMG_5185

You can use any of the downloaded fonts. Simply, just change the font name in the following line:

For an example, change it to:

Should look like this:

IMG_5186

To change the font size, reduce or increase the number at the end of the line:

Good site to download new fonts from: Fontsquirrel. To easily download the fonts straight to your pi, use right click on the “download otf” button.

 

squirrel

Choose “Copy link location”.

On your Pi, at command prompt pi@raspberrypi ~/Adafruit_Python_SSD1306/EduBoard_examples $, use right click to paste the file location.

Should look like this:

pi@raspberrypi ~/Adafruit_Python_SSD1306/EduBoard_examples $ http://www.fontsquirrel.com/fonts/download/GoodDog

Add the wget command to the front of the URL:

wget http://www.fontsquirrel.com/fonts/download/GoodDog

The above method assumes you are connected to your Raspberry Pi via SSH connection.

If not, just paste the file location into a text reader, and type it in at the Pi command prompt.

To unzip the downloaded file, follow the above steps. Make sure, the downloaded “font” location and the /path/font defined in the script are matching.

 

 Next tutorial, Install Midnight Commander