font16seg is a MicroPython module for M5Stack devices prividing a 16-segment font.
This is not a font file. This module draws a letter as 16-segmented figures.
You can download the font16seg archive package file from the release page.
The file can be found in the Assets section. (file name format is font16seg-vN.N.N.zip
)
Unarchive the file, you will find two types of files in it.
font16seg.mpy
.mpy
is a precompiled binary container file format.- This file is smaller, faster and more efficient than
font16seg.py
. However, it is not editable and has version restrictions. - See MicroPython .mpy files
font16seg.py
- MicroPython source code file.
Copy font16seg.mpy
(or font16seg.py
) to the directory listed in sys.path
.
Then run the following code on your M5Stack device.
import font16seg
font16seg.text(10, 10, 'FONT16SEG')
- M5Stack UIFlow (Micropython-1.12) official firmware.
Currently, this module has been tested on M5StickC Plus (UIFlow_StickC_Plus v1.11.5) only. It may work on other models and versions.
- Digits
0123456789
- A-Z (Upper case)
ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Signs
%*+-/<>[\]_
- Colon
:;
(;
is used as unlit for colon)
- Point (Full stop)
.,
(,
is used as unlit for point)
You can assign the 16-segment definition to any letters. See assign function.
Assign the 16-segment definition to the specific character code.
code
int
- Character code to assign the definition.
- Generally, 20 to 126 is used.
flags
int
- 16-bit flags indicate which segments are to be lit or not.
If you want to assign the degree sign to 'd' (0x64). Here is an example.
font16seg.assign(ord('d'), 0b0100101010000000)
font16seg.text(10, 10, '4dC')
Set the attributes of the 16-segment font.
This function is similar to lcd.attrib7seg()
. But the parameters are incompatible with that.
length
int
- Default:
4
- Length of the short segment rectangle part.
width
int
- Default:
2
- Width of the segment.
color
int
- Default:
lcd.get_fg()
- Segments color.
unlit_color
int
- optional
- Default:
None
- Unlit segments color.
letter_spacing
int
- optional
- Default:
3
- The distance between letters.
rotate
int
- optional
- Default:
0
- Text rotation angle.
- 0, 90, 180 or 270 is acceptable.
font16seg.attrib16seg(8, 6, lcd.YELLOW, unlit_color=lcd.NAVY, letter_spacing=16)
font16seg.text(10, 10, 'FONT')
Return calculated width and height of the font from the attributes.
Restore the attributes to default. It is same as the following code.
font16seg.attrib16seg(4, 2, lcd.get_fg(), unlit_color=None, letter_spacing=3, rotate=0)
Display the string txt.
x
int
- Horizontal position of top left point.
y
int
- Vertical position of top left point.
txt
str
- String to be displayed.
- Undefined letter will be displayed as a space (
0x20
). - Text is not wrapped even if CR or LF is given.
color
int
- optional
- Segments color.
unlit_color
int
- optional
- Unlit segments color.
Return calculated width of the text from the attributes.
txt
str
- String used to calculate width.
If you are interested in the font16seg development. This section may help you.
The font16seg is developed for the MicroPython environment. However, it is difficult to develop and test on the MicroPython runtime. Therefore, CPython runtime is used for development and testing.
- Setup Python 3.11
- Install pipenv
pip install pipenv
- Install dependencies using pipenv
pipenv sync --dev
$ pipenv run test
The mpy-cross
command is required to build font16seg.mpy
file.
Compile the mpy-cross
command in the following steps.
- Download MicroPython 1.12 source code
- Unarchive and compile
mpy-cross
tar -xvf micropython-1.12.tar.gz
cd micropython-1.12/mpy-cross/
make
- Copy the
mpy-cross
command to the directory listed in$PATH
Then run build
command.
$ pipenv run build
font16seg.mpy
file is created in the dist
directory.
$ pipenv run package
This module is released under the MIT license.