ESP32 (WT32-SC01) problems getting started

What do you want to achieve?

i would like to be pointed in the direction of a arduino sketch that will work with my esp board,i have the project exported and included in the the arduino ide,im just not sure what to put in the main sketch file to make this thing all come together

What have you tried so far?

a few youtube tutorials but not luck or clear explanation

Screenshot or video

Others

  • SquareLine Studio version: 1.1.0
  • Operating system: windows
  • Target hardware: esp32 wt32-sc01 touch screen dev-board

Have you exported the Arduino project from SquareLine? If so, please take a look at the README.

Basically you can configure the pin connection in libraries/TFT_eSPI/User_Setup.h .

Hi, have similar problems to get a very small example up and running on WT32-SC01 3.5".
I handmade already some lvgl / TFT_eSPI GUI’s for that board, so the pin connection seems to be correct.
My Squareline example contains only 5 objects, is my starting point to verify that the flow is working.
Simulation works as expected.
Export->Create Template Project worked fine.
Compile ( Arduino ) and upload successful.
But then I get only random pattern, so there is nothing written to the LCD.
For test reasons I add
tft.fillScreen(TFT_YELLOW);
at the end of setup()
Then the display is filled yellow. ( works fine with other colors, also )

So there is something wrong with my setup.
I’m on Windows 11, all available updated are installed.

I tried other lvgl / TFT_eSPI examples, independent from Squareline, they are working fine.
I expect, there is something wrong in my setup. I’m unable to find it. Spent a lot of time, watch interesting videos, but still hanging.

Any idea?
Thanks in advance
Pepito

I forgot, Pin connections for that board:
#define TFT_MISO 12
#define TFT_MOSI 13
#define TFT_SCLK 14
#define TFT_CS 15
#define TFT_DC 21
#define TFT_RST 22
#define TFT_BL 23

Try this code, I think he is using same displey. You can see here how it works. I hope it helps.

Thanks, this dis help a little bit.
Random pattern are gone, display is dark, I’m able to dimm the backlight.
But I’m still missing the generated UI … that one works in simulation.
Compile, upload, everything is ok, no warning, no error.
#define LV_TICK_CUSTOM 1 … of course :smirk:

Any idea or has somebody a very small example for the WT32-SC01 3.5" board?
Thanks and have a good day
Pepito

/* My ui.ino */
#include <lvgl.h>
#include “ui.h”
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <FT6236.h>
#define SDA_FT6236 18
#define SCL_FT6236 19
FT6236 ts = FT6236();

class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ST7796 _panel_instance;
lgfx::Bus_SPI _bus_instance; // SPI
lgfx::Light_PWM _light_instance;

public:
LGFX(void)
{
{ //
auto cfg = _bus_instance.config(); //
cfg.spi_host = VSPI_HOST; // (VSPI_HOST or HSPI_HOST)
cfg.spi_mode = 0; // SPI(0 ~ 3)
cfg.freq_write = 40000000; //
cfg.freq_read = 16000000; //
cfg.spi_3wire = false; // MOSI true
cfg.use_lock = true; //
cfg.dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable)
cfg.pin_sclk = 14; // SPIのSCLK
cfg.pin_mosi = 13; // SPIのMOSI
cfg.pin_miso = 12; // SPIのMISO
cfg.pin_dc = 21; // SPIのD/C (-1 = disable)
_bus_instance.config(cfg); //
_panel_instance.setBus(&_bus_instance); //
}

{ //
  auto cfg = _panel_instance.config();    // 
  cfg.pin_cs           =    15;  // CS(-1 = disable)
  cfg.pin_rst          =    22;  // RST(-1 = disable)
  cfg.pin_busy         =    -1;  // BUSY(-1 = disable)
  cfg.memory_width     =   320;  // 
  cfg.memory_height    =   480;  //
  cfg.panel_width      =   320;  //
  cfg.panel_height     =   480;  //
  cfg.offset_x         =     0;  //
  cfg.offset_y         =     0;  //
  cfg.offset_rotation  =     0;  //
  cfg.dummy_read_pixel =     8;  //
  cfg.dummy_read_bits  =     1;  //
  cfg.readable         =  true;  //
  cfg.invert           = false;  //
  cfg.rgb_order        = false;  //
  cfg.dlen_16bit       = false;  //
  cfg.bus_shared       =  true;  //

  _panel_instance.config(cfg);
}

