ESP32 CYD with LVGL: Display Temperature with DS18B20 Sensor (Text and Arc)

In this guide, you’ll learn how to display temperature from the DS18B20 sensor on an ESP32 Cheap Yellow Display (CYD) using LVGL (Light Versatile Graphics Library). We’ll display the temperature using a text label and an arc (curved gauge) object. You’ll also learn how to style LVGL objects. The ESP32 will be programmed using Arduino IDE.

ESP32 CYD with LVGL Display Temperature with DS18B20 Sensor Text and Arc

New to the ESP32 Cheap Yellow Display? Start here: Getting Started with ESP32 Cheap Yellow Display Board – CYD (ESP32-2432S028R).

Project Overview

In this project, we’ll display the temperature from the DS18B20 sensor on the ESP32 CYD screen. The temperature will be displayed on a text label and represented on a curved gauge (arc).

The temperature text will be displayed in different colors depending on the following ranges:

  • < 10 °C (50 °F): the temperature will be displayed in blue color;
  • 10 °C (50 °F) < temperature < 29 °C (84°F): the temperature will be displayed in green color;
  • 29 °C (84°F) < temperature: the temperature will be displayed in red color.

If you don’t have a DS18B20 sensor, you can use a BME280, a DHT22, or any other sensor (that requires a maximum of two GPIOs to connect)… Or you can use random values to test the project.

With this tutorial, you’ll learn how to use LVGL to:

  • Display data on text labels;
  • Change the text color and size;
  • Create a curved gauge;
  • Change the colors of the gauge;
  • Set the gauge value.

Prerequisites

Before proceeding, make sure you follow the next prerequisites. You must follow all steps, otherwise, your project will not work.

1) Parts Required

For this project, you need the following parts

2) Install ESP32 Boards in Arduino IDE

Arduino IDE 2 Logo

We’ll program the ESP32 using Arduino IDE. Make sure you have the ESP32 boards installed. Follow the next tutorial:

3) Get familiar with the ESP32 Cheap Yellow Display

The ESP32-2432S028R development board has become known in the maker community as the “Cheap Yellow Display” or CYD for short. This development board, whose main chip is an ESP32-WROOM-32 module, comes with a 2.8-inch TFT touchscreen LCD, a microSD card interface, an RGB LED, and all the required circuitry to program and apply power to the board.

ESP32 Cheap Yellow Display CYD Board ESP32-2432S028R front

If this is your first time using the ESP32 Cheap Yellow Display, make sure to follow our getting started guide:

4) Install SPI and LVGL Libraries

LVGL (Light and Versatile Graphics Library) is a free and open-source graphics library that provides a wide range of easy-to-use graphical elements for your microcontroller projects that require a graphical user interface (GUI).

Logo LVGL Light and Versatile Graphics Library

Follow the next tutorial to install and configure the required libraries to use LVGL for the ESP32 Cheap Yellow Display using Arduino IDE.

5) Install DS18B20 Libraries

In this tutorial, we’ll use the DS18B20 sensor to get temperature readings. Follow the next tutorial to get familiar with the sensor and install the required libraries.

You’ll need to install the “OneWire” library by Paul Stoffregen and “DallasTemperature” library by Miles Burton.

Wiring the DS18B20 Temperature Sensor to the ESP32 CYD Board

We’ll use OneWire communication protocol to get data from the DS18B20 sensor. This communication protocol only requires one GPIO to connect with a microcontroller.

On the Cheap Yellow Display, there is an extended IO socket that allows you to connect external peripherals. We’ll connect the sensor to the CN1 connector, and we’ll use GPIO 27.

ESP32 Cheap Yellow Display Extended IO Connectors

Your board should have come with a little JST connector to access those GPIOs. You can check the diagram below to see how to connect the sensor to the board.

Wiring the DS18B20 Temperature Sensor to the ESP32 CYD Board
ESP32 TFT Cheap Yellow Display LVGL DS18B20 Circuit Wiring

Learn more about the CYD Pinout: ESP32 Cheap Yellow Display (CYD) Pinout (ESP32-2432S028R).

Displaying Temperature on ESP32 CYD using LVGL – Arduino Code

The following code will get temperature from the BME280 sensor and display it on a text label on the screen. The text color will vary depending on the temperature value.

