Error: 'lv_font_montserrat_28' was not declared in this scope

I got LVGLDemo example sketch working on my Giga with display shield.
However whem I try to add font size to my label and its complaining that 'lv_font_montserrat_28' was not declared
Full error below:

C:\Users\artem\Documents\Arduino\LVGLDemo\LVGLDemo.ino: In function 'void setup()':
C:\Users\user1\Documents\Arduino\LVGLDemo\LVGLDemo.ino:75:38: error: 'lv_font_montserrat_28' was not declared in this scope
   lv_obj_set_style_text_font(label, &lv_font_montserrat_28, LV_PART_MAIN | LV_STATE_DEFAULT);
                                      ^~~~~~~~~~~~~~~~~~~~~
C:\Users\user1\Documents\Arduino\LVGLDemo\LVGLDemo.ino:75:38: note: suggested alternative: 'lv_font_montserrat_14'
   lv_obj_set_style_text_font(label, &lv_font_montserrat_28, LV_PART_MAIN | LV_STATE_DEFAULT);
                                      ^~~~~~~~~~~~~~~~~~~~~
                                      lv_font_montserrat_14
exit status 1
Compilation error: 'lv_font_montserrat_28' was not declared in this scope

My code:

  lv_obj_t * btn = lv_btn_create(obj);
  lv_obj_set_size(btn, 320, 150);
  lv_obj_center(btn);
  lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_CLICKED, NULL);

  label = lv_label_create(btn);
  lv_label_set_text(label, "Open");
  lv_obj_set_style_text_font(label, &lv_font_montserrat_28, LV_PART_MAIN | LV_STATE_DEFAULT);

I use windows 11 with Arduino IDE 2.3.2.
LVGL version 8.3.11
Please help

Hi,
Check "Text" section of the Giga Display Shield LVGL guide.

Thanks for the link, it was very helpful!

Hi, I've got the same problem. But there isn't anywhere the mbed_giga/libraries/Arduino_H7_Video/src folder.
I use lvgl.

C:\Users\Hp\Desktop\Luftfederung\BeideSeitenGehenDruckanzeige\BeideSeitenGehenDruckanzeige.ino: In function 'void setup()':
C:\Users\Hp\Desktop\Luftfederung\BeideSeitenGehenDruckanzeige\BeideSeitenGehenDruckanzeige.ino:139:45: error: 'lv_font_montserrat_30' was not declared in this scope
   lv_obj_set_style_text_font(center_label, &lv_font_montserrat_30, 0);
                                             ^~~~~~~~~~~~~~~~~~~~~
C:\Users\Hp\Desktop\Luftfederung\BeideSeitenGehenDruckanzeige\BeideSeitenGehenDruckanzeige.ino:139:45: note: suggested alternative: 'lv_font_montserrat_14'
   lv_obj_set_style_text_font(center_label, &lv_font_montserrat_30, 0);
                                             ^~~~~~~~~~~~~~~~~~~~~
                                             lv_font_montserrat_14
exit status 1

Compilation error: 'lv_font_montserrat_30' was not declared in this scope

Hi,

Same problem here,: when compiling my sketch, i get

'lv_font_montserrat_20' was not declared in this scope

I have modified the line #define LV_FONT_MONTSERRAT_20 1 in the lv_conf.h header file and the lv_conf.h is in the correct directory, i.e. the same directory where the lvgl directory is

I have included following lines at the top in my sketch and in following order:

#include "lv_conf.h"

#include "lvgl.h"

#include "Arduino_H7_Video.h"

#include "Arduino_GigaDisplayTouch.h"

Version of the IDE is 2.3.6 and the version of lvgl is 9.4.0

Thanks in advance for any help.

Hi @JurgenVanGoethem. By default, the lv_font_montserrat_14 font is the only one enabled for use in your sketches. You can enable additional fonts by modifying the configuration file.

Background

An important thing to understand is that when you use the "Arduino_H7_Video" library in your sketch, the library provides a lv_conf.h file that is configured for use with the GIGA Display Shield. That configuration is used instead of the configuration file you might add to the "lvgl" library if you follow instructions or tutorials for the configuration of the lvgl library:

https://docs.lvgl.io/9.4/details/integration/frameworks/arduino.html#configure-lvgl

A. Create Custom LVGL Configuration Library

