Skip to content
We have moved: pcb.esp32s.com → pcb32.comSame store. Existing accounts, orders and affiliate commission records are unchanged.
Номер заказа: USD
Номер заказа: USD
pcb32.com
Cart 0

Освоение ESP32 CYD и LVGL: Полное руководство по отображению пользовательских изображений на вашем дешевом желтом дисплее.

Looking to add crisp, custom graphics to your next smart home interface or IoT project? If you own the popular ESP32-2432S028R, better known as the Дешевый желтый дисплей (CYD) , displaying high-quality images is a crucial step in creating a professional-looking user interface.

This comprehensive guide, updated for 2026, walks you through the exact process of converting and displaying any image on your CYD using LVGL (Light Versatile Graphics Library) and the Arduino IDE. Whether you want to show a company logo, a family photo, or custom icons for your smart device controller, this tutorial provides the battle-tested code and configuration you need to get it right the first time.

Stop struggling with blank screens and library conflicts. Let’s turn your CYD into a vibrant display powerhouse.

Why This Guide is Different: Built on EEAT Principles

Before diving into the code, it’s critical to understand why following a precise, authoritative guide matters. The ESP32-CYD ecosystem relies on specific library versions and configurations. A generic tutorial using the wrong lv_conf.h или User_Setup.h file will lead to compilation errors and frustration. This guide is built on hands-on testing with the exact hardware and software versions to ensure your success.

What You’ll Need: The Hardware and Software Foundation

Требования к оборудованию
To follow this project, you need just one key component:

Software Prerequisites (Crucial for Success)
Your development environment must be set up with precision. Following steps from random sources will likely cause your project to fail. You must complete the following setups using our verified guides:

  1. Arduino IDE with ESP32 Core: Ensure you have the Arduino IDE installed and the Платы ESP32 package added. If you haven’t done this, follow our detailed tutorial: [Install ESP32 Boards in Arduino IDE].

  2. LVGL Library (Version 9.2): LVGL is the graphics library that makes creating beautiful interfaces possible. You need to install the specific version 9.2 by kisvegabor.

    • ⚠️ CRITICAL: The default lv_conf.h library configuration file will not work. You должен use the specific configuration file provided in our dedicated [CYD LVGL Getting Started Guide].

  3. TFT_eSPI Library: This library by Bodmer handles the low-level communication with the display.

    • ⚠️ CRITICAL: Similarly, the standard User_Setup.h file for the TFT_eSPI library is not configured for the CYD’s specific pins. You должен use the custom setup file from our [CYD LVGL Getting Started Guide].

Once these libraries are correctly configured, you are ready to display images.

Step 1: Preparing Your Image for LVGL (The image.h File)

LVGL does not use standard JPEG or PNG files directly. You must convert your image into a C-style byte array that the library can render efficiently. Here is the exact process:

  1. Use the Official LVGL Image Converter: Navigate to the official LVGL image converter tool at lvgl.io/tools/imageconverter. Always use the official tool to ensure compatibility.

  2. Set the Correct Parameters:

    • Версия: Select LVGL v9 (must match your library version).

    • Image File: Choose the image you want to display (e.g., a logo, icon, or photo). For best results on the 240×320 screen, keep your image dimensions manageable (e.g., 128×128 pixels) to save memory.

    • Color Format: Select ARGB8888. This format provides the best color depth for your display.

    • Нажмите Convert button.

  3. Extract the Image Data: The tool will download a .c file. Open it with a text editor. Inside, you’ll find a large array of hexadecimal numbers enclosed in curly brackets { ... }. Copy only the content inside the brackets, including the numbers.

  4. Create Your image.h Header File: In your Arduino sketch folder, create a new file and name it image.h. Open it and paste the template structure provided below.

  5. Integrate Your Image Data: In the template, locate the line:

    c
    константа LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_MY_IMAGE uint8_t my_image_map[] = {REPLACE_WITH_YOUR__IMAGE_ATTRIBUTE};

    Replace {REPLACE_WITH_YOUR__IMAGE_ATTRIBUTE} with the hexadecimal data you copied from the converted file. Important: Do not rename my_image_map или my_image unless you are comfortable changing the variable names in the main code as well.

  6. Set Image Dimensions: Scroll down in your image.h file. Find the lv_image_dsc_t my_image structure. Modify the .w = 128 и .h = 128 lines to match the actual width and height of the image you converted.

    c
    константа lv_image_dsc_t my_image = {
        .заголовок = {
            .magic = LV_IMAGE_HEADER_MAGIC,
            .cf = LV_COLOR_FORMAT_ARGB8888,
            .w = 128,      // <-- CHANGE TO YOUR IMAGE WIDTH
            .h = 128,       // <-- CHANGE TO YOUR IMAGE HEIGHT
            // ...
        },
        // ...
    };
  7. Save and Place the File: Save image.h. Это должен reside in the same folder as your main Arduino .ino sketch file. Your Arduino IDE will automatically show it as a second tab.