/*  Rui Santos & Sara Santos - Random Nerd Tutorials
    CYD Project Details: https://RandomNerdTutorials.com/esp32-cyd-lvgl-temperature-ds18b20/
    TFT Project Details: https://RandomNerdTutorials.com/esp32-lvgl-ds18b20-tempreature-tft-display/
    
    THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE:
    1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd-lvgl/
    2) REGULAR ESP32 Dev Board + 2.8 inch 240x320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240x320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft-lvgl/
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
//  *** YOU MUST USE THE lv_conf.h AND User_Setup.h FILES PROVIDED IN THE NEXT LINKS IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/ 
//  Install the "lvgl" library version 9.X by kisvegabor to interface with the TFT Display - https://lvgl.io/ - IMPORTANT: lv_conf.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials
#include <lvgl.h>

//  Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI - IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials
#include <TFT_eSPI.h>

// Install OneWire and DallasTemperature libraries
#include <OneWire.h>
#include <DallasTemperature.h>

// GPIO where the DS18B20 is connected to
const int oneWireBus = 27;     

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

// SET VARIABLE TO 0 FOR TEMPERATURE IN FAHRENHEIT DEGREES
#define TEMP_CELSIUS 1    

#if TEMP_CELSIUS
  #define TEMP_ARC_MIN -20
  #define TEMP_ARC_MAX 40
#else
  #define TEMP_ARC_MIN -4
  #define TEMP_ARC_MAX 104
#endif

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

// If logging is enabled, it will inform the user about what is happening in the library
void log_print(lv_log_level_t level, const char * buf) {
  LV_UNUSED(level);
  Serial.println(buf);
  Serial.flush();
}

lv_obj_t * arc;

// Set the temperature value in the arc and text label
static void set_temp(void * text_label_temp_value, int32_t v) {
  sensors.requestTemperatures();
  // Get the latest temperature reading in Celsius or Fahrenheit
  #if TEMP_CELSIUS
    float ds18b20_temp = sensors.getTempCByIndex(0);
    if(ds18b20_temp <= 10.0) {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_BLUE), 0);
    }
    else if (ds18b20_temp > 10.0 && ds18b20_temp <= 29.0) {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_GREEN), 0);
    }
    else {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_RED), 0);
    }
    const char degree_symbol[] = "\u00B0C";
  #else
    float ds18b20_temp = 1.8 * sensors.getTempFByIndex(0) + 32;
    if(ds18b20_temp <= 50.0) {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_BLUE), 0);
    }
    else if (ds18b20_temp > 50.0 && ds18b20_temp <= 84.2) {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_GREEN), 0);
    }
    else {
      lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_RED), 0);
    }
    const char degree_symbol[] = "\u00B0F";
  #endif

  lv_arc_set_value(arc, map(int(ds18b20_temp), TEMP_ARC_MIN, TEMP_ARC_MAX, 0, 100));

  String ds18b20_temp_text = String(ds18b20_temp) + degree_symbol;
  lv_label_set_text((lv_obj_t*) text_label_temp_value, ds18b20_temp_text.c_str());
  Serial.print("Temperature: ");
  Serial.println(ds18b20_temp_text);
}

void lv_create_main_gui(void) {
  // Create an Arc
  arc = lv_arc_create(lv_screen_active());
  lv_obj_set_size(arc, 210, 210);
  lv_arc_set_rotation(arc, 135);
  lv_arc_set_bg_angles(arc, 0, 270);
  lv_obj_set_style_arc_color(arc, lv_color_hex(0x666666), LV_PART_INDICATOR);
  lv_obj_set_style_bg_color(arc, lv_color_hex(0x333333), LV_PART_KNOB);
  lv_obj_align(arc, LV_ALIGN_CENTER, 0, 10);

  // Create a text label in font size 32 to display the latest temperature reading
  lv_obj_t * text_label_temp_value = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_temp_value, "--.--");
  lv_obj_set_style_text_align(text_label_temp_value, LV_TEXT_ALIGN_CENTER, 0);
  lv_obj_align(text_label_temp_value, LV_ALIGN_CENTER, 0, 10);
  static lv_style_t style_temp;
  lv_style_init(&style_temp);
  lv_style_set_text_font(&style_temp, &lv_font_montserrat_32);
  lv_obj_add_style(text_label_temp_value, &style_temp, 0);

  // Create an animation to update with the latest temperature value every 10 seconds
  lv_anim_t a_temp;
  lv_anim_init(&a_temp);
  lv_anim_set_exec_cb(&a_temp, set_temp);
  lv_anim_set_duration(&a_temp, 1000000);
  lv_anim_set_playback_duration(&a_temp, 1000000);
  lv_anim_set_var(&a_temp, text_label_temp_value);
  lv_anim_set_values(&a_temp, 0, 100);
  lv_anim_set_repeat_count(&a_temp, LV_ANIM_REPEAT_INFINITE);
  lv_anim_start(&a_temp);
}

void setup() {
  String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  Serial.begin(115200);
  Serial.println(LVGL_Arduino);

  // Start the DS18B20 sensor
  sensors.begin();
  
  // Start LVGL
  lv_init();
  // Register print function for debugging
  lv_log_register_print_cb(log_print);

  // Create a display object
  lv_display_t * disp;
  // Initialize the TFT display using the TFT_eSPI library
  disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
  
 // Function to draw the GUI
  lv_create_main_gui();
}

void loop() {
  lv_task_handler();  // let the GUI do its work
  lv_tick_inc(5);     // tell LVGL how much time has passed
  delay(5);           // let this time pass
}

View raw code

How Does the Code Work?

Let’s take a look at how to get temperature from the DS18B20 sensor and update the text label and gauge periodically with the latest reading.

Alternatively, you can skip to the Demonstration section.

Including Libraries

In all your sketches, you need to include the lvgl.h and the TFT_eSPI.h libraries to display on the screen.

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

You need to include the OneWire and the DallasTemperature libraries to interface with the DS18B20 sensor.

#include <OneWire.h>
#include <DallasTemperature.h>

Declaring the DS18B20 Sensor

The data pin of the DS18B20 sensor is connected to GPIO 27.

// GPIO where the DS18B20 is connected to
const int oneWireBus = 27;    

We create a OneWire instance on that GPIO.

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);

Finally, we create a DallasTemperature object called sensors to refer to our sensor.

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

Celsius or Fahrenheit

Our code is prepared to display the temperature in Celsius or Fahrenheit degrees. To choose your desired unit, you can set the value of the TEMP_CELSIUS variable. It is set to 1 by default to display the temperature in Celsius degrees.

#define TEMP_CELSIUS 1    

If you want to display in Fahrenheit degrees instead, set it to 0.

#define TEMP_CELSIUS 0

Gauge Minimum and Maximum Values

On the following variables we define the minimum and maximum values for the gauge. For the temperature in Celsius, we’re defining a minimum of -20ºC and a maximum of 40ºC. For the temperature in Fahrenheit, we’re defining the minimum for -4ºF and the maximum for 104ºF.

#if TEMP_CELSIUS
  #define TEMP_ARC_MIN -20
  #define TEMP_ARC_MAX 40
#else
  #define TEMP_ARC_MIN -4
  #define TEMP_ARC_MAX 104
#endif

You can adjust those values depending on the temperature range you’ll be reading.

Defining the Display Width and Height

You need to define your display width and height in all your sketches that use LVGL. If you’re using the recommended display, the size is 320×240.

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

Creating a Drawing Buffer

You need to create a buffer to draw on the display as follows:

#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

You should also include this in all LVGL examples.

Debugging Function

For debugging with the LVGL library, you should use the log_print() function. It is defined below. Include it in all your sketches before the setup().

// If logging is enabled, it will inform the user about what is happening in the library
void log_print(lv_log_level_t level, const char * buf) {
  LV_UNUSED(level);
  Serial.println(buf);
  Serial.flush();
}

Global Gauge/Arc Object

We create a global LVGL object arc (that’s the curved gauge) so that we can access it inside all functions later on.

lv_obj_t * arc;

setup()

In the setup(), include the following lines for debugging. These will print the version of LVGL that you’re using. You must be using version 9.

String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
Serial.begin(115200);
Serial.println(LVGL_Arduino);

Initialize the DS18B20 Sensor

Intialize the DS18B20 sensor in the setup().

// Start the DS18B20 sensor
sensors.begin();

Initialize the LVGL Library

Initialize the LVGL Library by calling the lv_init() function in the setup().

// Start LVGL
lv_init();

Register Debugging Function

Register your log_print() function declared previously as a function associated with debugging LVGL.

// Register print function for debugging
lv_log_register_print_cb(log_print);

Create a Display Object

To write to the display, you must create a display object first. You need to do this in all your LVGL sketches. The following lines will create an LVGL display object called disp with the screen width, screen height, and drawing buffer defined earlier.

// Create a display object
lv_display_t * disp;
// Initialize the TFT display using the TFT_eSPI library
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));

Drawing the GUI

The LVGL library works asynchronously. You must call the function to draw on the display in the setup(). Then, everything works with events and callbacks. The code will always be listening for events in the background. When something happens, it will run the callback function associated with the event. You don’t need to check for any events in the loop().

Throughout most of our examples, the function that will draw to the screen will be called lv_create_main_gui(). Then, inside that function, we’ll add the instructions to build the interface.

// Function to draw the GUI
lv_create_main_gui();

Creating an Arc (Curved Gauge)

To create an arc, we can call the LVGL function lv_arc_create() and pass as argument where we want to display the arc. We want to add it to the current screen (lv_screen_active()).

arc = lv_arc_create(lv_screen_active());

Set the arc size by using the lv_obj_set_size() function. This function is used to set the size of LVGL objects. Pass as arguments: the object you’re referring to, the width and the height.

lv_obj_set_size(arc, 210, 210);

Set the arc rotation (lv_arc_set_rotation()) and maximum and minimum angles for the indicator that will be drawn in the arc (lv_arc_set_bg_angle()).

lv_arc_set_rotation(arc, 135);
lv_arc_set_bg_angles(arc, 0, 270);

Styling the Arc

We can set the color of the indicator arc using the lv_object_set_style_arc_color() that is used to define the color of LVGL arches. Pass as arguments: the LVGL arc, the color, and the part of the arc that you want to set the color, in our case, it’s the indicator (LV_PART_INDICATOR).

 lv_obj_set_style_arc_color(arc, lv_color_hex(0x666666), LV_PART_INDICATOR);

To apply any color, you can use the lv_color_hex() function and pass as argument the color’s hex code.

You can also set the color of the knob as follows:

lv_obj_set_style_bg_color(arc, lv_color_hex(0x333333), LV_PART_KNOB);

Finally, set the alignment of the arc. To do that, you can use the lv_obj_align() function. Pass as arguments, the LVGL object, the alignment and x and y offsets in pixels.

lv_obj_align(arc, LV_ALIGN_CENTER, 0, 10);

You can use the following image as a reference to place your object on the screen.

LVGL Set Object's alignment

In our case, we’re aligning it at the center, so we use LV_ALIGN_CENTER.

If you wanted to place it at the top right corner, you would use LV_ALIGN_TOP_RIGHT.

Displaying Text on the Display

Inside the lv_create_main_gui() function, we also add the instructions to write text on the screen.

A text is a label object. The following lines create an LVGL label object called text_label_temp_value. We use the lv_label_create() function and we pass as argument lv_screen_active() to add the label to the current screen.

lv_obj_t * text_label_temp_value = lv_label_create(lv_screen_active());

After creating the text label, we can set its text by using the lv_label_set_text() function that accepts as arguments the text label we’re referring to and the text we want to add to that label. In our case, we’re setting the text to –.– because when the display first starts, there isn’t a reading from the sensor yet. You can display any other text.

lv_label_set_text(text_label_temp_value, "--.--");

The following lines align the text label.

lv_obj_set_style_text_align(text_label_temp_value, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(text_label_temp_value, LV_ALIGN_CENTER, 0, 10);

Styling the Label Object

To style our text label, we’ll start by creating an object of type lv_style_t called style_temp. This kind of object is used to apply styles to LVGL objects.

static lv_style_t style_temp;

After creating the style, we initialize it using the lv_style_init() function and pass as argument our text label style (style_temp).

lv_style_init(&style_temp);

Then, we can set the font type and size using the lv_style_set_text_font() function. We pass as argument the style object we’re referring to and the font type.

lv_style_set_text_font(&style_temp, &lv_font_montserrat_32);

The font type name already includes the font size. We’re using lv_font_montserrat_32, which refers to Montserrat font in size 32. A list of built-in font types can be found in the link below:

Once we’ve defined all the properties of our style, we can finally apply it to our text_label_temp_value using the lv_obj_add_style() function as follows.

lv_obj_add_style(text_label_temp_value, &style_temp, 0);

 The 0 indicates that we want to add the style to the text_label_temp_value object as a whole and not just some parts of the text_label_temp_value.

Creating an Animation – Updating the Temperature

To update the temperature on the screen both on the text label and arc, we can create an animation that will run a specific function periodically. In this case, we’ll update it every 10 seconds.

First, create an animation called a_temp and associate a callback function to that animation. In this case, the set_temp() callback function.

lv_anim_t a_temp;
lv_anim_init(&a_temp);
lv_anim_set_exec_cb(&a_temp, set_temp);

Set how frequently you want to run the set_temp() function. In our case, we’re setting it to 10 seconds (this function will update the screen with the newest data).

lv_anim_set_duration(&a_temp, 1000000);
lv_anim_set_playback_duration(&a_temp, 1000000);

You can pass a variable to the callback function by using the lv_anim_set_var() function. In our case, we want to access the text_label_temp_value, which is the variable we want to update.

lv_anim_set_var(&a_temp, text_label_temp_value);

Then, you need to add the following lines to make the animation work and run forever as long as the program is running.

lv_anim_set_var(&a_temp, text_label_temp_value);
lv_anim_set_values(&a_temp, 0, 100);
lv_anim_set_repeat_count(&a_temp, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a_temp);

Updating the Temperature Label – The Callback Function

Let’s now take a look at the set_temp() callback function that will run every 10 seconds.

static void set_temp(void * text_label_temp_value, int32_t v) {

Frist, we check if we need to display the temperature in Celsius or Fahrenheit degrees depending on the value of the TEMP_CELSIUS variable.

We get the temperature from the DS18B20 and save it in the ds18b20_temp variable.

float ds18b20_temp = sensors.getTempCByIndex(0);

We then, check in which range the temperature value is to set its color accordingly.

sensors.requestTemperatures();
// Get the latest temperature reading in Celsius or Fahrenheit
#if TEMP_CELSIUS
  float ds18b20_temp = sensors.getTempCByIndex(0);
  if(ds18b20_temp <= 10.0) {
    lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_BLUE), 0);
  }
  else if (ds18b20_temp > 10.0 && ds18b20_temp <= 29.0) {
    lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_GREEN), 0);
  }
  else {
    lv_obj_set_style_text_color((lv_obj_t*) text_label_temp_value, lv_palette_main(LV_PALETTE_RED), 0);
  }

We want to display the degree symbol on the screen. It is an unicode character and we can get it as follows.

const char degree_symbol[] = "\u00B0F";

More information about unicode characters.

We update the value displayed on the arc by calling the lv_arc_set_value() function. Pass as an argument, the arc object, and the value. It accepts a value from 0 to 100%. So, we use the map() function to map the current temperature to that range taking into account the minimum and maximum values we defined at the beginning of the code.

lv_arc_set_value(arc, map(int(ds18b20_temp), TEMP_ARC_MIN, TEMP_ARC_MAX, 0, 100));

The arc will now be updated with the latest temperature reading. Now, we need to update the text label.

We create a string with the current temperature value concatenated with the degree symbol.

String ds18b20_temp_text = String(ds18b20_temp) + degree_symbol;

Finally, set the text_label_temp_value text to that string using the lv_label_set_text() function.

lv_label_set_text((lv_obj_t*) text_label_temp_value, ds18b20_temp_text.c_str());

We also print in the Serial Monitor for debugging purposes.

Serial.print("Temperature: ");
Serial.println(ds18b20_temp_text);

And that’s how you update the arc value and a text label using an LVGL animation.

loop()

In the loop(), you can add any other tasks that you need your ESP32 to do like in any regular Arduino sketch. In our case, we won’t add any tasks to the loop(), but to keep LVGL running and detecting events, you always need to add the following lines to your loop().

void loop() {
  lv_task_handler();  // let the GUI do its work
  lv_tick_inc(5);         // tell LVGL how much time has passed
  delay(5);                 // let this time pass
}

Demonstration

Upload the code to your board. Go to Tools > Board and select ESP32 > ESP32 Dev Module. Then, select the right COM port in Tools > Port. Finally, click the upload button.

Arduino IDE 2 Upload Button

After a few seconds, the temperature will be displayed on the screen as shown in the picture below.

ESP32 TFT Cheap Yellow Display LVGL DS18B20 Temperature Arduino IDE

The color of the text will change depending on the temperature range.

ESP32 TFT Cheap Yellow Display LVGL DS18B20 Temperature High Demonstration

At the same time, the temperature will be displayed on the Serial Monitor.

Display DS18B20 Temperature on ESP32 CYD Display Serial Monitor

Wrapping Up

In this tutorial, you learned to display sensor data on the Cheap Yellow display screen using the LVGL library. You learned how to display text and create a curved gauge.

We hope you found this tutorial useful. We’re preparing more guides about this board, so stay tuned. If you would like to learn more about creating graphical user interfaces using the LVGL library with the ESP32, check out our latest eBook:

Other guides you might like reading:

To learn more about the ESP32, make sure to take a look at our resources:



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

20 thoughts on “ESP32 CYD with LVGL: Display Temperature with DS18B20 Sensor (Text and Arc)”

      • I tried with both libs but it doesn’t rotate. What should the command be and where should it be in the sketch. It may be that I don’t really know what to do. I can only think very slowly and unfortunately remember very little. I respect your work.

        Reply
  1. Hello Rui,

    Do you have example of displaying temperature but from an other esp32 ? I need to display temperature and other value sensor from different esp32.

    Thanks for for work and advice,
    marc,

    Reply
  2. Hi Rui & Sara,
    can You please explain, why you calculate
    #define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))?
    SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8) = 320240/10(16/8) = 15360
    Why do you devide SCREEN_WIDTH * SCREEN_HEIGHT by 10 and multiply it with 2?
    Why do the 76800 pixels only need 15360 bytes? (Did I get something wrong?)
    The draw_buf is of an uint32_t (32 Bytes) so the DRAW_BUF_SIZE / 4 is clear.
    Sincerely Yours, Rudolf

    Reply
  3. The orientation of the display can be changed with lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_0/90/180/270). LVGL will swap the horizontal and vertical resolutions internally according to the set degree. When changing the rotation LV_EVENT_SIZE_CHANGED is sent to the display to allow reconfiguring the hardware. In lack of hardware display rotation support lv_draw_sw_rotate can be used to rotate the buffer in the flush_cb

    Reply
  4. Hi Bert . I am very new to all this and although LVGL is pretty, I find it very difficult and long winded to understand or use.
    Kind regards
    Mark D

    Reply
  5. Good morning, I can use a DHT22 as a sensor as an alternative to the DS18B20 sensor.
    In case what changes do I need to make to the sketch. Thank you

    Reply
  6. Hi Have you tried this code in Fahrenheit degrees?
    My code works fine in C degrees but not in F degrees. When I have 30 C and switch to #define TEMP_CELSIUS 0 it shows 186.8 F, any good solution for this problem.
    Thanks’
    Ronny L

    Reply
    • I had the same problem. It seems that when you change the flag to F it already converts the temperature to F and doesn’t need the conversion formula. Find the line 1.8 * sensors.getTempFByIndex(0) + 32 and change it to sensors.getTempFByIndex(0) without the conversion formula.

      Works for me now.

      Reply
  7. First, the short connection cable assembly, which plugs into CYD P3 and CN1 connectors on Board backside, is not automatically shipped with a CYD. I learned this fact the hard way. I ordered a CYD. It arrived with no cable assembly. I ordered two more CYD’s making sure that a cable was included with same.

    Second, the white lettering on the orange/yellow CYD PCB is hard to read, given the small size lettering on the silkscreen. White lettering does not contrast well printed on an orange/yellow background. The CYD photograph does not offer a clear identification for the CN1 and P3 pin outs. I was finally able to read the pin outs using a fairly powerful magnifying glass.

    Third, I had to spend some tine on my CYD identifying which wire colors on my CYD cable matched up with what CN1 and P3 pins.

    If it is any help to other CYD users, my cable assembly wire colors/pin out connections are:

    CN1 3V3 GPO27 GPO22 Gnd P3 GPO21 GPO22 GPO35 Gnd
    Red Yel Blue Blk Red Yel Blue Blk

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.