i2c lcd module schematic free sample
This article includes everything you need to know about using acharacter I2C LCD with Arduino. I have included a wiring diagram and many example codes to help you get started.
In the second half, I will go into more detail on how to display custom characters and how you can use the other functions of the LiquidCrystal_I2C library.
Once you know how to display text and numbers on the LCD, I suggest you take a look at the articles below. In these tutorials, you will learn how to measure and display sensor data on the LCD.
Each rectangle is made up of a grid of 5×8 pixels. Later in this tutorial, I will show you how you can control the individual pixels to display custom characters on the LCD.
They all use the same HD44780 Hitachi LCD controller, so you can easily swap them. You will only need to change the size specifications in your Arduino code.
The 16×2 and 20×4 datasheets include the dimensions of the LCD and you can find more information about the Hitachi LCD driver in the HD44780 datasheet.
After you have wired up the LCD, you will need to adjust the contrast of the display. On the I2C module, you will find a potentiometer that you can turn with a small screwdriver.
The LiquidCrystal_I2C library works in combination with the Wire.h library which allows you to communicate with I2C devices. This library comes pre-installed with the Arduino IDE.
*When using the latest version of the LiquidCrystal_I2C library it is no longer needed to include the wire.h library in your sketch. The other library imports wire.h automatically.
Note that counting starts at 0 and the first argument specifies the column. So lcd.setCursor(2,1) sets the cursor on the third column and the second row.
Next the string ‘Hello World!’ is printed with lcd.print("Hello World!"). Note that you need to place quotation marks (” “) around the text since we are printing a text string.
The example sketch above shows you the basics of displaying text on the LCD. Now we will take a look at the other functions of the LiquidCrystal_I2C library.
This function turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters over by one space.
I would love to know what projects you plan on building (or have already built) with these LCDs. If you have any questions, suggestions or if you think that things are missing in this tutorial, please leave a comment down below.
If you’ve ever tried to connect an LCD display to an Arduino, you might have noticed that it consumes a lot of pins on the Arduino. Even in 4-bit mode, the Arduino still requires a total of seven connections – which is half of the Arduino’s available digital I/O pins.
The solution is to use an I2C LCD display. It consumes only two I/O pins that are not even part of the set of digital I/O pins and can be shared with other I2C devices as well.
True to their name, these LCDs are ideal for displaying only text/characters. A 16×2 character LCD, for example, has an LED backlight and can display 32 ASCII characters in two rows of 16 characters each.
At the heart of the adapter is an 8-bit I/O expander chip – PCF8574. This chip converts the I2C data from an Arduino into the parallel data required for an LCD display.
If you are using multiple devices on the same I2C bus, you may need to set a different I2C address for the LCD adapter so that it does not conflict with another I2C device.
An important point here is that several companies manufacture the same PCF8574 chip, Texas Instruments and NXP Semiconductors, to name a few. And the I2C address of your LCD depends on the chip manufacturer.
According to the Texas Instruments’ datasheet, the three address selection bits (A0, A1 and A2) are placed at the end of the 7-bit I2C address register.
According to the NXP Semiconductors’ datasheet, the three address selection bits (A0, A1 and A2) are also placed at the end of the 7-bit I2C address register. But the other bits in the address register are different.
So your LCD probably has a default I2C address 0x27Hex or 0x3FHex. However it is recommended that you find out the actual I2C address of the LCD before using it.
Connecting an I2C LCD is much easier than connecting a standard LCD. You only need to connect 4 pins instead of 12. Start by connecting the VCC pin to the 5V output on the Arduino and GND to ground.
Now we are left with the pins which are used for I2C communication. Note that each Arduino board has different I2C pins that must be connected accordingly. On Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also known as A5 (SCL) and A4 (SDA).
After wiring up the LCD you’ll need to adjust the contrast of the display. On the I2C module you will find a potentiometer that you can rotate with a small screwdriver.
Plug in the Arduino’s USB connector to power the LCD. You will see the backlight lit up. Now as you turn the knob on the potentiometer, you will start to see the first row of rectangles. If that happens, Congratulations! Your LCD is working fine.
To drive an I2C LCD you must first install a library called LiquidCrystal_I2C. This library is an enhanced version of the LiquidCrystal library that comes with your Arduino IDE.
Filter your search by typing ‘liquidcrystal‘. There should be some entries. Look for the LiquidCrystal I2C library by Frank de Brabander. Click on that entry, and then select Install.
The I2C address of your LCD depends on the manufacturer, as mentioned earlier. If your LCD has a Texas Instruments’ PCF8574 chip, its default I2C address is 0x27Hex. If your LCD has NXP Semiconductors’ PCF8574 chip, its default I2C address is 0x3FHex.
So your LCD probably has I2C address 0x27Hex or 0x3FHex. However it is recommended that you find out the actual I2C address of the LCD before using it. Luckily there’s an easy way to do this, thanks to the Nick Gammon.
But, before you proceed to upload the sketch, you need to make a small change to make it work for you. You must pass the I2C address of your LCD and the dimensions of the display to the constructor of the LiquidCrystal_I2C class. If you are using a 16×2 character LCD, pass the 16 and 2; If you’re using a 20×4 LCD, pass 20 and 4. You got the point!
First of all an object of LiquidCrystal_I2C class is created. This object takes three parameters LiquidCrystal_I2C(address, columns, rows). This is where you need to enter the address you found earlier, and the dimensions of the display.
In ‘setup’ we call three functions. The first function is init(). It initializes the LCD object. The second function is clear(). This clears the LCD screen and moves the cursor to the top left corner. And third, the backlight() function turns on the LCD backlight.
After that we set the cursor position to the third column of the first row by calling the function lcd.setCursor(2, 0). The cursor position specifies the location where you want the new text to be displayed on the LCD. The upper left corner is assumed to be col=0, row=0.
There are some useful functions you can use with LiquidCrystal_I2C objects. Some of them are listed below:lcd.home() function is used to position the cursor in the upper-left of the LCD without clearing the display.
lcd.scrollDisplayRight() function scrolls the contents of the display one space to the right. If you want the text to scroll continuously, you have to use this function inside a for loop.
lcd.scrollDisplayLeft() function scrolls the contents of the display one space to the left. Similar to above function, use this inside a for loop for continuous scrolling.
If you find the characters on the display dull and boring, you can create your own custom characters (glyphs) and symbols for your LCD. They are extremely useful when you want to display a character that is not part of the standard ASCII character set.
CGROM is used to store all permanent fonts that are displayed using their ASCII codes. For example, if we send 0x41 to the LCD, the letter ‘A’ will be printed on the display.
CGRAM is another memory used to store user defined characters. This RAM is limited to 64 bytes. For a 5×8 pixel based LCD, only 8 user-defined characters can be stored in CGRAM. And for 5×10 pixel based LCD only 4 user-defined characters can be stored.
After the library is included and the LCD object is created, custom character arrays are defined. The array consists of 8 bytes, each byte representing a row of a 5×8 LED matrix. In this sketch, eight custom characters have been created.
In the previous Arduino LCD tutorial, you have noticed that the classic parallel LCD consumes a lot of pins on the Arduino. Even in the 4-bit mode, it requires at least 6 digital I/O pins on the Arduino. So in many projects where you use the classic parallel LCD, you will run out of pins very easily.
The solution to this problem is to use an I2C LCD display. It requires only two digital I/O pins and you can even share those two pins with other I2C devices.
Commonly available LCD displays with I2C LCD adapter are 16×2 and 20×4 character LCD displays. They both have a total of 16 pins including 8 parallel data pins. So if you don’t use an I2C LCD you will need at least 6 digital I/O pins on the Arduino to display something.
If you look closely you will find that the characters of the LCD are built using a grid of 5×8 pixels. Later in this tutorial, you will learn how to turn on and off any individual pixels to make custom characters.
At the center of this adapter, there is an 8-bit I/O expander chip – PCF8574. It takes the I2C data from the MCU (Arduino) and converts it into serial data required for an LCD display. At one side the I2C LCD adapter has four pins that can be connected to Arduino or any microcontroller that supports the I2C communication protocol. On another side, it has 16 pins that are connected to the LCD display.
There are two header pins to control the backlight of the LCD display. One pin supplies a 5v power and another pin is for the backlight LED. These two pins are connected together by default. So the backlight will be always on. You can remove the jumper to turn off the backlight LED or you can use a potentiometer in between these two pins to control the intensity of the backlight LED.
Some I2C LCD adapters come with PCF8574, while others use PCF8574A chips. Each of these chips has its own I2C address. The PCF8574 chip from NXP Semiconductor uses 0x27 while the PCF8574A chip uses 0x3F.
Sometimes you need to change this default I2C address for a project where you use multiple I2C devices on the same I2C bus So that it does not conflict with other I2C devices.
If you go through the datasheet of PCF8574 by NXP, you will find that PCF8574 and PCF8574A use a 7-bit I2C address. The first four-bit is fixed and the last three-bit is hardware selectable.
Connect the LCD’s VCC pin to the Arduino 5v pin and the Ground pin to the Arduino Ground pin. The remaining two pins are SCL and SDA. You need to connect the SCL pin to the Arduino SCL pin and SDA to the Arduino SDA pin.
In this tutorial, I am using the LiquidCrystal-I2C library to control the display. It has many pre-built functions to control an I2C LCD display in a much simpler way.
To install the library first you need to download it from the LiquidCrystal-I2C GitHub repository. Then open your Arduino IDE and navigate to Sketch > Include Library > Add .ZIP Library.
You need to know the I2C address of the LCD before starting the communication. To know the I2C address of your LCD run the below sketch.#include
Printing text on the LCD is very simple. The below sketch will print some text on the display. But before uploading this sketch you need to do some minor changes according to your display size and address.
In the second line, I create a LiquidCrystal_I2C variable. It requires three variables – the I2C address of the LCD and the dimension of the LCD (columns and rows of the display). The I2C address of my display is 0x27 and it has 16 columns and 2 rows. So I will use – LiquidCrystal_I2C lcd(0x27,16,2). If you have a different LCD display change the I2C address and dimension accordingly.
Then you need to define a LiquidCrystal_I2C variable for your LCD. It requires three variables – the I2C address of the LCD and the dimension of the LCD (columns and rows of the display).
clear() – Clears the display and places the cursor at the top left corner. You can use this function to display different text/strings at the same place at a time. The below code shows the use of this function.#include
noDisplay() – Turns off the LCD screen but does not clear data from the LCD memory. The below code shows the use of display() and noDisplay() function.#include
write() – This function is used to write a character to the display. You can see the use of this function in the I2C LCD custom character section below.
scrollDisplayRight() – Moves the display content one step to the right. The below code shows the use of these functions.#include
rightToLeft() – sets the display orientation from right to left. That means the text/strings will flow from right to left. The below code shows the use of this function.#include
CGRAM is used for storing user-defined characters. The Hitachi HD44780 controller has a CGROM of 64 bytes. So for a 5×8 pixel-based LCD, up to 8 user-defined characters can be stored in the CGRAM. And for a 5×10 pixel-based LCD, only 4 user-defined characters can be stored.
There are some online and offline tools available to visually draw the custom character and it will automatically generate the byte code for you. I suggest you use the online LCD Character Creator tools.
Now in the below sketch, I will use that bite code to print the custom character on the LCD. Upload the below code to your Arduino board and see how the display looks like.
Here you can see that I include the LiquidCrystal_I2C library first. Then I create a LiquidCrystal_I2C variable for my LCD using the I2C address and dimension of my LCD. I am using an array smiley[] to store the bit data for the custom character.
In this Arduino LCD I2C tutorial, we will learn how to connect an LCD I2C (Liquid Crystal Display) to the Arduino board. LCDs are very popular and widely used in electronics projects for displaying information. There are many types of LCD. This tutorial takes LCD 16x2 (16 columns and 2 rows) as an example. The other LCDs are similar.
In the previous tutorial, we had learned how to use the normal LCD. However, wiring between Arduino and the normal LCD is complicated. Therefore, LCD I2C has been created to simplify the wiring. Actually, LCD I2C is composed of a normal LCD, an I2C module and a potentiometer.
lcd.print() function supports only ASCII characters. If you want to display a special character or symbol (e.g. heart, angry bird), you need to use the below character generator.
Depending on manufacturers, the I2C address of LCD may be different. Usually, the default I2C address of LCD is 0x27 or 0x3F. Try these values one by one. If you still failed, run the below code to find the I2C address.
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.
In this simple sketch we show you the most useful and important functions from the LiquidCrystal_I2C library. So, let’s take a quick look at how the code works.
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.
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:
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.
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.
The Arduino family of devices is features rich and offers many capabilities. The ability to interface to external devices readily is very enticing, although the Arduino has a limited number of input/output options. Adding an external display would typically require several of the limited I/O pins. Using an I2C interface, only two connections for an LCD character display are possible with stunning professional results. We offer both a 4 x 20 LCD.
The character LCD is ideal for displaying text and numbers and special characters. LCDs incorporate a small add-on circuit (backpack) mounted on the back of the LCD module. The module features a controller chip handling I2C communications and an adjustable potentiometer for changing the intensity of the LED backlight. An I2C LCD advantage is that wiring is straightforward, requiring only two data pins to control the LCD.
A standard LCD requires over ten connections, which can be a problem if your Arduino does not have many GPIO pins available. If you happen to have an LCD without an I2C interface incorporated into the design, these can be easily
The LCD displays each character through a matrix grid of 5×8 pixels. These pixels can display standard text, numbers, or special characters and can also be programmed to display custom characters easily.
Connecting the Arduino UNO to the I2C interface of the LCD requires only four connections. The connections include two for power and two for data. The chart below shows the connections needed.
The I2C LCD interface is compatible across much of the Arduino family. The pin functions remain the same, but the labeling of those pins might be different.
Located on the back of the LCD screen is the I2C interface board, and on the interface is an adjustable potentiometer. This adjustment is made with a small screwdriver. You will adjust the potentiometer until a series of rectangles appear – this will allow you to see your programming results.
The Arduino module and editor do not know how to communicate with the I2C interface on the LCD. The parameter to enable the Arduino to send commands to the LCD are in separately downloaded LiquidCrystal_I2C library.
The LiquidCrystal_I2C is available from GitHub. When visiting the GitHub page, select the Code button and from the drop-down menu, choose Download ZIP option to save the file to a convenient location on your workstation.
Before installing LiquidCrystal_I2C, remove any other libraries that may reside in the Arduino IDE with the same LiquidCrystal_I2C name. Doing this will ensure that only the known good library is in use. LiquidCrystal_I2C works in combination with the preinstalled Wire.h library in the Arduino editor.
To install the LiquidCrystal_I2C library, use the SketchSketch > Include Library > Add .ZIP Library…from the Arduino IDE (see example). Point to the LiquidCrystal_I2C-master.zip which you previously downloaded and the Library will be installed and set up for use.
Several examples and code are included in the Library installation, which can provide some reference and programming examples. You can use these example sketches as a basis for developing your own code for the LCD display module.
The I2c address can be changed by shorting the address solder pads on the I2C module. You will need to know the actual address of the LCD before you can start using it.
Once you have the LCD connected and have determined the I2C address, you can proceed to write code to display on the screen. The code segment below is a complete sketch ready for downloading to your Arduino.
The code assumes the I2C address of the LCD screen is at 0x27 and can be adjusted on the LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,16,2); as required.
This function turns off any characters displayed to the LCD. The text will not be cleared from the LCD memory; rather, it is turned off. The LCD will show the screen again when display() is executed.
Scrolling text if you want to print more than 16 or 20 characters in one line then the scrolling text function is convenient. First, the substring with the maximum of characters per line is printed, moving the start column from right to left on the LCD screen. Then the first character is dropped, and the next character is displayed to the substring. This process repeats until the full string has been displayed on the screen.
The LCD driver backpack has an exciting additional feature allowing you to create custom characters (glyph) for use on the screen. Your custom characters work with both the 16×2 and 20×4 LCD units.
To aid in creating your custom characters, there are a number of useful tools available on Internet. Here is a LCD Custom Character Generator which we have used.
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.
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.
But after using all the GPIO pins for various purposes like SPI, UART, ADC etc., GPIO 22 and GPIO 21 are free (without any important alternative functions). So, in this project, we will be using GPIO 22 as SCL and GPIO 21 as SDA of the I2C interface.
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.
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.
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.
There is an LCD I2C master library included in the Arduino IDE. But there"s a slight problem with the code in it. All the examples in this library assumes the default address of the I2C as 0x27. So first we have to find out what the address of our I2C is. We can do this by using the I2C scanner code. Once we have the I2C address we can replace this value in the example code and start using it.
As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness. When they are connected to a controller, multiple IOs will be occupied of the controller which has no so many outer ports. Also it restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed to solve the problem.
I2C bus is a type of serial bus invented by PHLIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple-host system. The blue potentiometer on the I2C LCD1602 (see the figure below) is used to adjust the backlight for better display. I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.
We will print a simple text on the LCD using Arduino UNO in this example. In this case, you control what is displayed on the Arduino readily. You only need four cables. Power, Ground, I2C data, and I2C clock.
The below line code adds the LCD library to your project. This consists of all the LCD-related functions. Since we are using the I2C version, we have included the standard LCD library made for the I2C version.#include
The following line of the code resets and initializes all the LCD registers and prepares them for project usage. This function will be called only once in thesetup()function.lcd.init();
To turn on the backlight, you can use the below code. You will be able to see the contents of the display without a backlight, too, if it is a green LCD. Backlight, nevertheless, makes the project more beautiful and reading crisper.lcd.backlight();
The first parameter tells the position column-wise (0indicated first place,1indicates the second place, and so on). The second parameter tells the row number. We have only two rows (0and1).lcd.setCursor(1, 0);
This completes a basic introduction to the LCD as well as an example project to start the LCD exploration. In the coming sections, we will see different projects as soon as possible