Connecting LCD 1602 to Arduino: description, functions, instructions, features, problems and their solution

Each radio amateur, after a number of simple homemade products, comes to the goal of constructing something grand with the use of sensors and buttons. It is much more interesting to display data on a display than on a port monitor. But then the question arises: which display to choose? And in general, how to connect it, what is needed to connect? The answers to these questions will be discussed in this article.

LCD 1602 for connecting to arduino

LCD 1602

Among the many options among the displays, I would like to separately mention the LCD1602 display based on the HD4478 controller. There is this display in two colors: white letters on a blue background, black letters on a yellow background. Connecting the LCD 1602 to the Arduino will also not cause any problems, as there is a built-in library, and you do not need to download anything else. Displays differ not only in price but also in size. Hams are often used 16 x 2, that is, 2 lines of 16 characters. But there is also 20 x 4, where 4 lines of 20 characters. Dimensions and color do not play any role in connecting the LCD 1602 display to Arduno, they are connected the same way. The viewing angle is 35 degrees, the response time of the display is 250 ms. It can work at temperatures from -20 to 70 degrees Celsius. When working, it uses 4 mA per screen and 120 mA for backlight.

LCD 1602 pinout

Where is it used?

This display has its popularity not only among hams, but also among large manufacturers. For example, printers, coffee machines also use LCD1602. This is due to its low price, this display on Chinese sites costs 200-300 rubles. It’s worth buying there, because in our stores the margins for this display are very high.

Connection to Arduino

Connecting the LCD 1602 to the Arduino Nano and Uno is no different. You can work with the display in two modes: 4 bits and 8. When working with 8-bit, the low and high bits are used, and with 4-bit only the low bits are used. It makes no sense to work with 8-bit, as it will add 4 more contacts to connect, which is not advisable, because there will be no higher speed, the limit of display updates is 10 times per second. In general, a lot of wires are used to connect the lcd 1602 to the Arduino, which causes some inconvenience, but there are special shields, but more on that later. The photo shows the connection of the display to the Arduino Uno:

Connecting a display to an arduino

Example code:

#include <LiquidCrystal.h> //    LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (RS, E, DB4, DB5, DB6, DB7) void setup(){ lcd.begin(16, 2); //    lcd.setCursor(0, 0); //     1  lcd.print("Hello, world!"); //   lcd.setCursor(0, 1); //     2  lcd.print("fb.ru"); //   } void loop(){ } 

What does the code do? The first step is connecting the library to work with the display. As mentioned above, this library is already part of the Arduino IDE and you do not need to download or install it additionally. Next, the contacts that are connected to the terminals are determined: RS, E, DB4, DB5, DB6, DB7, respectively. Then the screen dimension is set. Since we are working with a version with 16 characters and 2 lines, we write such values. We place the cursor at the beginning of the first line and display our first Hello World text. Next, put the cursor on the second line and display the name of the site. That's all! The connection of the lcd 1602 to the Arduino Uno was reviewed.

What is I2C and why is it needed?

As mentioned above, connecting a display takes up a lot of contacts. For example, when working with multiple sensors and an LCD display, 1602 pins may not be enough. Often radio amateurs use versions of Uno or Nano, where there are not many contacts. Then people came up with special shields. For example, I2C. It allows you to connect the display in just 4 contacts. This is half the size. The I2C module is sold both separately, where you yourself need to solder, or already soldered to the LCD 1602 display.

I2C LCD Display Module 1602

Connection using I2C module

Connecting the LCD 1602 to an Arduino Nano with I2C takes up little space, only 4 contacts: ground, power, and 2 outputs for data transfer. We connect power and ground to 5V and GND to Arduino, respectively. The remaining two pins: SCL and SDA are connected to any analog pins. In the photo you can see an example of connecting an LCD 1602 to an arduino with an I2C module:

Display Connections Using I2C Module

Program code

If you needed to use only one library to work with a display without a module, then you need two libraries to work with the module. One of them is already part of the Arduino IDE - Wire. Another library, LiquidCrystal I2C, must be downloaded separately and installed. To install the library in Arduino, the contents of the downloaded archive must be downloaded to the Libraries root folder. Example code using I2C:

 #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); //   void setup() { lcd.init(); lcd.backlight();//    lcd.print("FB.ru"); lcd.setCursor(8, 1); lcd.print("LCD 1602"); } void loop() { //        . lcd.setCursor(0, 1); //          lcd.print(millis()/1000); } 

As you can see, the code is almost the same.

How to add your character?

The problem with these displays is that there is no support for Cyrillic characters. For example, you need to load some symbol into the display so that it can reflect it. To do this, the display allows you to create up to 7 of your characters. Present the table:

00010
00001
11001
00001
11001
00001
00010
00000

If 0 - there is nothing there, if 1 - this is a shaded area. In the example above, you can see the creation of the symbol "smiling smiley". For an example program in Arduino, this would look like this:

 #include <Wire.h> #include <LiquidCrystal.h> //    //     byte smile[8] = { B00010, B00001, B11001, B00001, B11001, B00001, B00010, }; LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (RS, E, DB4, DB5, DB6, DB7) void setup(){ lcd.begin(16, 2); //    lcd.createChar(1, smile); //     1 lcd.setCursor(0, 0); //     1  lcd.print("\1"); //   (   1) - "\1" } void loop(){ } 

As you can see, the bit mask was created the same as the table. Once created, it can be displayed as a variable in the display. Remember that only 7 characters can be stored in memory. In principle, this is enough. For example, if you want to show a degree symbol.

Adding Your Characters to LCD 1602

Problems where the display may not work

There are times when the display does not work. For example, it turns on, but does not show characters. Or does not turn on at all. First, see if you connected the contacts correctly. If you used the connection of lcd 1202 to Arduino without I2C, then it is very easy to get confused in the wires, which can cause the display to work incorrectly. You should also make sure that the contrast of the display is increased, since with a minimum contrast it is not even visible whether the LCD 1602 is on or not. If this does not help, then perhaps the problem may lie in the soldering of contacts, this is when using the I2C module. Also a common reason why the display may not work is the incorrect setting of the I2C address. The fact is that there are many manufacturers, and they can set a different address, you need to fix it here:

 LiquidCrystal_I2C lcd(0x27,16,2); 

In brackets you can see two values, 0x27 and 16.2 (16, 2 is the size of the display, and 0x27 is just the same I2C address). Instead of these values, you can try to put 0x37 or 0x3F. Well, another reason is simply a faulty LCD 1602. Given that almost everything for Arduino is made in China, you can’t be 100% sure that the purchased product is not defective.

Pros and Cons of LCD 1602

Consider the pros and cons of the LCD 1602 display.

pros

  • Price. This module can be purchased at a very affordable price in Chinese stores. The price is 200-300 rubles. Sometimes sold even with the I2C module.
  • Easy to connect. Probably no one is now connecting the LCD 1602 without I2C. And with this module, the connection takes only 4 contacts, there will be no "cobwebs" of wires.
  • Programming. Thanks to ready-made libraries, working with this module is easy; all functions are already registered. And if necessary, add your character takes only a couple of minutes.

Minuses

  • During the use by thousands of radio amateurs, no big minuses were revealed, only there are cases of buying a defect, since Chinese display options are mainly used.

In this article, we examined the connection of the LCD 1602 display to Arduino, and also presented examples of programs for working with this display. Indeed, he is one of the best in his category, it’s not just that thousands of ham radioists choose him for their projects!

Source: https://habr.com/ru/post/G9957/


All Articles