Step 2: The Arduino Code for Displaying the Image

With your image.h file prepared, you can now use the following code. This sketch initializes the display, LVGL, and renders your image.

Create a new Arduino sketch and paste the code below. Ensure the sketch is saved in a folder with the same name as the .ino file, and that your image.h file is inside that folder.

c
/* Rui Santos & Sara Santos - Random Nerd Tutorials
   Based on the guide at: https://RandomNerdTutorials.com/esp32-cyd-lvgl-display-image/ */

/*  REQUIRED LIBRARIES (with specific configurations)
    - lvgl library version 9.2 by kisvegabor: https://lvgl.io/
    - TFT_eSPI library by Bodmer: https://github.com/Bodmer/TFT_eSPI
    *** YOU MUST USE THE CUSTOM lv_conf.h AND User_Setup.h FILES FROM: ***
    *** https://RandomNerdTutorials.com/cyd-lvgl/ ***
*/

#включать <lvgl.h>
#включать <TFT_eSPI.h>
#включать "image.h" // Include your custom image data

// Screen dimensions for the CYD
#определять ШИРИНА_ЭКРАНА 240
#определять ВЫСОТА_ЭКРАНА 320

// Drawing buffer for LVGL
#определять DRAW_BUF_SIZE (ШИРИНА_ЭКРАНА * ВЫСОТА_ЭКРАНА / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

// LVGL log function for debugging via Serial Monitor
пустота log_print(lv_log_level_t level, константа чар * buf) {
  LV_UNUSED(level);
  Серийный номер.println(buf);
  Серийный номер.flush();
}

// Function to create and align the image object
пустота draw_image(пустота) {
  LV_IMAGE_DECLARE(my_image); // Declare the image from image.h
  lv_obj_t * img1 = lv_image_create(lv_screen_active()); // Create image object on active screen
  lv_image_set_src(img1, &my_image); // Set the image source
  lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0); // Align to the center of the screen
}

пустота настраивать() {
  // Initialize Serial for debugging
  Серийный номер.начинать(115200);
  Серийный номер.println("Starting ESP32 CYD Image Display...");
  String LVGL_Arduino = Нить("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  Серийный номер.println(LVGL_Arduino); // Verify you are using LVGL v9

  // Initialize LVGL core
  lv_init();
  lv_log_register_print_cb(log_print); // Register the debug print function

  // Create the LVGL display object using the TFT_eSPI driver
  lv_display_t * disp;
  disp = lv_tft_espi_create(ШИРИНА_ЭКРАНА, ВЫСОТА_ЭКРАНА, draw_buf, sizeof(draw_buf));
  lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270); // Correct rotation for CYD

  // Draw the image on the screen
  draw_image();
  Серийный номер.println("Image drawing function called.");
}

пустота петля() {
  // This is the LVGL engine: let it handle tasks and timing
  lv_task_handler(); // Let LVGL perform its rendering tasks
  lv_tick_inc(5);    // Inform LVGL that 5ms have passed
  задерживать(5);          // Small delay to prevent watchdog triggers
}

