Posted on

Adding Touchscreen Functionality to ESP32-S3 HMI

Adding Touchscreen Functionality to ESP32-S3 HMI
Adding Touchscreen Functionality to ESP32-S3 HMI

ESP32 NORVI HMI is a powerful HMI resistive touch screen with an 800*480 resolution LCD display. It uses the ESP32-S3-WROOM-1-N4R8 module as the main control processor, with a dual-core 32-bit microprocessor, integrated WiFi and Bluetooth wireless functions, a main frequency of up to 240MHz, providing powerful performance and versatile applications, suitable for IoT application devices and other scenes. Let’s see how advanced Touchscreen Functionality works with ESP32 HMI.

The module includes a 5.0-inch LCD display and a driver board. The display screen uses resistive touch technology. It supports a development environment such as Arduino IDE and is compatible with the LVGL graphics library. This enables developers to customize their UI interfaces and create interesting projects quickly and easily, greatly shortening the development cycle.

A 5-inch resistive touch display is a touchscreen technology with a layered structure, comprising a flexible top layer and a rigid bottom layer separated by insulating dots. When pressure is applied, these layers make contact at specific points, and touch input is detected by measuring changes in voltage. Some common features of the touch panel are,

  • Accuracy and Pressure Sensitivity: Resistive touchscreens provide accurate touch input by detecting the precise point of contact.
  • Cost-Effectiveness: Resistive touch panels are cost-effective to produce, making them a popular choice for budget-friendly displays.
  • Versatility and Compatibility: Compatible with various input methods, resistive touchscreens can be operated with any object that applies pressure.
  • Calibration Requirements: Periodic calibration may be necessary to maintain accurate touch response.

To add the Touchscreen Functionality to an ESP32-S3 HMI, it will need to use a combination of the ESP32-S3 microcontroller, a suitable Touch library, and the LVGL  graphics library. Below are the general steps to add these functionalities:

  1. Set Up Development Environment:

Install Arduino IDE on PC.

Integrate ESP32 board support in Arduino IDE.

Install required libraries for ESP32, touch, and LVGL. 

The Touch library may need to use a library that is compatible with the specific 5-inch resistive touch.

  1. Include Libraries in Arduino Sketch:

Include the required libraries at the beginning of the Arduino sketch:

#include <XPT2046_Touchscreen.h>

#include <lvgl.h>

 

  1. Initialize Touch parameters:
  • Initialize the set points

The touch screen set points are configured through an example code provided by a touch library. By executing the code and interacting with the four sides of the display, the corresponding values are displayed in the serial monitor. This process enables the determination of touchscreen set points based on the user’s input and observation of the serial output.

#define TOUCH_MAP_X1 270

 #define TOUCH_MAP_X2 3800

 #define TOUCH_MAP_Y1 3600

 #define TOUCH_MAP_Y2 330

  • Variables touch_last_x and touch_last_y store the last touched coordinates.

int touch_last_x = 0, touch_last_y = 0;

#if defined(TOUCH_XPT2046)

XPT2046_Touchscreen ts(TOUCH_XPT2046_CS, TOUCH_XPT2046_INT);

  • Touch Initialization Function.