{ //
  auto cfg = _light_instance.config();    //

  cfg.pin_bl = 23;              //
  cfg.invert = false;           // true
  cfg.freq   = 44100;           //
  cfg.pwm_channel = 7;          //

  _light_instance.config(cfg);
  _panel_instance.setLight(&_light_instance);  //
}

setPanel(&_panel_instance); //

}
};

LGFX tft;

/Change to your screen resolution/
static const uint32_t screenWidth = 320;
static const uint32_t screenHeight = 480;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * 10 ];

/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
uint32_t w = ( area->x2 - area->x1 + 1 );
uint32_t h = ( area->y2 - area->y1 + 1 );

tft.startWrite();
tft.setAddrWindow( area->x1, area->y1, w, h );
// tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
tft.endWrite();

lv_disp_flush_ready( disp );
}

/Read the touchpad/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
if(ts.touched()){
data->state = LV_INDEV_STATE_PR;
TS_Point p = ts.getPoint();
data->point.x = p.y;
data->point.y = tft.height() - p.x;
}else{
data->state = LV_INDEV_STATE_REL;
}
}

void setup()
{
Serial.begin(115200);

tft.begin();
tft.setRotation(1);
tft.setBrightness(255); // works fine

if(!ts.begin(40, SDA_FT6236, SCL_FT6236)){ // works fine
Serial.println(“Unable to start the capacitive touch Screen.”);
}

lv_init();
Serial.println(“lv_init done”);
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * 10 );

/Initialize the display/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
Serial.println(“Display Init done”);
/Change the following line to your display resolution/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
Serial.println(“Set Display Properties done”);
/Initialize the (dummy) input device driver/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
Serial.println(“Set Dummy Input Device done”);
ui_init();
Serial.println(“ui_init() done”);
}

void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay( 5 );
}

I start from scratch again, now it works with my own simple example. It’s a good starting point.
Touch is working fine…
But I’m unable to make the audio mixer example work on my device.
I set the width = 320, height = 480, resize and move some objects, that everything fits on screen,
but the result is only a white screen :slight_smile:
Touch is not operating ( have no debug outputs ).
I expect, the process is hanging on some place, or not started.
But my own stuff has priority … :wink:
Thanks and have a good day
Pepito

Please enable logging to see id LVGL has some errors or warnings. I think it’s an out-of-memory issue.

Can you happen to post your simple example? I’m just starting with Squareline & WT32-SC01 and it would be a tremendous help to have something to start with. I will appreciate anything you can provide.

Mike

Hi Mike,

I’m currently not at home.

It works fine with that board.

With touch.

Going to send you my template.

Then generate only your specific ui files.

Do not update / overwrite the template.

Check libraries, often there ist some stuff missing, e.g. for touch.

Have a good day

Peter

here is the tmplate.ino:
#include “lvgl.h”
#include “ui.h”
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <FT6236.h>
#define SDA_FT6236 18
#define SCL_FT6236 19
FT6236 ts = FT6236();

public:
LGFX(void)
{
{ //
auto cfg = _bus_instance.config(); //
cfg.spi_host = VSPI_HOST; // (VSPI_HOST or HSPI_HOST)
cfg.spi_mode = 0; // SPI(0 ~ 3)
cfg.freq_write = 40000000; //
cfg.freq_read = 16000000; //
cfg.spi_3wire = false; // MOSI true
cfg.use_lock = true; //
cfg.dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable)
cfg.pin_sclk = 14; // SPIのSCLK
cfg.pin_mosi = 13; // SPIのMOSI
cfg.pin_miso = 12; // SPIのMISO
cfg.pin_dc = 21; // SPIのD/C (-1 = disable)
_bus_instance.config(cfg); //
_panel_instance.setBus(&_bus_instance); //
}

