How to run LVGL on M5Stack

  • FYI, I correctly display a button, I have many things left to do next, like finding the reason why my DrawingBoard.cpp pointers are badly set, but in the end, you help me a lot!
    Thanks again!

    For people reading this, I'll do my best to improve my GitHub repository in order to have a simple example for M5Core, explaining which parameters must be configured in lv_conf.h :)

  • Hi Pierre,

    Sorry I don't feel I did much for you but my (real) work is really taking much of my time (even what is supposed to be my free time) and I wish I could have spent more time working this out with you.
    In any case my offer still stands, I can help you building up a simple template with comments for people to get started.
    I already spent much time on it and I believe I have understood all the basic concepts .
    As already said, now i need to go one step further with event management.
    Also I am quite used to code in C (this is the language I started with a loooong time ago) I am not an expert but at least I can understand the most of what I do :)
    Btw a good platform that I have adopted now since several months is VSCode + PIO...Very neat combination!

  • I will omit the details,
    Currently, M5Stack Core2 is working with LVGL v8.1.0 and Arduino IDE.


    About lv_conf.h
    The following three settings are required.

    lvgl-master v8.1.0 / src / lv_conf.h

    1. /* clang-format off */
      #if 1 /Set it to "1" to enable content/

    2. #define LV_COLOR_DEPTH 16

    3. #define LV_TICK_CUSTOM 1
      #if LV_TICK_CUSTOM
      #define LV_TICK_CUSTOM_INCLUDE "Arduino.h"

  • Thank you @macsbug , this is exactly what I add to edit in my lv_conf.h in order to make it works!

    @erich I updated my repository, it now works, but not as expected. I've two issues:

    • I'm not able to change the label text each time I press a button (the reason of the seg fault)
    • I'm not able to draw on the right side like the lvgl take the wrong space, or the tft I don't know yet which one ^^'

    After that, everything will be ok (at least for this first project)

    As you said, a good platform for development is the key, I work with emacs for years, but I never configured it for C language.
    I've Arduino software open beside, only to compile & transfer.

  • Thank you @GoT , This is a great program.
    Thank you for publishing to github.


    1. not able to change the label text.
    2. The right side cannot be drawn.

    Change DrawingBoard.cpp.

    static lv_style_t style_color_label;
    static lv_style_t style_size_label;
    static lv_style_t style_clear_label;
    static lv_style_t style_label;

    void DrawingBoard::setup() {
    //lv_obj_t* _size_label = lv_label_create(lv_scr_act());
    _size_label = lv_label_create(lv_scr_act());

    //lv_obj_add_style(_size_label, &style_label, 0);
    lv_obj_add_style(_size_label, &style_size_label, 0);

    //lv_obj_add_style(_clear_label, &style_label, 0);
    lv_obj_add_style(_clear_label, &style_clear_label, 0);

    void DrawingBoard::drawPoint(int32_t x, int32_t y) {
    //_tft.drawCircle(x, y, _size, getColor());
    //_tft.fillCircle(x, y, _size, getColor());
    M5.Lcd.drawCircle(x, y, _size, getColor());
    M5.Lcd.fillCircle(x, y, _size, getColor());

    void DrawingBoard::changeSize() {
    //lv_label_set_text_fmt(_size_label, "Size: %d", _size);
    lv_label_set_text_fmt(_size_label, "Size: %d", _size);

    void DrawingBoard::clear() {

    All 'tft's are possible with 'M5.Lcd'.
    It is possible with M5.Lcd without using TFT_eSPI.
    Development environment: LVGL 8.1.0 + Arduino IDE 1.8.19

  • @macsbug you're right, I did mention using TFT_eSPI instead of M5.Lcd only for portability reason.
    I would like to create a set of sample files that I can use with any display and not only with M5Stack devices.

  • OMG, it works as expected! <3
    If both of you have GitHub account, I'd be glad to add you as credit for the awesome help!

  • Great, I'm glad it works for you!
    I don't feel I did much to help but anyways here is my GH account:
    At the moment I juste have a couple of private reps but I am planning to add public stuff when I get more used to M5Stack devices as this is becoming my main development/iot device platform.
    I will come back to this thread as I will probably need some help when I progress with my current project ;)

  • @erich you did more than you think.
    Feel free to ask when you will need it, if the M5Core2 is enough to run your program, I would be glad to help as you did

  • @got thanks, I will for sure ;)