Skip to main content

Font Library Usage & Creation

Built-in Bitmap String Fonts

128-Character Bitmap Fonts

128-character bitmap fonts are suitable for displaying the basic ASCII character set. These fonts come in different sizes and styles to suit a variety of display needs.

Font FileExample Image
vga1_8x8.pyVGA1 8x8 bitmap font preview
vga1_8x16.py
vga1_16x16.py
vga1_16x32.py
vga1_bold_16x16.pyVGA1 bold 16x16 bitmap font preview
vga1_bold_16x32.py

256-Character Bitmap Fonts

256-character bitmap fonts include a wider character set, including some international characters and symbols. These fonts are usually used in more complex application scenarios.

Font FileExample Image
vga2_8x8.pyVGA2 16x16 bitmap font preview
vga2_8x16.py
vga2_16x16.py
vga2_16x32.py
vga2_bold_16x16.pyVGA2 bold 16x16 bitmap font preview
vga2_bold_16x32.py

Usage Example

from lcd import LCD
import vga1_16x32 as font

# Initialize the LCD
lcd = LCD()

# Clear the screen
lcd.fill(LCD.BLACK)
lcd.text(font, "hello", 0, 0, LCD.WHITE, LCD.BLACK)
info

Displaying bitmap text:

  • Call the lcd.text() method to display the text "hello" at position (0, 0) on the screen.
  • Set the font color to white (LCD.WHITE) and the background color to black (LCD.BLACK).

Built-in Vector String Fonts

Vector Character Fonts

Font FileExample Image
astrol.pyastrol font
cyrilc.pycyrilc font
gotheng.pygotheng font
gothger.pygothger font
gothita.pygothita font
greekc.pygreekc font
greekcs.pygreekcs font
greekp.pygreekp font
greeks.pygreeks font
italicc.pyitalicc font
italiccs.pyitaliccs font
italict.pyitalict font
lowmat.pylowmat font
marker.pymarker font
meteo.pymeteo font
music.pymusic font
romanc.pyromanc font
romancs.pyromancs font
romand.pyromand font
romanp.pyromanp font
romans.pyromans font
romant.pyromant font
scriptc.pyscriptc font
scripts.pyscripts font
symbol.pysymbol font
uppmat.pyuppmat font

Usage Example

from lcd import LCD
import astrol as font

# Initialize the LCD
lcd = LCD()

# Clear the screen
lcd.fill(LCD.BLACK)
lcd.draw(font, "Hello", 0, 0, LCD.WHITE, scale=1.5)
info

Displaying vector text:

  • Call the lcd.draw() method to display the vector font astrol text "hello" at position (0, 0) on the screen.
  • Set the font color to white (LCD.WHITE) and a 1.5x magnification.

External Chinese Font Library (User-made)

Schematic

External Chinese font library schematic

By running the font2bitmap.py program, convert specified text into a bitmap file of specified font, then store the bitmap file on the Beetle S1's SD card. You can then use the font library to display Chinese text!

Creation Steps

  1. Download the font-to-bitmap conversion program: font2bitmap.py
  2. Download the font file: NotoSansSC-Regular.zip (needs to be unzipped before use)
    • You can use any other font; this is just used as an example.
  3. Open a CMD terminal and run font2bitmap.py!

Execution process:

  1. For example, download the files to D:\font

Putting the files in the D:\font directory

  1. Open CMD: press Win + R, type cmd, then press Enter.

Opening CMD

  1. Type the command D: to enter the D drive (enter whichever drive the files are on).

Entering the D drive

  1. Type the command cd d:\font to enter the folder.

Entering the font folder

  1. Type the conversion command: python font2bitmap.py -s "你好" NotoSansSC-Regular.otf 16 > font.py, then you will get a bitmap library file font.py containing the Chinese text "你好".

Running the conversion command

Generating the font.py file

Note

Before running the command python font2bitmap.py -s "你好" NotoSansSC-Regular.otf 16 > font.py, you need to install python3 and other required tools.

Usage Example

  1. Copy the bitmap file font.py to the Beetle S1's \SD\sys\font directory
  2. Then import the font module (note that you must add the environment variable path first)
import sys
sys.path.append('/sd/sys/font')

import font as font
  1. Use the write(bitmap_font, s, x, y[, fg, bg, background_tuple, fill_flag]) method to display the text.
import sys
sys.path.append('/sd/sys/font')
import font as font

from lcd import LCD
# Create an LCD instance
display = LCD()

# Clear the screen to black
display.fill(LCD.BLACK)

display.write(font,"你好",0,0,LCD.WHITE)