Lv_label_set_text_fmt() not accepting more than 13 characters?


I have trouble setting a string on a label if the string contains more than 13 characters.
Longer strings result in no text at all being rendered , or 1 or 2 random characters are displayed.

What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

printing a string longer than 13 characters

What have you tried so far?

Decreased the string size by 1 character until the text was correct rendered.

Code to reproduce


String usedSSID = "0123456789abcd";
lv_label_set_text_fmt(ui_LabelSSID,"ssid:\t%s", usedSSID);

The label:

    ui_PanelSSID = lv_obj_create(ui_SetupScreen);
    lv_obj_set_width(ui_PanelSSID, 548);
    lv_obj_set_height(ui_PanelSSID, 43);
    lv_obj_set_x(ui_PanelSSID, 78);
    lv_obj_set_y(ui_PanelSSID, 111);
    lv_obj_set_align(ui_PanelSSID, LV_ALIGN_CENTER);
    lv_obj_clear_flag(ui_PanelSSID, LV_OBJ_FLAG_CLICKABLE);      /// Flags
    lv_obj_set_style_bg_color(ui_PanelSSID, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_PanelSSID, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_PanelSSID, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    ui_LabelSSID = lv_label_create(ui_PanelSSID);
    lv_obj_set_width(ui_LabelSSID, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_height(ui_LabelSSID, LV_SIZE_CONTENT);    /// 1
    lv_obj_set_align(ui_LabelSSID, LV_ALIGN_LEFT_MID);
    lv_label_set_text(ui_LabelSSID, "ssid");
    lv_obj_set_style_text_color(ui_LabelSSID, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(ui_LabelSSID, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_LabelSSID, &ui_font_displayRoboto28m, LV_PART_MAIN | LV_STATE_DEFAULT);

Screenshot and/or video

I am also facing the same issue. Were you able to solve it?

I was able to solve it. Apparently strings in Arduino are handled a little differently. Using “c_str()” fixes the issue.

String usedSSID = "0123456789abcd";
lv_label_set_text_fmt(ui_LabelSSID,"ssid:\t%s", usedSSID.c_str());