Add new font code example needed

Hello,
succeeded in writing some labels to “ESP-WROVER-KIT V4.1” which contains ili9341 display. Can set text and background colors and change text size using implemented “roboto” font. But I need a bigger font. Created font C-file (roboto_80.c) by use of online font converter and copied file to root of esp32. But what to do now? Do I have to add the C-file to lv-bindings and re-compile or ???
See down for test-program.

Thanks for response,

Peter

"""
Demo program demonstrating the capabities of LittlevGL on ESP32-WROVER-KIT_V4.1 containing ILI9341
Author: 
Date:   

"""



import lvgl as lv
import lvesp32
import espidf as esp
from ili9341 import ili9341 # Import ILI9341 driver and initialized it
import time

#Constants
MADCTL_MH = const(0x04)
MADCTL_ML = const(0x10)
MADCTL_MV = const(0x20)
MADCTL_MX = const(0x40)
MADCTL_MY = const(0x80)

PORTRAIT = MADCTL_MX
LANDSCAPE = MADCTL_MV
LV_FONT_DECLARE = "roboto_80"


#Init ESP-WROVER-KIT V4.1
lv.init()
disp = ili9341(miso=25, mosi=23, clk=19, cs=22, dc=21, rst=18, power=14, backlight=5, rot=LANDSCAPE, width=320, height=240)


#Create a style based on style_plain
mystyle = lv.style_t(lv.style_plain)
#mystyle.text.font = roboto_80 # font roboto 80 pixel
mystyle.text.font = lv.font_roboto_28
mystyle.body.main_color = lv.color_hex(0x000000) # background top color (main), 0xRRGGBB
mystyle.body.grad_color = lv.color_hex(0x000000) # background bottom color (gradient), 0xRRGGBB
mystyle.text.color = lv.color_hex(0xffffff) # text-colour, 0xRRGGBB


#Create screen and labels
scr = lv.obj()
scr.set_style(mystyle)
label1 = lv.label(scr)
label2 = lv.label(scr)


#Create content
while(1):
    label1.set_pos(20,20)
    label1.set_text("Hello World!")
    label2.set_pos(50,50)
    label2.set_text("23:59")
    # Load the screen
    lv.scr_load(scr)
    time.sleep_ms(1000)           # sleep for 1 second

    label2.set_pos(50,50)
    label2.set_text("00:00")
    # Load the screen
    lv.scr_load(scr)
    time.sleep_ms(1000)           # sleep for 1 second

Hi Peter!

Currently, yes.

In the future I’m going to add support for loading fonts dynamically (on runtime, without rebuilding micropython). Here is the GitHub issue for tracking this:

But don’t worry, even today adding a new font to lv_micropython is very easy:

  • Create the font (as you did) and put the font C file ( lv_font_roboto_80.c) under some lvgl dir, for example, under lvgl/src/lv_font
  • Edit lv_conf.h and add your font to LV_FONT_CUSTOM_DECLARE. You can add multiple fonts if you want to.

In your case, define it like this:

#ifndef LV_FONT_CUSTOM_DECLARE
#define LV_FONT_CUSTOM_DECLARE  LV_FONT_DECLARE(lv_font_roboto_80)
#endif
  • Build lv_micropython

If you don’t want to modify lv_conf.h, you could add the font from the make command line instead, by adding the macro to LV_CFLAGS:

LV_CFLAGS="-DLV_FONT_CUSTOM_DECLARE=LV_FONT_DECLARE(lv_font_roboto_80)"

But you don’t need both. Either change lv_conf.h or add it to the make command line.

Now you should be able to use your font on Micropython

mystyle.text.font = lv.font_roboto_80

Hello,
thanks for support, succeeded in implementing font and display settings (see attached picture). For arised issues i’ll make another post.

best regards,

Peter

Thanks for the update. It looks very nice!
If you want, you can post more information about your project in My Projects category.

Done.
See: My Projects

best regards

Peter