void touch_init() {

#if defined(TOUCH_XPT2046)

  SPI.begin(TOUCH_XPT2046_SCK, TOUCH_XPT2046_MISO, TOUCH_XPT2046_MOSI, TOUCH_XPT2046_CS);

  ts.begin();

  ts.setRotation(TOUCH_XPT2046_ROTATION);

  • Check for Touch Signal.

bool touch_has_signal() {

#if defined(TOUCH_XPT2046)

  return ts.tirqTouched();

  • Check if Touched

bool touch_touched() {

#if defined(TOUCH_XPT2046)

  if (ts.touched())  {

    TS_Point p = ts.getPoint();

  • Check if Touch Released.

bool touch_released(){

if defined(TOUCH_XPT2046)

  return true;

 

Example

This touch code provides an abstraction layer for the touch library, allowing the user to easily understand. The code includes initialization, event handling, and functions to check if the screen is touched or released. 

If buttonXMin, buttonXMax, buttonYMin, and buttonYMax represent the borders or boundaries of the region on the touch screen corresponding to the position of the button. let’s see how to configure a button, and set its action. 

#include <XPT2046_Touchscreen.h>

#define TOUCH_CS 10 // Example pin for touch CS

XPT2046_Touchscreen ts(TOUCH_CS);

#define BUTTON_PIN 7 // Example pin for the button

void setup() {

  Serial.begin(9600);

  ts.begin();

  pinMode(BUTTON_PIN, INPUT);

}

void loop() {

  // Read touch input

  TS_Point p = ts.getPoint();

  // Check if the touch screen is touched

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

    // Process touch input (e.g., map coordinates, perform actions)

    int mappedX = map(p.x, TS_MINX, TS_MAXX, 0, 800); // Adjust based on display size

    int mappedY = map(p.y, TS_MINY, TS_MAXY, 0, 480); // Adjust based on display size

    Serial.print(“Touched at X: “);

    Serial.print(mappedX);

    Serial.print(“, Y: “);

    Serial.println(mappedY);

    // Check if the touch is in the region of the button

    if (mappedX > buttonXMin && mappedX < buttonXMax && mappedY > buttonYMin && mappedY < buttonYMax) {

      // Button is pressed, perform action

      Serial.println(“Button Pressed!”);

      // Add button action here

    }

  }

}

Hope you get the way of adding Touchscreen Functionality to ESP32-S3 HMI

Check-out the ESP32-S3 HMI or, contact us at s[email protected]

Posted on Leave a comment

Low-cost HMI with ESP32-S3 Chip & LVGL

Building a Low-cost HMI with ESP32-S3 Chip & LVGL for Innovative Projects

Low-cost HMI can be used for your innovative projects. Wondering how to choose and what are their features. Learn through this article.

The world of embedded systems has been witnessing a revolutionary transformation, marked by innovations that redefine the boundaries of technology. At the forefront of this evolution stands the NORVI ESP32 HMI, an ingenious fusion of the ESP32-S3 microcontroller, a versatile 5-inch TFT LCD, and the dynamic LVGL Graphics Library. This confluence presents an alluring solution for developers and enthusiasts seeking to create cost-effective yet high-performance Human-Machine Interfaces (HMIs).

Key 3 Features of Low-cost HMI

A Low-cost HMI (Human-Machine Interface) solution boasts three fundamental components.

Firstly, it integrates the ESP32-S3 Microcontroller, esteemed for its robust capabilities in handling IoT applications, equipped with Wi-Fi, Bluetooth, and a rich set of peripherals. Secondly,  it incorporates an 8-bit RGB 5-inch LCD complemented by a touch panel, offering a cost-effective yet visually engaging display solution, ideal for various interactive applications. Lastly, leverages the LVGL (LittlevGL) Graphics Library, renowned for its efficiency in creating intuitive user interfaces across diverse embedded systems. This amalgamation delivers an affordable yet powerful HMI platform suitable for numerous projects requiring graphical user interfaces and touch interaction. These Low-cost HMI features will be discussed one by one now.

Unveiling the ESP32-S3 Microcontroller

  • As the first feature of Low-cost HMI,  ESP32-S3 microcontroller can be identified.
  • The NORVI ESP32 HMI is based on the ESP32-S3 microcontroller, which has 45 physical GPIO pins. It utilizes 20 GPIO pins for the display and the majority of the remaining pins for various functions, including digital inputs, transistor outputs, and communication.
  • ESP32-S3 is best for low-power applications that require advanced Wi-Fi and Bluetooth capabilities.
  • ESP32-S3 is a newer and more advanced microcontroller, and as such, it is generally more expensive than ESP32. But ESP32-S3 is an enhanced variant of the ESP32 microchip. Compared with ESP32, ESP32-S3 supports larger, high-speed octal SPI flash, and PSRAM with configurable data and instruction cache. Prices for ESP32-S3 can range from around $5 to $15 per unit, depending on the specific model and features.
  • However, the NORVI ESP32 HMI has an integrated ESP32-S3 module, serving both UI functions and communication purposes. This integrated approach lends the NORVI ESP32 HMI a cost-effective and higher performance edge compared to the others.

8-bit RGB 5-inch LCD with touch panel: A Visual Delight

  • Second Low-cost HMI feature is LVGL 5inch LCD Display with 8-bit RG and resistive touch.
  • NORVI ESP32 HMI offers a crystal-clear 5-inch TFT LCD with resistive touch technology, ensuring a user-friendly and interactive experience.
  • TFT display has a resolution of 800×480 pixels and a high contrast ratio of 500:1, making it capable of rendering deep blacks and vibrant colors.  It also has a high brightness of 450cd/m2, making it suitable for use in both indoor and outdoor environments.
  • TFT display comes with optional resistive touch screen capability, allowing users to interact with the display through touch. This option allows for precise touch input using a stylus or finger.
  • 8-bit RGB is used to interface with large color displays. It sends 8 bits of data for each of the three colors, Red Green, and Blue every clock cycle. Since there are 24 bits of data transmitted every clock cycle, at clock rates up to 50 MHz, this interface can drive much larger displays at video frame rates of 60 Hz and up.RGB is Low-cost due to technology maturity but High performance.
  • Prices for a 5-inch TFT LCD can range from around $19 to $20 per unit, depending on the specific model and features.

Powering Creativity with LVGL Graphics Library

  • Third, the Low-cost HMI feature is LVGL library support which makes it more useful.
  • LVGL is the most popular free and open-source embedded graphics library that offers a wide range of features that can be used to create beautiful UIs for any display type. LVGL’s graphical elements are fully customizable.
  • It provides building blocks for creating user interfaces on embedded systems and it has advanced graphics features such as animation, also it supports a variety of input devices, including touch pads, mice, keyboards, and encoders. 
  • Especially, the library is hardware-independent, meaning it can be used with any microcontroller or display. 

Embracing the Future of Human-Machine Interaction

The ever-expanding landscape of embedded systems, the NORVI ESP32 HMI stands as a testament to the innovation driving the industry forward as positioning by Low-cost HMI. In the realm of creating low-cost Human-Machine Interfaces (HMIs), the fusion of the ESP32-S3 microcontroller with NORVI ESP32 HMI, alongside the integration of a versatile 5-inch TFT LCD and the dynamic LVGL Graphics Library, defines an enticing solution for developers and enthusiasts.Whether an experienced developer or a hobbyist embarking on a new project, this powerful combination offers the tools needed to bring ideas to life. In a world where seamless interaction between humans and machines is paramount, the NORVI ESP32 HMI and its companions pave the way for a new era of user-friendly and cost-effective solutions.                                     

Low-cost HMI is now available to buy from NORVI.

Visit the Product Page or, Contact Us at [email protected]

Stay Connected to get updated news on LVGL for HMI: Facebook : LinkedIn : Twitter: YouTube