# Squareline GUI + Sunton ESP32-8048S043 4.3" 800x480 capacitive touch display

**URL:** <http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130>\
**Category:** How to\
**Created:** [November 23, 2023, 12:19pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130 "2023-11-23T12:19:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 23, 2023, 12:19pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/1 "2023-11-23T12:19:27Z")

</div>

Hello,

I am trying for days now to cobble together different code snippets for ESP32 display / GUI programming with low success rate. I got the LVGL widget demo running ([GitHub - zingo/Sunton\_ESP32-8048S043: Basic LVGL demo setup of Sunton ESP32-S3 4.3" 800\*480 IPS with Touch](https://github.com/zingo/Sunton_ESP32-8048S043/tree/main)).

But no success yet uploading / changing the code to integrate and start with custom UI generated by Squareline. Also compile errors trying to use newer GFX library versions.

Can anybody help me with a basic code package in VSCode/PlatformIO utilizing arduino and current libraries:

```auto
lib_deps = 
	moononournation/GFX Library for Arduino@^1.4.0
	lvgl/lvgl@^8.3.9
	tamctec/TAMC_GT911@^1.0.2
	SPI@^2.0.0
	Wire@^2.0.0

```

With a working UI (made in squareline, simple button transition from screen 1 \> screen 2) so I can go from there?

My hardware is a Sunton ESP32-8048S043 4.3" 800x480 capacitive touch display.

---

<div class="post-metadata">

**Author:** ![kgschlosser](http://forum.squareline.io/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@kgschlosser](http://forum.squareline.io/u/kgschlosser)\
**Post date:** [November 23, 2023, 10:51pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/2 "2023-11-23T22:51:38Z")

</div>

I am actually going to be helping another person with a Sunton display accomplish the same exact thing you are trying to do. So I can kill 2 birds with one stone and get it going for you as well.

---

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 24, 2023, 8:41am UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/3 "2023-11-24T08:41:13Z")

</div>

In the meantime after a TON of trial and error I finally got it working! Showing a pretty basic test UI project from Squareline.

See my full project attached for VSCode on Github. Hope it works … it is my first upload.

Do not expect extensive support though … 😆

> **[GitHub - pixelwave/Sunton-ESP32-8048S043: First test with Sunton ESP32-8048S043...](https://github.com/pixelwave/Sunton-ESP32-8048S043/tree/main)**
>
> main

---

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 24, 2023, 2:28pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/4 "2023-11-24T14:28:33Z")

</div>

But for my last puzzle piece I need some further help.

I now have everything setup, display works with Squareline GUI and touch as well.

What I am trying to achieve is when a button on the Squareline GUI is pressed, a HEAD http request is send.

I have the connect to Wifi and Http request script and it works in the main.cpp:

```auto
// Wifi Setup
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "PUT-SSID-HERE"; // Replace with your network SSID (name)
const char* password = "PUT-PW-HERE"; // Replace with your network password

void setup() {
  Serial.begin(115200); // Begin serial communication at 9600 baud rate

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void sendHEADRequest(String url) {
  HTTPClient http;
  // Your URL for the HEAD request
  http.begin(url);
  int httpCode = http.sendRequest("HEAD");
  //http.end();
}

void loop()
{
  // Head Request Test -> BLUE COLOR
  sendHEADRequest("http://192.168.178.59/win&A=128&FX=0&R=0&G=0&B=255"); // Replace with your URL
  Serial.println("Head request send!!!");
  delay(3000); // Debouncing delay
}

```

But putting the code in the main.cpp obviously does not work in combination with the button press. I identified the function call for my button is in “ui.c”:

```auto
///////////////////// FUNCTIONS ////////////////////
void ui_event_Button1( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_RELEASED) {
      _ui_screen_change( &ui_Screen2, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen2_screen_init);
      _ui_screen_delete( &ui_Screen1);
}

```

But if I just change it to:

```auto
void ui_event_Button1( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_RELEASED) {
      _ui_screen_change( &ui_Screen2, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_Screen2_screen_init);
      _ui_screen_delete( &ui_Screen1);
      sendHEADRequest("http://192.168.178.59/win&A=128&FX=0&R=0&G=255&B=0"); // Replace with your URL
}

```

… it throws a couple of errors because of course the ui.c files is not aware of the libraries and function definitions.

I am quite new to C … could someone help me understand this and get it to work? What would be the easiest way to make “ui.c” aware of the function … or to put it there directly? But then I get a few errors because some libraries are missing / not correctly routed to that file…

---

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 24, 2023, 5:19pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/5 "2023-11-24T17:19:20Z")

</div>

If I have the setup:

main.cpp with the function:

```auto
void myFunction() {
  sendHEADRequest("http://192.168.178.59/win&A=128&FX=0&R=0&G=255&B=0");
}

```

main.h with the declaration:

```auto
// MAIN.h
#ifndef MAIN_H
#define MAIN_H

void myFunction();

#endif

```

ui.c with the call:

```auto
#include "main.h"
...
void ui_event_Button3( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_RELEASED) {
      greenBtn( e );
      myFunction();
}

```

… why do I get an error: “undefined reference to `myFunction’”

---

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 24, 2023, 5:35pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/6 "2023-11-24T17:35:35Z")

</div>

IT WORKS NOW!

… as expected … C/C++ basic language understanding is my problem. But this solves my problem:

main.h

```auto
#ifndef MAIN_H
#define MAIN_H

#ifdef __cplusplus

extern "C"
{

#endif

//declare functions here
  void myFunction();

#ifdef __cplusplus

}

#endif

#endif

```

main.cpp

```auto
#include "main.h"
...
extern "C" void myFunction() {
  sendHEADRequest("http://192.168.178.59/win&A=128&FX=0&R=0&G=255&B=0");
}

```

ui.c

```auto
#include "main.h"
...
void ui_event_Button3( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_RELEASED) {
      greenBtn( e );
      myFunction();
}

```

Great! Now I have everything to build my remote controller. 😀

---

<div class="post-metadata">

**Author:** ![Marian\_M](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@Marian\_M](http://forum.squareline.io/u/Marian_M)\
**Post date:** [November 25, 2023, 11:01am UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/7 "2023-11-25T11:01:32Z")

</div>

Yop but ui.c is not place for edit code… Learn use events in squareline  
Yuo can choice ui\_events.c or cpp

---

<div class="post-metadata">

**Author:** ![pixelwave](http://forum.squareline.io/letter_avatar_proxy/v4/letter/p/0ea827/32.png) [@pixelwave](http://forum.squareline.io/u/pixelwave)\
**Post date:** [November 25, 2023, 12:54pm UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/8 "2023-11-25T12:54:27Z")

</div>

Yes I moved my function calls there!

---

<div class="post-metadata">

**Author:** ![kgschlosser](http://forum.squareline.io/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@kgschlosser](http://forum.squareline.io/u/kgschlosser)\
**Post date:** [November 26, 2023, 1:02am UTC](http://forum.squareline.io/t/squareline-gui-sunton-esp32-8048s043-4-3-800x480-capacitive-touch-display/2130/9 "2023-11-26T01:02:50Z")

</div>

> [@Sunton ESP32 5.0" RGB display board](https://forum.squareline.io/t/sunton-esp32-5-0-rgb-display-board/2145):
>
> I have attached a board I made for Squareline Studio for the Sunton ESP32\_8048S050C board. This is the 5.0" display with capacitive touch. It uses ESP-IDF \>= 5.0.4 and LVGL 8.3.x There is no lv\_conf.h included so that will need to be added to the exported code. Be sure to enable the user data in the lv\_conf.h file. This should also work for other Sunton displays, you might have to change the pin numbers located at the top of the main.c file. This uses the rgb panel API that is in the esp\_lcd co…

That is a working board for Squareline Studio
