I want to push a button, and on pressed, change an image (with another color), and when the button is released, change the image back to the original one.
In my squareline simulator, this works perfect, but in arduino, nothing happens when pushing the button.
I tried different ways of events by setting properties of the image and change the picture, tried to call a function : ui_event_Button1 (this is in my case put in ui.c, whereas in some literature, I read it would be in ui_events.c …has Squareline a manual with details of how the structure is written ?)
There was also no touch screen library included like XPT2046_Touchscreen.h, so how can your button press then be detected ? I added XPT2046_Touchscreen.h, and this works in arduino, but not with the squareline project.
Do you use the Arduino-TFT_eSPI board-template? It doesn’t have the XPT2046 set in the ui.ino file by default because it’s a multi-purpose board-template. Maybe that’s your problem. Does the touch work with a simple button or other widgets? If not, you should init the touchscreen-driver in ui.ino and uncomment the commented-out tft.getTouch in my_touchpad_read, etc.
(If you’d like to see a working Arduino example with TFT_eSPI and XPT2046 touch-driver, Raspberry PI Pico board-template main.cpp is a working tested one.)
Yes, use arduino tft_espi template, and included manually the xpt2046 touch screen, which is working, I get x-y coordinates, and use them to change an output on a pin, but the event does not seem to respond to the button press, seems not to be linked to the coordinates of the touchscreen.
Where can I find the working example you mentioned?
Do I need to call the created event/function in some way?
This looks to be a problem that most arduino users face… How did they solve it?
So it seems your separate driver is working, maybe the problem is connecting it with LVGL touchpad-read callback. However there’s a built-in XPT2046 driver in TFT_eSPI and I use that in the Raspberry Pico board-template, I tink you should try that scenario. The Pico board-template is available online: GitHub - SquareLineStudio/board_raspberry_pi_pico at v1.0.0
(And of course you can find it in SquareLine Studio at the ‘create’ page and it gets downloaded to ‘boards’ folder if you select it and create a new project with it. It’s Pico-SDK based though, not Arduino-IDE based, but the driver-init code can be used there too.)
After you complete the touchscreen-read callback with your touchscreen-read function and connect it to an ‘indev’ registered for the display, it gets called periodically by LVGL (at a refresh rate found in lv_conf.h), so you don’t need to call it yourself.
How others solved this? Let’s see if we get some other replies…
Hi Hermit,
I restarted with the file created by SLS. (no #include XPT2046_Touchscreen.h ), assuming as you said, it is included in the TFT_eSPI.
As SLS project is using a button pressed, it is clear that the touchscreen “is” used, so I am puzzled why the output of SLS is showing : bool touched = false;//tft.getTouch( &touchX, &touchY, 600 ); whereas it should be : bool touched = tft.getTouch( &touchX, &touchY, 600 );…anywhay, this does not solve the problem.
Also, in your referred pico files, there is in LV_CONF.h a difference : #define LV_MEM_CUSTOM 1 whereas in my file, it is 0. Changing this also did not affect.
It looks like the touch function is not working in the SLS created Arduino file(s). (do you have a file/project that is working with touch in Arduino ? If so, please provide it and I can compare where it is going wrong.
This Arduino TFT_eSPI is a multi-purpose board-template, I guess that’s why the touch-request is commented out since its 1st versions, so XPT2046 in TFT_eSPI is not forced on the user. It’s not enough to comment that out, the touch should also be initialized together with the LCD and set/calibrated (by tft.begin and tft.setTouch).
Yes, there are some working examples that use XPT2046 of TFT_eSPI in Arduino-IDE, for example take a look at Elecrow’s RP2040 3.5inch Pico board: Pico HMI 3.5-inch Arduino Tutorial - Elecrow Wiki