{ //
  auto cfg = _panel_instance.config();    // 
  cfg.pin_cs           =    15;  // CS(-1 = disable)
  cfg.pin_rst          =    22;  // RST(-1 = disable)
  cfg.pin_busy         =    -1;  // BUSY(-1 = disable)
  cfg.memory_width     =   320;  // 
  cfg.memory_height    =   480;  //
  cfg.panel_width      =   320;  //
  cfg.panel_height     =   480;  //
  cfg.offset_x         =     0;  //
  cfg.offset_y         =     0;  //
  cfg.offset_rotation  =     0;  //
  cfg.dummy_read_pixel =     8;  //
  cfg.dummy_read_bits  =     1;  //
  cfg.readable         =  true;  //
  cfg.invert           = false;  //
  cfg.rgb_order        = false;  //
  cfg.dlen_16bit       = false;  //
  cfg.bus_shared       =  true;  //

  _panel_instance.config(cfg);
}

{ //
  auto cfg = _light_instance.config();    //

  cfg.pin_bl = 23;              //
  cfg.invert = false;           // true
  cfg.freq   = 44100;           //
  cfg.pwm_channel = 7;          //

  _light_instance.config(cfg);
  _panel_instance.setLight(&_light_instance);  //
}

setPanel(&_panel_instance); //

}
};

LGFX tft;

static const uint32_t screenWidth = 480;
static const uint32_t screenHeight = 320;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * 10 ];

/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
uint32_t w = ( area->x2 - area->x1 + 1 );
uint32_t h = ( area->y2 - area->y1 + 1 );

tft.startWrite();
tft.setAddrWindow( area->x1, area->y1, w, h );
// tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
tft.endWrite();

lv_disp_flush_ready( disp );
}

void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
if(ts.touched())
{
data->state = LV_INDEV_STATE_PR;
TS_Point p = ts.getPoint();
data->point.x = p.y;
data->point.y = tft.height() - p.x;
// Serial.print( "Data x " );
// Serial.println( data->point.x );

// Serial.print( "Data y " );
// Serial.println( data->point.y );
}
else
{
data->state = LV_INDEV_STATE_REL;
}
}

void setup()
{
Serial.begin(115200);

tft.begin();
tft.setRotation(1);
tft.setBrightness(255); // works fine

if(!ts.begin(40, SDA_FT6236, SCL_FT6236)){
Serial.println(“Unable to start the capacitive touch Screen.”);
}

lv_init();
Serial.println(“lv_init done”);
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * 10 );

/Initialize the display/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
Serial.println(“Display Init done”);
/Change the following line to your display resolution/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
Serial.println(“Set Display Properties done”);
/Initialize the (dummy) input device driver/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
Serial.println(“Set Dummy Input Device done”);
ui_init();
Serial.println(“ui_init() done”);
// tft.fillScreen(TFT_YELLOW);
}

void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay( 5 );
}

one level up …/libraries/ you need the following in it:

Thank you! I really appreciate it. I’m sure this is going to save me a lot of time!

Mike

Please go to this URL and select the firmware and flash it.
You only need a Browser and a USB cable.
https://iot.sukesh.me

Arduino sample is here

Integration with SquareLine Studio coming soon.

1 Like

hello

I also buy the wt32-sc01 plus
on the other hand I want to upload the program from arduino IDE 2.0. is it possible.

because i am using esp32-dev module, with com port 12 on my pc.
the arduino ide compiles the program but fails to flash the esp32

am I making a mistake?

I thank you

I found this: GitHub - FCam1/SC01_Plus_HMI_example: Arduino example using SquareLine Studio to make an HMI with an SC01_plus capacitive display.

It works perfect on my SC01 Plus. I just copy the files from squareline after exporting them