It is possible to adjust the LVGL configuration by editing the configuration file that is bundled with the Arduino_H7_Video library. However, if you do that then all your modifications will be lost each time you use the Arduino IDE Boards Manager to update to a new version of the "Arduino Mbed OS Giga Boards" platform (the Arduino_H7_Video library is bundled with the platform). A better approach is to create a simple Arduino library and store your custom LVGL configuration in that library. This library will not be lost through updates of the Arduino Mbed OS Giga Boards platform and you can create as many of these libraries as you like if you want to use different configurations for different projects.

  1. Start Arduino IDE if it is not already running.
  2. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  3. Take note of the path shown in the "Sketchbook location" field of the dialog.
  4. Click the "CANCEL" button.
    The "Preferences" dialog will close.
  5. Use your file manager to create a new folder named MyLVGLConfig under the libraries subfolder of the "sketchbook location" path.
    โ“˜ You can name the folder anything you like as long as it only contains basic characters and no spaces (A-z, 0-9, _, -, .).
  6. Create a new file named MyLVGLConfig.h in the MyLVGLConfig folder.
    • โ“˜ If you chose a different name for the folder, adjust the filename accordingly.
    • :red_exclamation_mark: Make sure the filename is exactly MyLVGLConfig.h, not something like MyLVGLConfig.h.txt.
    • This file will not contain any code. Optionally, you can add a comment to the file to explain its purpose:
      // This file is intentionally left empty.
      // Its only purpose is to allow discovery of the library by the Arduino sketch build system.
      
  7. Click the following link to open the GitHub page for the Arduino_H7_Video library's LVGL 9.x configuration file in your web browser:
    ArduinoCore-mbed/libraries/Arduino_H7_Video/src/lv_conf_9.h at main ยท arduino/ArduinoCore-mbed ยท GitHub
  8. Click the downward pointing arrow icon ("Download raw file") at the right side of the toolbar:
  9. Wait for the download to finish.
  10. Copy the downloaded file to the MyLVGLConfig folder you created in the previous step of these instructions.
  11. Rename the downloaded file to lv_conf.h.

You must have the following folder structure:

<sketchbook location>/
โ”œโ”€โ”€ libraries/
โ”‚   โ”œโ”€โ”€ MyLVGLConfig/
โ”‚   โ”‚   โ”œโ”€โ”€ MyLVGLConfig.h
โ”‚   โ”‚   โ””โ”€โ”€ lv_conf.h
โ”‚   ...
...

B. Customize LVGL Configuration

The lv_conf.h file in the library you created by following the above procedure contains a configuration for using the 9.x versions of LVGL with the GIGA Display Shield. This provides a convenient starting point for your own custom LVGL configuration.

I'll provide instructions you can follow to enable LVGL's lv_font_montserrat_20 font for use in your Arduino sketches. If you would like to use a different font, just adjust the instructions accordingly.

  1. Use any text editor to open the lv_conf.h file from the library you created.
  2. Find this line in the file:
    #define LV_FONT_MONTSERRAT_20 0
    
  3. Change that line to:
    #define LV_FONT_MONTSERRAT_20 1
    
  4. Save the file

C. Use the Custom LVGL Configuration

To use the custom LVGL configuration in an Arduino sketch, just add the following line to the top of the sketch:

#include <MyLVGLConfig.h>

:red_exclamation_mark: The #include directive for MyLVGLConfig.h must be placed at some line above the line of the #include directive for Arduino_H7_Video.h in your sketch.


You can now use the lv_font_montserrat_20 font in your sketch. The sketch should now compile successfully and work as expected when you upload it to the GIGA R1 WiFi board.


I'll provide a minimal "hello world" example of using the custom configuration in a sketch:

#include <MyLVGLConfig.h> // This must be placed above the #include directive for Arduino_H7_Video.h
#include <Arduino_H7_Video.h>
#include <lvgl.h>
#include <font/lv_font.h>

// The constructor's default parameter values are appropriate for the GIGA Display Shield when compiling for the GIGA R1
// WiFi board.
Arduino_H7_Video Display;

void setup() {
  Display.begin();

  lv_obj_t *label = lv_label_create(lv_screen_active());
  lv_style_value_t labelFontStyleValue;
  // NOTE: The LV_FONT_MONTSERRAT_20 macro must be defined in lv_conf.h to use lv_font_montserrat_20.
  labelFontStyleValue.ptr = &lv_font_montserrat_20;
  lv_obj_set_local_style_prop(label, LV_STYLE_TEXT_FONT, labelFontStyleValue, 0);
  lv_label_set_text(label, "Hello, world!");
  lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
}

void loop() {
  lv_timer_handler();
}

It worked - thank you so much for your help !!!

You are welcome. I'm glad it is working now.

Regards, Per