Adding Multiple Fonts and Sizes for use with the OLED

 

BCore OLED Font Tutorial

Overview: 

Now that you know how to use fonts other than the ones that come shipped with the BCore Operating System, here’s how to add even more for use at the same time!

 

 Steps:

  1. Continuing from the previous tutorial's Sonata project, (make sure you have it open in Sonata in front of you)
  2. Go to the folder where you've extracted the font files that you downloaded in the previous tutorial.
  3. Copy the rest of the font files (*.bin) to your project folder.
  4. Go back to Sonata IDE
  5. We will need to have more Data Files included in the project.
    • The Data Files help to organize the space in the DataFlash Chip.
    • Each Data File declared represents a "Page" in the DFlash. Each "Page" is allocated 65K bytes of memory in the DFlash.
    • Since Data1 has already been used by Font "CNB32.bin" and it's taken up about 60Kbytes of memory, we won't have enough space to add another font file in the same page. So we'll need to create another Data File.
  6. To do this, go to Project > Create New Data 
    • Sonata Create new Data File
  7. In the Project Explorer in the left pane, you should see now 2 Data Files.
  8. From the Project Explorer, select Data2.
    • Sonata Data File 2

 

For Data2, let's use the 24pt version of the font CNB.

Copy and Paste the following line of code to declare the font.

 

DATA UFONT(23560) FROMFILE "CNB24.bin"

 

23560 is the declared size of the font file in word format. (1 Word = 2 Bytes = 16bit)

 

Check out the font file's size by looking at its property and divide it by 2.

 

Let's proceed to download the font file into the DataFlash chip.

With DATA2 selected, you should see the following buttons above the project explorer pane.

 

BCore DataFlash Data Download

  1. Click on “Compile” (1). There should be no errors here.
  2. Click on “Download” (2). (This download is not to be confused with the normal project download. This download function is specifically for downloading data files into the data flash chip.)

The download process should be pretty fast, and you should see a line of these characters in the debug window on your right. “<<<<<<<<<<<<<<<<” This indicates that it has finished downloading the data files into the DFlash chip.

 

In the project explorer pane, click on CODE1.

To use the 24pt font that is stored in DATA2, we'll need to add the following 3 lines of code to the previous program.

 

PTR = DFlash.AddressOf(DATA2.UFONT)
OLED.USERFONT.INIT(PTR)
OLED.Print "FONT 24 " 'LARGE FONTS SIZE 24

 

So the entire program will look like this:

 

'CODE1
Dim PTR As Long
'===============================================================================
Public Sub Main()
Debug.Print "Fonts"
OLED.Init(Const.Color.Black)
OLED.Orientation = 0
'OLED.Print "Font 123" 'NORMAL FONTS SIZE 8
OLED.FontType = 3
PTR = DFlash.AddressOf(DATA1.UFONT)
OLED.USERFONT.INIT(PTR)
OLED.Print "FONT 32" 'LARGE FONTS SIZE 32
PTR = DFlash.AddressOf(DATA2.UFONT)
OLED.USERFONT.INIT(PTR)
OLED.Print "FONT 24 " 'LARGE FONTS SIZE 24
End Sub

 

 

Note: UserFont is currently not showing up under syntax helper as a member of OLED in the current version of Sonata, but this ought to change in the subsequent releases of Sonata.

 

Finally, "Compile and Download" the project. (Shortcut: F5)

 

That should give you 2 lines of 2 different font sizes on the screen.

 

TIP: Should you have an error while downloading, try pressing the white reset button on the BCore100 Board, and try again.

BCore Multiple Fonts for OLED screen program

 

To get your screen looking like the image above where it's using even more fonts, you'll need to keep adding more Data Files to the project until it looks like this;

Sonata Data Code View

Declare the font files and compile+download them into the DataFlash Chip.

 

You can download a full project here where this is already done for you. Download package

Of course, you'll need to compile and download each Data File before you can see the fonts.