Hi there, please, I need a very, very simple example of configuration for the touchscreeen using squareline and wt32-sc01 (not plus), and no tux please… tux is the only place where the sc01+lvgl+touch is mention, but is a bit complex, just need a simple working example, I finally got the images from squareline to upload but was not, so far, able to use the touch.
I have tried adding lovyan but with no luck.
it is hard to believe, but I could not find a simple example for this board like a simple on/off touch button using squareline.
the example in the tux page using only the touchscreen without lvgl is great and works, but I’d like to add the nicer looking from squareline.

thank you very much

Can you link the driver which work without LVGL?

Making an already working driver work with LVGL is quite simple. See here.

Hi kisvegabor, I have looked before at that link, I did again but still can’t make it work.
this example from the tux gitub works perfectly fine in my wt32-sc01, but i am missing something trying to add the code on the UI from squareline:

/* Simple Touch Drawing sample for WT32-SC01 */ #define LGFX_AUTODETECT // Autodetect board #define LGFX_USE_V1 // set to use new version of library

#include <LovyanGFX.hpp> // main library

static LGFX lcd; // declare display variable

// Variables for touch x,y
static int32_t x,y;

void setup(void)
{
Serial.begin(115200);
Serial.print(“ready”);
lcd.init();

// Setting display to landscape
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);

lcd.setCursor(0,0);
lcd.printf(“Ready to touch & draw!”);
}

void loop()
{
if (lcd.getTouch(&x, &y)) {
lcd.fillRect(x-2, y-2, 5, 5, TFT_RED);
lcd.setCursor(380,0);
lcd.printf(“Touch:(%03d,%03d)”, x,y);
Serial.printf(“Touch:(%03d,%03d)”, x,y);
Serial.println();

if (x > 200 && x < 300)
{
  if (y > 150 && y < 250)
  {
    lcd.setCursor(380, 300);
    lcd.print("GOT IT");
  }  
}

}
}

You need something like this:

void my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
   int32_t x,y;
   if (lcd.getTouch(&x, &y)) {
      data->point.x = x;
      data->point.y = y;
      data->state = LV_INDEV_STATE_PRESSED;
   } else {
      data->state = LV_INDEV_STATE_RELEASED; 
   }
}
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_input_read;
lv_indev_register(&indev_drv);

thanks again for the answer.
I had tried like that before, but when I do, I get this errors:

In file included from

 c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\common.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/esp32/Bus_SPI.hpp:51,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/device.hpp:50,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1_init.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/LovyanGFX.hpp:31,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:8:
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:182:32: error: 'SeekMode' has not been declared
     bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); }
                                ^~~~~~~~
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp: In member function 'virtual void lgfx::v1::FileWrapper::skip(int32_t)':
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:180:55: error: 'SeekCur' was not declared in this scope
     void skip(int32_t offset) override { seek(offset, SeekCur); }
                                                       ^~~~~~~
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:180:55: note: suggested alternative:
In file included from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/Processors/TFT_eSPI_ESP32.h:137,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/TFT_eSPI.h:100,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:2:
C:\Users\Neptuno\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\FS\src/FS.h:43:5: note:   'SeekCur'
     SeekCur = 1,
     ^~~~~~~
In file included from c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\common.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/esp32/Bus_SPI.hpp:51,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/device.hpp:50,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1_init.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/LovyanGFX.hpp:31,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:8:
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp: In member function 'virtual bool lgfx::v1::FileWrapper::seek(uint32_t)':
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:181:63: error: 'SeekSet' was not declared in this scope
     bool seek(uint32_t offset) override { return seek(offset, SeekSet); }
                                                               ^~~~~~~
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:181:63: note: suggested alternative:
In file included from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/Processors/TFT_eSPI_ESP32.h:137,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/TFT_eSPI.h:100,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:2:
C:\Users\Neptuno\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\FS\src/FS.h:42:5: note:   'SeekSet'
     SeekSet = 0,
     ^~~~~~~
