nodecmu tft lcd display to esp32 factory
I have tried david_prentice"s MCUFRIEND_kbv Library with some hacks to no avail. I tried to hack the library for ESP8266 (updated write_8 and read_8 functions in mcufriend_sheild.h and defined SUPPORT_4532) - using these connections
This person ( (146) ESP8266 and 2.4" 8-bit parallel ST7781 TFT Uno Shield - YouTube) got the same display working w/ nodeMCU (albeit their module is 5V one and has hack on the LDO).
The Bodmer/TFT_eSPI: Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips (github.com) library says 8 bit parallel is not possible w/ ESP8266 because of shortage of GPIOs - but ESP8266 has 16 GPIOs (out of which 4 are SPI). I don"t plan on using touch or SD card functionality anyways. The LCD requires 8(data) + 4 (Control) + 1 = 13 pins, which should fit in the 16 provided by ESP8266 ? Please let me know if I am missing anything.
Anyways - the first question at hand would be - is it possible to run 8 bit parallel tft w/ ESP8266, followed by - which library can do the job if possible.
A 80*160 pixel color display has the particular advantage that it is small: screen diagonal of 0.96 inch. This makes it attractive for use in (literally) small applications, particularly in scale models: railways, homes, cities. Attached to a ESP8266 and ESP32 microcontroller these displays can produce animations or day/night scenes, illuminated shop windows, traffic boards, advertisement panels and so forth. Here we wire a 0.96’ TFT with ST7735S controller to ESP8266 and ESP32 microcontroller boards
Model railway displays can be made more attractive by the addition of ‘live’ decoration: train station arrival/departure boards, information screens, advertisement boards, etcetera. Another type of decoration is animated shop windows. For this genre of application a miniature display can be an interesting option. All these applications have in common that any display used needs to be small, flat, economical and easy to fit, sometimes as retrofit, into the interior of plastic model structures such as model railway homes and Lego buildings. They even may be placed in structures belonging to model Christmas or Easter villages. The market supplies small monochrome displays, e.g. 0.91 inch diameter, 128*32 pixel OLED, the slightly bigger (0.96 inch), 64*128 pixel OLED, and the recently introduced 0.96’ 160*80 TFT. The OLEDS can be found in different versions (white, blue, yellow monochrome color). Very attractive is the 0.96’ TFT because it is capable of displaying 64k colors. Driven by a powerful ESP8266 or ESP32, animations can be run such as miniature billboards and advertisement boards. Static displays that change between day and night such as shop window illumination, are also among the possibilities. In this article we deal with the connectivity between a 0.96’, 160*80 pixel TFT and ESP8266 or ESP32 microcontroller boards. The TFT’s controller is a ST7735S which is perfectly supprted by Bodmer’s TFT_eSPI library.
Whilst the early ESP8266 development work was done with a configuration consisting of a breadboard with the display on it and with connections through jumper wires such assemblies perform very irregular. The 0.96′ SPI TFT responds very critically to imperfect wiring: one slightly loose jumper wire and the display won’t work. A minibench with soldered pin connectivity was therefore constructed for ESP8266 experiments, designed to support a Wemos D1 mini ESP8266 and a TFT display. The Wemos was selected here because its small footprint makes it easy to hide this microcontroller board inside buildings constructed from Lego blocks. Components of the minibench: a double-sided 60×40 mm soldering prototyping board, three 8-pin headers sockets and wires. The design, wiring scheme and the result are shown in figures 2 and 3.
Connected with an ESP32 the TFT display feels at ease. Maybe this is so because Bodmer’s TFT_eSPI library provides a User_Setup example that did not need tweaking. The display responded immediately, fast and reliable. Hardware SPI pins on the ESP32 are used for clock and data: pin 18 is connected to SCL at the display while pin 23 is connected to SDA of the display (see figure 4). The other pins breathe familiarity as well: RST of the display to D4 of the Wemos, DC to D2 and CS to pin D6. The pin on the display marked BLK remains unconnected; I noted comments on several fora that BLK may be connected to the 3.3V pin, to any pin on the ESP32 that supports pulse width modulation, or that the BLK pin can be set HIGH (backlight ON) or LOW (backlight OFF). The display at hand has no voltage regulator which implies that if one wants to use it with an Arduino Uno the precaution must be followed that control signals to the display run via voltage level conversion.
There are two major libraries supporting ST7735 controller-based TFTs: the Adafruit_GFX.h library and Bodmer’s TFT_eSPI.h library. My experience with the Adafruit_GFX.h library is that although the common graphic functions perform well, support of animations via a series of instructions ‘drawBitmap ()’ is relatively slow. Adafruit_GFX seems to be created for 160*128 displays. The library does not support the instruction ‘pushImage ()’. By contrast the TFT_eSPI.h library supports graphics as good as the GFX library while animations perform perfectly and at high speed, both with ‘drawBitmap ()’ and ‘pushImage ()’ functions. We further discuss here the TFT_eSPI library and keep Adafruit_GFX.h in storage for future experiments.
The TFT_eSPI library is different from most libraries, e.g. Adafruit_GFX and U8G2 in the sense that the ‘constructor’ is inside a special file whose name is ‘Setup_xxxx.h’ that resides in the folder ‘User_setups’. These special files are ascii which makes them endlessly tweakable with a common ascii text editor. The specific Setup_xxxx.h is called in another setup file named User_Setup_Select.h that resides in the library’s main directory. Consider Bodmer’s ‘constructor’ systematics as a kind of two-stage rocket. Both stages need to be edited befor launch. The first stage is User_Setup_Select.h and the second stage is Setup_xxxx.h. After the editing has been done successfully the display will indeed perform ‘as a rocket’!
The display was with both platforms tested with graphical tests that are available for everyone in the Arduino IDE through File → Examples, while I also ran several of my own graphical tests as well that I created c-arrays of pictures and displayed these supported by the TFT_eSPI.h library. I recommend here to upload example TFT_Meter_5 available in the TFT_eSPI library ensemble (in the Arduino IDE: File → Examples → TFT_eSPI → 160×128 → TFT_Meter_5). Brilliant!
Below follows the complete listing of ‘Setup_FW_ESP8266_ST7735_TFT_017.h’. For intimi: this is a modified Setup43_ST7735.h. I post here a screen capture because the WordPress editor has problems with the character ‘#’.
One way to demonstrate what one can do with a small display that runs animations is to make it part of a building, let’s say a shop window or something similar. Fortunately the 0.96′ display nicely fits in portrait orientation a front door in the Lego plastic building block system. So I scooped up some material from my children’s Lego assortment and constructed a Swiss chalet that features in the front door the 160*80 TFT display. This display is powered by an ESP32WROOM32. The rooms were fitted with white leds that can be switched on and off. Switching is controlled by an Arduino Nano and is completely separate from all the action happening at the front door. For the purpose of preparing Figure 5 I replaced the animation by a static 160*80 Panda bear image – “there’s a bear at the front door, mama!”.
This tutorial shows how to use the I2C LCD (Liquid Crystal Display) with the ESP32 using Arduino IDE. We’ll show you how to wire the display, install the library and try sample code to write text on the LCD: static text, and scroll long messages. You can also use this guide with the ESP8266.
Additionally, it comes with a built-in potentiometer you can use to adjust the contrast between the background and the characters on the LCD. On a “regular” LCD you need to add a potentiometer to the circuit to adjust the contrast.
Before displaying text on the LCD, you need to find the LCD I2C address. With the LCD properly wired to the ESP32, upload the following I2C Scanner sketch.
After uploading the code, open the Serial Monitor at a baud rate of 115200. Press the ESP32 EN button. The I2C address should be displayed in the Serial Monitor.
Displaying static text on the LCD is very simple. All you have to do is select where you want the characters to be displayed on the screen, and then send the message to the display.
The next two lines set the number of columns and rows of your LCD display. If you’re using a display with another size, you should modify those variables.
Then, you need to set the display address, the number of columns and number of rows. You should use the display address you’ve found in the previous step.
To display a message on the screen, first you need to set the cursor to where you want your message to be written. The following line sets the cursor to the first column, first row.
Scrolling text on the LCD is specially useful when you want to display messages longer than 16 characters. The library comes with built-in functions that allows you to scroll text. However, many people experience problems with those functions because:
The messageToScroll variable is displayed in the second row (1 corresponds to the second row), with a delay time of 250 ms (the GIF image is speed up 1.5x).
In a 16×2 LCD there are 32 blocks where you can display characters. Each block is made out of 5×8 tiny pixels. You can display custom characters by defining the state of each tiny pixel. For that, you can create a byte variable to hold the state of each pixel.
Then, in the setup(), create a custom character using the createChar() function. This function accepts as arguments a location to allocate the char and the char variable as follows:
In summary, in this tutorial we’ve shown you how to use an I2C LCD display with the ESP32/ESP8266 with Arduino IDE: how to display static text, scrolling text and custom characters. This tutorial also works with the Arduino board, you just need to change the pin assignment to use the Arduino I2C pins.
We hope you’ve found this tutorial useful. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.
ESP chips can generate various kinds of timings that needed by common LCDs on the market, like SPI LCD, I80 LCD (a.k.a Intel 8080 parallel LCD), RGB/SRGB LCD, I2C LCD, etc. The esp_lcd component is officially to support those LCDs with a group of universal APIs across chips.
In esp_lcd, an LCD panel is represented by esp_lcd_panel_handle_t, which plays the role of an abstract frame buffer, regardless of the frame memory is allocated inside ESP chip or in external LCD controller. Based on the location of the frame buffer and the hardware connection interface, the LCD panel drivers are mainly grouped into the following categories:
Controller based LCD driver involves multiple steps to get a panel handle, like bus allocation, IO device registration and controller driver install. The frame buffer is located in the controller’s internal GRAM (Graphical RAM). ESP-IDF provides only a limited number of LCD controller drivers out of the box (e.g. ST7789, SSD1306), More Controller Based LCD Drivers are maintained in the Espressif Component Registry
LCD Panel IO Operations - provides a set of APIs to operate the LCD panel, like turning on/off the display, setting the orientation, etc. These operations are common for either controller-based LCD panel driver or RGB LCD panel driver.
esp_lcd_panel_io_spi_config_t::dc_gpio_num: Sets the gpio number for the DC signal line (some LCD calls this RS line). The LCD driver will use this GPIO to switch between sending command and sending data.
esp_lcd_panel_io_spi_config_t::cs_gpio_num: Sets the gpio number for the CS signal line. The LCD driver will use this GPIO to select the LCD chip. If the SPI bus only has one device attached (i.e. this LCD), you can set the gpio number to -1 to occupy the bus exclusively.
esp_lcd_panel_io_spi_config_t::pclk_hz sets the frequency of the pixel clock, in Hz. The value should not exceed the range recommended in the LCD spec.
esp_lcd_panel_io_spi_config_t::spi_mode sets the SPI mode. The LCD driver will use this mode to communicate with the LCD. For the meaning of the SPI mode, please refer to the SPI Master API doc.
esp_lcd_panel_io_spi_config_t::lcd_cmd_bits and esp_lcd_panel_io_spi_config_t::lcd_param_bits set the bit width of the command and parameter that recognized by the LCD controller chip. This is chip specific, you should refer to your LCD spec in advance.
esp_lcd_panel_io_spi_config_t::trans_queue_depth sets the depth of the SPI transaction queue. A bigger value means more transactions can be queued up, but it also consumes more memory.
Install the LCD controller driver. The LCD controller driver is responsible for sending the commands and parameters to the LCD controller chip. In this step, you need to specify the SPI IO device handle that allocated in the last step, and some panel specific configurations:
esp_lcd_panel_dev_config_t::bits_per_pixel sets the bit width of the pixel color data. The LCD driver will use this value to calculate the number of bytes to send to the LCD controller chip.
esp_lcd_panel_io_i2c_config_t::dev_addr sets the I2C device address of the LCD controller chip. The LCD driver will use this address to communicate with the LCD controller chip.
esp_lcd_panel_io_i2c_config_t::lcd_cmd_bits and esp_lcd_panel_io_i2c_config_t::lcd_param_bits set the bit width of the command and parameter that recognized by the LCD controller chip. This is chip specific, you should refer to your LCD spec in advance.
Install the LCD controller driver. The LCD controller driver is responsible for sending the commands and parameters to the LCD controller chip. In this step, you need to specify the I2C IO device handle that allocated in the last step, and some panel specific configurations:
esp_lcd_panel_dev_config_t::bits_per_pixel sets the bit width of the pixel color data. The LCD driver will use this value to calculate the number of bytes to send to the LCD controller chip.
esp_lcd_i80_bus_config_t::data_gpio_nums is the array of the GPIO number of the data bus. The number of GPIOs should be equal to the esp_lcd_i80_bus_config_t::bus_width value.
esp_lcd_panel_io_i80_config_t::pclk_hz sets the pixel clock frequency in Hz. Higher pixel clock frequency will result in higher refresh rate, but may cause flickering if the DMA bandwidth is not sufficient or the LCD controller chip does not support high pixel clock frequency.
esp_lcd_panel_io_i80_config_t::lcd_cmd_bits and esp_lcd_panel_io_i80_config_t::lcd_param_bits set the bit width of the command and parameter that recognized by the LCD controller chip. This is chip specific, you should refer to your LCD spec in advance.
esp_lcd_panel_io_i80_config_t::trans_queue_depth sets the maximum number of transactions that can be queued in the LCD IO device. A bigger value means more transactions can be queued up, but it also consumes more memory.
Install the LCD controller driver. The LCD controller driver is responsible for sending the commands and parameters to the LCD controller chip. In this step, you need to specify the I80 IO device handle that allocated in the last step, and some panel specific configurations:
esp_lcd_panel_dev_config_t::bits_per_pixel sets the bit width of the pixel color data. The LCD driver will use this value to calculate the number of bytes to send to the LCD controller chip.
esp_lcd_panel_dev_config_t::reset_gpio_num sets the GPIO number of the reset pin. If the LCD controller chip does not have a reset pin, you can set this value to -1.
More LCD panel drivers and touch drivers are available in IDF Component Registry. The list of available and planned drivers with links is in this table.
esp_lcd_panel_draw_bitmap() is the most significant function, that will do the magic to draw the user provided color buffer to the LCD screen, where the draw window is also configurable.
Commands sent by this function are short, so they are sent using polling transactions. The function does not return before the command transfer is completed. If any queued transactions sent by esp_lcd_panel_io_tx_color() are still pending when this function is called, this function will wait until they are finished and the queue is empty before sending the command(s).
Commands sent by this function are short, so they are sent using polling transactions. The function does not return before the command transfer is completed. If any queued transactions sent by esp_lcd_panel_io_tx_color() are still pending when this function is called, this function will wait until they are finished and the queue is empty before sending the command(s).
This function will package the command and RGB data into a transaction, and push into a queue. The real transmission is performed in the background (DMA+interrupt). The caller should take care of the lifecycle of the color buffer. Recycling of color buffer should be done in the callback on_color_trans_done().
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
In this project, we will learn how to interface a PCF8574 I2C LCD with ESP32 Development Board. We will see how to configure the I2C Pins in ESP32, download necessary libraries for Arduino IDE, understand how ESP32 I2C LCD interface works and display some data on the 16×2 LCD.
There are many display devices like OLED Display, 128×64 Graphical Display, Nokia 5110 Display etc. But for displaying simple text and number, all we need is a 16×2 or 20×4 Character Display.
The main disadvantage of 16×2 LCD Display is it requires at least 6 GPIO pins of a Microcontroller to function properly. This is not even the 8-bit mode but reduced 4-bit mode (add another 4 GPIO pins for 8-bit mode).
Using that many pins of a microcontroller just for a simple character LCD Display is not desirable especially if you are designing a project with lot of sensors and devices connected to the microcontroller.
As the name suggests, the PCF8574 I2C LCD Module is a PCF8574 IC based module designed to convert regular 16×2 (or 20×4) character LCD Displays in to I2C based devices i.e., instead of using 8-bit or 4-bit parallel interface to send data, we can use I2C bus to send data to the display.
If you notice the board layout and pins of this I2C LCD Module, you can observe that it is a modified version of the regular IO Expander Module, which is also based on PCF8574 IC.
This I2C LCD Module includes the POT to adjust the contrast of the LCD and pull-up resistors for SDA and SCL lines. So, you don’t need any additional connections.
The first thing we need to figure out for ESP32 I2C LCD Interface to work is the I2C pins of ESP32. If you remember, in the ESP32 Pinout Tutorial, I mentioned that the ESP32 Microcontroller has two I2C interfaces and any GPIO pin can be configured to be used as an I2C Pin.
Another important point to note is that the 16×2 LCD runs on standard TTL voltage levels i.e., 4.7V to 5.3V. We cannot apply 3.3V as VCC to the I2C LCD Module even though the PCF8574 IC works at this voltage.
As you can see from the table, the VCC of the I2C LCD Module is connected to VIN pin of the ESP32 Development Board. This is connected to USB Supply when ESP32 is powered through USB. So, we will get around 5V on this pin.
You have to download one library called ‘LiquidCrystal_I2C’ in order to work with I2C LCD Module. If you already installed this library, you can skip this step. If not, then follow along. Open Arduino IDE and open the library manager by selecting Tools -> Manage Libraries. . .
Once the library manager window opens, search for ‘liquidcrystal i2c’ and install the library ‘LiquidCrystal I2C’ by Frank de Brabander. There are other libraries for I2C LCD. You can try them as well.
Close the library manager. Make all the necessary connections as per the circuit diagram and plug in the ESP32 board to the computer. In the Arduino IDE, select the correct board (ESP32 Dev Module) and also the correct COM Port.
Since we are working with I2C interface, the slave address is one of the important things we need to be aware of. Here, the ESP32 Microcontroller is the master and the PCF8574 I2C LCD Module is the slave.
You can refer to the datasheet of PCF8574 IC and calculate the slave address but for now we will go with the easy way i.e., a small program which determines the slave address automatically.
In fact, we used the same code with Arduino and ESP8266 for other I2C related projects. After making all the necessary connections between ESP32 and I2C LCD Module, upload the following code and open the serial monitor of Arduino IDE.
For the next code, let us make a small circuit involving a potentiometer and ADC of the ESP32. I connected a 10 KΩ POT to ADC 2 Channel 3 of ESP32. It is associated with GPIO 15 Pin (D15 on ESP32 DevKit Board).
The following image shows the circuit diagram for connecting 10 KΩ Potentiometer to ESP32 Development Board and displaying the result of ADC on the I2C LCD.
A simple tutorial on interfacing PCF8574 I2C LCD Module with ESP32 Development Board. You learned the importance of I2C LCD Module, I2C pins on ESP32, how the ESP32 I2C LCD Interface works and how to display some text on the LCD.