LVGL on Arduino Mega 2560

It wouldn’t bother if it didn’t run quickly and smoothly, as my application is very static anyway.

The text on the screenshots is partly in German. Here is the translation:

1.)
The sketch uses 12966 bytes (5%) of the program memory. The maximum is 253952 bytes.
Global variables use 233 bytes (2%) of dynamic memory, leaving 7959 bytes for local variables. The maximum is 8192 bytes.

2.)
The sketch uses 88122 bytes (34%) of the program memory. The maximum is 253952 bytes.
Global variables use 21851 bytes (266%) of dynamic memory, leaving -13659 bytes for local variables. The maximum is 8192 bytes.

lv_conf.h (24.7 KB)

The Code:

#include <lvgl.h>
#include <UTFT.h>

static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10];

UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
int x;
int y;

void timer_1(void)
{
  if (millis() % 5 > 1) //Every 5 ms
  {
    lv_tick_inc(1);
  }
}

void LCD_WritePixel(int x, int y, int color)
{
  myGLCD.setColor(color);
  myGLCD.drawPixel(x, y);
}


void setup()
{
  Serial.begin(9600);
  myGLCD.InitLCD();

  lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  lv_disp_drv_t disp_drv;
  lv_disp_drv_init(&disp_drv);
  disp_drv.hor_res = 320;
  disp_drv.ver_res = 240;
  disp_drv.buffer = &disp_buf;
  disp_drv.flush_cb = my_flush_cb;
  lv_disp_t * disp;
  lv_disp_drv_register(&disp_drv); /*Register the driver and save the created display objects*/
}

void my_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
  /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
  int32_t x, y;
  for (y = area->y1; y <= area->y2; y++) {
    for (x = area->x1; x <= area->x2; x++) {
      LCD_WritePixel(x,  y, color_p->full);
      color_p++;
    }
  }

  /* IMPORTANT!!!
     Inform the graphics library that you are ready with the flushing*/
  lv_disp_flush_ready(disp_drv);
}

void loop()
{
  timer_1();


  if (millis() % 5 > 1)
  {
    lv_task_handler();
  }
}

Best regards
David

Great (you don’t need to translate german language (mit mir kannst du auch deutsch sprechen, aber sehr langsam :slight_smile: ). So here are the changes I suggest:

  1. change static lv_color_t buf[LV_HOR_RES_MAX * 10]; to static lv_color_t buf[LV_HOR_RES_MAX * 1];
  2. in lv_conf.h change #define LV_ANTIALIAS 1 to #define LV_ANTIALIAS 0 and #define LV_MEM_CUSTOM 0 to #define LV_MEM_CUSTOM 1

Try co compile your sketch and post the result. If it still didn’t fit then you have to check if LVGL picks the right lv_conf.h file - there is no memory allocation for internal LVGL heap now…

That’s cool. Where are you from? Where do you come from? I’ve made the changes. You have created a change. But not enough.

Best regards
David

I’m from Czech Republic… Ok so there is change about 21851 - 15284 = 6567 bytes. Hmm, the last chance I see is to disable all widgets (LV_USE_BAR, LV_USE_BTNMATRIX, LV_USE_CHART, LV_USE_IMG, LV_USE_IMGBTN, LV_USE_SPINBOX). Maybe better way to check, what is so memory hungry is to check this project in Platformio and check the map file. Unfortunately I’m not able to give it a try this weekend :frowning:

Okay nice. That’s not a problem, it’s not urgent. I think it’s really cool how you try to help people. In addition to with, you can also learn a lot yourself. Thanks a lot for this!

Best regards
David