In file included from c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\common.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/esp32/Bus_SPI.hpp:51,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1/platforms/device.hpp:50,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/lgfx/v1_init.hpp:22,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\arduino_443962\src/LovyanGFX.hpp:31,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:8:
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp: In member function 'bool lgfx::v1::FileWrapper::seek(uint32_t, int)':
c:\users\neptuno\documents\arduino\libraries\arduino_443962\src\lgfx\v1\platforms\esp32/common.hpp:182:74: error: invalid conversion from 'int' to 'fs::SeekMode' [-fpermissive]
     bool seek(uint32_t offset, SeekMode mode) { return _fp->seek(offset, mode); }
                                                                          ^~~~
In file included from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/Processors/TFT_eSPI_ESP32.h:137,
                 from C:\Users\Neptuno\Documents\Arduino\libraries\TFT_eSPI/TFT_eSPI.h:100,
                 from C:\Users\Neptuno\Documents\Arduino\ui_test\ui_test.ino:2:
C:\Users\Neptuno\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\FS\src/FS.h:66:38: note:   initializing argument 2 of 'bool fs::File::seek(uint32_t, fs::SeekMode)'
     bool seek(uint32_t pos, SeekMode mode);
                             ~~~~~~~~~^~~~
exit status 1
Error compiling for board ESP32 Wrover Kit (all versions).

and this is my ui.ino:

#include <lvgl.h>
#include <TFT_eSPI.h>
#include "ui.h"

#define LGFX_AUTODETECT     // Autodetect board
#define LGFX_USE_V1         // set to use new version of library

#include <LovyanGFX.hpp>    // main library

static LGFX lcd;            // declare display variable

// Variables for touch x,y
static int32_t x,y;

/*If you want to use the LVGL examples,
  make sure to install the lv_examples Arduino library
  and uncomment the following line.
#include <lv_examples.h>
*/

/*Change to your screen resolution*/
static const uint16_t screenWidth  = 480;
static const uint16_t screenHeight = 320;

static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * screenHeight / 10 ];

TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */

#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(const char * buf)
{
    Serial.printf(buf);
    Serial.flush();
}
#endif

/* Display flushing */
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
    uint32_t w = ( area->x2 - area->x1 + 1 );
    uint32_t h = ( area->y2 - area->y1 + 1 );

    tft.startWrite();
    tft.setAddrWindow( area->x1, area->y1, w, h );
    tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
    tft.endWrite();

    lv_disp_flush_ready( disp );
}

/*Read the touchpad*/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
   int32_t x,y;
   if (lcd.getTouch(&x, &y)) {
      data->point.x = x;
      data->point.y = y;
      data->state = LV_INDEV_STATE_PRESSED;
   } else {
      data->state = LV_INDEV_STATE_RELEASED; 
   }
}



void setup()
{
    Serial.begin( 115200 ); /* prepare for possible serial debug */

    String LVGL_Arduino = "Hello Arduino! ";
    LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();

    Serial.println( LVGL_Arduino );
    Serial.println( "I am LVGL_Arduino" );

    lv_init();

#if LV_USE_LOG != 0
    lv_log_register_print_cb( my_print ); /* register print function for debugging */
#endif

    tft.begin();          /* TFT init */
    tft.setRotation( 3 ); /* Landscape orientation, flipped */

    lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 10 );

    /*Initialize the display*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init( &disp_drv );
    /*Change the following line to your display resolution*/
    disp_drv.hor_res = screenWidth;
    disp_drv.ver_res = screenHeight;
    disp_drv.flush_cb = my_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    lv_disp_drv_register( &disp_drv );

    /*Initialize the (dummy) input device driver*/
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init( &indev_drv );
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = my_touchpad_read;
    lv_indev_drv_register( &indev_drv );


    ui_init();

    Serial.println( "Setup done" );
}

void loop()
{
    lv_timer_handler(); /* let the GUI do its work */
    delay(5);
}