Understanding the Core Functions

  • lv_tft_espi_create(): This function, provided by the LVGL library’s TFT_eSPI driver integration, links the display hardware to LVGL using your correctly configured User_Setup.h.

  • LV_IMAGE_DECLARE(my_image);: This macro tells the compiler that my_image is an external variable defined in your image.h file.

  • lv_image_create() и lv_image_set_src(): These functions create an LVGL image object and assign your custom image data as its source.

  • Он петля() Функция: The calls to lv_task_handler() и lv_tick_inc() are mandatory for LVGL to operate. They process graphical tasks and keep time for animations.

Uploading and Verifying Your Project

  1. Check Your Files: In your Arduino IDE, ensure you have two tabs: one for your main .ino file and one for image.h.

  2. Select Board and Port: Go to Tools > Доска and select ESP32 Dev Module. Then, select the correct COM port under Tools > Port.

  3. Загрузить: Click the upload button (right arrow). The compilation process will include your image.h file automatically.

  4. Результат: After a successful upload, your CYD screen should clear and display your custom image perfectly centered, just like the example below.

(Image: Your custom image displayed on the CYD screen)

Устранение распространенных проблем

  • “Image won’t display / garbled colors”: This is almost always a library configuration issue. Double-check that you have used the exact lv_conf.h и User_Setup.h files from our setup guide. Also, verify you selected ARGB8888 in the image converter.

  • “Compilation Error: ‘my_image’ was not declared”: Your image.h file is likely not in the correct folder. It must be in the same directory as your .ino file. Check the Arduino IDE tabs.

  • “Brownouts / Restarts”: Large images consume significant RAM. Try using a smaller image (e.g., 100×100 pixels) and ensure your power supply is adequate (a good USB cable and port make a big difference).

Taking Your CYD Projects Further

Displaying a static image is just the beginning. With LVGL, you can layer images with buttons, create animated sprites, and build a complete touch-based user interface for your projects. Imagine a smart home controller with logos for lights and thermostats, or a retro game console with custom sprites.

If you’re ready to move from static images to fully interactive dashboards, our in-depth eBook, “Build a Home Automation System for Beginners,” guides you through combining the ESP32, LVGL, and practical IoT protocols like MQTT to create a professional, real-world project.

Conclusion: Your CYD, Your Vision

You now have the authoritative, field-tested knowledge to display any image on your Дешевый желтый дисплей ESP32. By following this guide, you’ve avoided the common pitfalls of incorrect library configurations and learned the proper workflow for converting and integrating image assets with LVGL.

Он CYD is an incredibly powerful tool for makers, and mastering its display capabilities opens the door to creating IoT devices with user interfaces that look as good as they function. Now, go ahead and make your display truly your own.

======================================

О сайте ESP32S.com

С 2016 года, ESP32S.com Наша компания превратилась в полноценного партнера по экосистеме для вашего развития в сфере Интернета вещей. Расположенная в Шэньчжэне, глобальном центре инноваций в электронике, мы помогли сотням разработчиков и компаний реализовать свои проекты. ESP32Воплощаем идеи в жизнь. Наша команда стремится оказывать исключительную поддержку и предлагать инновационные решения, которые помогут вам достичь ваших целей в области Интернета вещей.
В ESP32S.com, мы осваиваем тонкости разработки ESP32Разработка продукта, основанного на концепции, включает в себя множество этапов, от разработки до вывода на рынок. Именно поэтому мы предлагаем комплексные решения, охватывающие весь жизненный цикл продукта. ESP32Устройства на базе [технологии]. Независимо от того, нужна ли вам помощь в проектировании печатных плат, создании прототипов, производстве или даже маркетинге и доставке, мы вам поможем.

Свяжитесь с нами

Готовы вывести свой IoT-проект на новый уровень? Свяжитесь с ESP32S.com Узнайте больше о наших комплексных решениях уже сегодня! ESP32Устройства на базе [технологии]. Позвольте нам стать вашим надежным партнером в воплощении ваших инновационных идей в жизнь. Свяжитесь с нами прямо сейчас для начала.