Trouble with fonts, and with displaying floating point numbers in LVGL project

Continuing the discussion from Squareline Studio:

Hello friends
I have 2 problems and can't fix, 1 - the font size and 2 float number...
i created blank project and in center put label for live data of temperature sensor, in SL-Studio i set "montserrat 48" in style settings also checkmarked in flags > floating that's all..
after exporting i get error about font

/Users/macbook/Documents/Arduino/libraries/ui/src/screens/ui_Screen1.c: In function 'ui_Screen1_screen_init':
/Users/macbook/Documents/Arduino/libraries/ui/src/screens/ui_Screen1.c:17:40: error: 'lv_font_montserrat_48' undeclared (first use in this function); did you mean 'lv_font_montserrat_14'?
 lv_obj_set_style_text_font(ui_Label1, &lv_font_montserrat_48, LV_PART_MAIN| LV_STATE_DEFAULT);
                                        ^~~~~~~~~~~~~~~~~~~~~
                                        lv_font_montserrat_14
/Users/macbook/Documents/Arduino/libraries/ui/src/screens/ui_Screen1.c:17:40: note: each undeclared identifier is reported only once for each function it appears in

exit status 1

if export project with default font settings then i get live data but only in decimal format

 float temperature;
    bmp.getTemperature(&temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    int sensVal = temperature;
    lv_label_set_text_fmt(label1, "%d", sensVal);

Please advise if you know how to fix font and float?
Thanks

Hi George, we must be literally doing the same UI at the same time. I have just run up against the exact same two problems. I tried copying the font file into the src/fonts folder manually but that just chucked up another error to do with not being able to find lvgl.h in the parent directory. I backed off and deleted the bigger font text box and put it in the "fix that later" bucket.

Regarding the float I think the way to do it will be to operate in integers, store the integer in your controller, then have it converted to a float in your code and then pull that number onto the screen as a text. I couldn't find any way of getting Squareline to handle decimal places other than when I tried using the spin box, which kind of worked but also highlighted the decimal - as that's kind of its purpose. That might be a way forward if I can find a way of stopping it highlighting the decimal but that also threw up an error in the code to do with styles. I deleted the offending line out of the generated code and then it compiled but it felt a bit messy and probably not the way forward.

I see we are both using Mac as a dev platform - I sometimes worry that might be an underlying issue.

To cut to the chase this is what I'm trying to replicate on the controller screen:

I'll be going back to it tomorrow. To be fair I only found out that LVGL existed on Friday and Squareline Studio shortly after, so I'm pretty stoked that I've got the bare bones of a UI on the display shield already.

@farmer_giles Thank you for your response

Yes Mac is better in development and yesterday apple presented M3 Max :heart_eyes:
About font size I"m still working for it, if i figure out how to increase I'll share solution :slightly_smiling_face:

Hi George, I store the temperature as an integer so 254 is 25.4
You could do this in your code:
int sensVal = temperature * 10; // sets the int sensVal to 10 times the temperature
lv_label_set_text_fmt(label1, "Temp: %d.%d",sensVal/10, sensVal-(sensVal/10*10));

This uses the trimming and prioritisation of integer maths to your advantage and give you the result you want.

1 Like

@farmer_giles
Thank you very much... this is exactly what I wanted :100:

@iamgeorge @leocavagnis
Hi both - I did a load more reading on lv_label_set_text_fmt and discovered that in the lv_conf.h you can change the value of
#define LV_SPRINTF_USE_FLOAT 0
from 0 to 1 and in theory this will mean you can use %f in your sprintf formatting in lv_label_set_text_fmt command, however, it does not seem to work. I read around a bit more and this might be something to do with the Arduino IDE as the only other mention of this where someone managed to fix this specific problem was by moving away from the IDE and programming in a different environment. It's almost like it's not processing the lv_conf.h file, or at least the functionality of that line - or something is overriding it. For the moment I have to convert everything into integers to fake the float as above.
I even tried putting lv_conf.h in my IDE and including it in the normal way but that had no effect either.
Can either of you shed any further light on this one?

@farmer_giles

and finally I found the 100% Solution how to increase font sizes
Edit this file lv_conf.h but not in Arduino library,
in my case this is the path : ~/Users/macbook/Library/Arduino15/packages/arduino/hardware/mbed_giga/4.0.8/libraries/Arduino_H7_Video/src/lv_conf.h

how to enable fonts montserrat 18 and 48

#define LV_FONT_MONTSERRAT_8  0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 0
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 0
#define LV_FONT_MONTSERRAT_18 1
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 0
#define LV_FONT_MONTSERRAT_24 0
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 1

also I change Float setting from 0 to 1 but not working, still Searching the way how to show float numbers, i am prototyping Air Quality Monitor and this is important.

1 Like

For floating numbers change this settings in both lv_conf.h files

#define LV_SPRINTF_CUSTOM - 0 to 1
#define LV_SPRINTF_USE_FLOAT - 0 to 1 
lv_label_set_text_fmt(LABEL, "%f", VALUE);

but you will get 8 digit number like this "21.700000" instead of "21.70"

nice on I will give that a go.
you can format your number like this: %.2f and you will get 2 decimal places

1 Like

Good day @farmer_giles
%2f this does not works for me and i'm still can't figure out why... I think something is with IDE, I'll share if i find out.

@iamgeorge you need %.2f not %2f there is a dot between the % and the 2f

1 Like

@farmer_giles
"%.2f" works perfect Thanks a lot

@farmer_giles @leocavagnis
I am searching Brightness control, did you know how to control brightness?
only find this code but this is not what i want...

#include <Arduino_GigaDisplay.h>

//Create backlight object
GigaDisplayBacklight backlight;

void setup() {
  //init library
  backlight.begin();
}

int i = 0;
void loop() {
  backlight.set(i++ % 100);
  delay(100);
}

2 posts were split to a new topic: Use multi touch feature of Giga Display Shield with LVGL

A post was split to a new topic: How do you set the pins on the board?