Every radio amateur, after some simple DIY work, comes to the goal of constructing something grand using sensors and buttons. After all, it is much more interesting to display data on the display than on the 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
Among the many options among displays, I would like to single out 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 not cause any problems either, since there is a built-in library, and you don’t need to download anything extra. Displays differ not only in price, but also in size. Often radio amateurs use 16x 2, i.e. 2 lines of 16 characters. But there is also 20 x 4, where there are 4 lines of 20 characters. Dimensions and color do not play any role in connecting the lcd 1602 display to Arduno, they are connected in the same way. The viewing angle is 35 degrees, the display response time is 250 ms. Can work at temperatures from -20 to 70 degrees Celsius. When working, it uses 4 mA for the screen and 120 mA for the backlight.
Where is it used?
This display has its popularity not only among radio amateurs, but also among large manufacturers. For example, printers, coffee machines also use LCD1602. This is due to its low price, this display costs 200-300 rubles on Chinese sites. It is worth buying there, as in our stores the margins for this display are very high.
Connect to Arduino
Connecting LCD 1602 to Arduino Nano and Uno is no different. You can work with the display in two modes: 4 bits and 8. When working with an 8-bit display, both the lower and higher bits are used, and with a 4-bit one, only the lower ones. There is no particular point in working with 8-bit, since 4 more contacts will be added to connect, which is not advisable, because the speed will not be higher, the display update limit 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:
Code example:
include //Add the required library LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (RS, E, DB4, DB5, DB6, DB7) void setup(){ lcd.begin(16, 2); // Set screen dimension lcd.setCursor(0, 0); // Set the cursor to the beginning of line 1 lcd.print("Hello, world!"); // Display text lcd. setCursor(0, 1); // Set the cursor to the beginning of line 2 lcd.print("fb.ru"); // Output text } void loop(){ }
What does the code do? First of all, the library for working with the display is connected. As mentioned above, this library is already included in the Arduino IDE and you do not need to download and install it additionally. Next, the contacts that are connected to the pins are defined: RS, E, DB4, DB5, DB6, DB7, respectively. Then the screen size is set. Since we are working with a version with 16 characters and 2 lines, we write such values. We set the cursor to the beginning of the first line and display our first text Hello World. Next, put the cursor on the second line and display the name of the site. That's all! Connecting lcd 1602 to Arduino Uno was considered.
What is I2C and why is it needed?
As mentioned above, connecting the display takes a lot of pins. For example, when working with multiple sensors and an LCD display 1602 contacts may simply not be enough. Often, radio amateurs use the Uno or Nano versions, where there are not many contacts. Then people came up with special shields. For example, I2C. It allows you to connect the display with just 4 pins. This is two times less. The I2C module is sold both separately, where you need to solder it yourself, and already soldered toLCD display 1602.
Connection with I2C module
Connecting LCD 1602 to Arduino Nano with I2C takes up little space, only 4 pins: ground, power and 2 data outputs. We connect power and ground to 5V and GND on the Arduino, respectively. The remaining two contacts: SCL and SDA are connected to any analog pins. In the photo you can see an example of connecting lcd 1602 to arduino with I2C module:
Program code
If it was necessary to use only one library to work with a display without a module, then two libraries are needed to work with a module. One of them is already in the Arduino IDE - Wire. Another library, LiquidCrystal I2C, needs to be downloaded separately and installed. To install the library in Arduino, the contents of the downloaded archive must be uploaded to the Libraries root folder. Code example using I2C:
include include LiquidCrystal_I2C lcd(0x27, 16, 2); // Set up the display void setup() { lcd.init(); lcd.backlight();// Turn on the display backlight lcd.print("FB.ru"); lcd.setCursor(8, 1); lcd.print("LCD 1602"); } void loop() { // Set cursor to second line and null character. lcd.setCursor(0, 1); // Print out the number of seconds since the arduino started lcd.print(millis()/1000); }
As you can see, the code is almost the same.
How do I add my own symbol?
The problem with these displays is that there is nosupport for Cyrillic and symbols. For example, you need to load some character 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:
0 | 0 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 1 |
1 | 1 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 1 |
1 | 1 | 0 | 0 | 1 |
0 | 0 | 0 | 0 | 1 |
0 | 0 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 0 |
If 0 - there is nothing there, if 1 - it's a shaded area. In the example above, you can see the creation of the "smiling smiley" character. Using an example program in Arduino, it would look like this:
include include // Include the required library // Smile symbol bitmask 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); // Set screen dimension lcd.createChar(1, smile); // Create character number 1 lcd.setCursor(0, 0); // Set the cursor to the beginning of line 1 lcd.print("\1"); // Display the smiley (character number 1) - "\1" } void loop(){ }
As you can see, was createdthe bitmask is the same as the table. Once created, it can be output as a variable to the display. Remember that only 7 characters can be stored in memory. In principle, this is enough. For example, if you want to show the degree symbol.
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 it doesn't turn on at all. First, see if you connected the contacts correctly. If you used to connect lcd 1202 to Arduino without I2C, then it is very easy to get tangled in the wires, which can cause the display to work incorrectly. You should also make sure that the display contrast is increased, since at 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 the 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 correct it here:
LiquidCrystal_I2C lcd(0x27, 16, 2);
In brackets you can see two values, 0x27 and 16, 2 (16, 2 is the display size, and 0x27 is just the I2C address). Instead of these values, you can try to put 0x37 or 0x3F. Well, another reason is simply a faulty LCD 1602. Considering that almost everything for Arduino is made in China, you cannot be 100% sure that the purchasedthe product is not defective.
LCD 1602 pros and cons
Let's look at the pros and cons of the LCD 1602.
Pros
- Price. This module can be purchased at a very affordable price in Chinese stores. The price is 200-300 rubles. Sometimes even sold with an I2C module.
- Easy to connect. Probably no one connects an LCD 1602 without I2C these days. And with this module, the connection takes only 4 pins, there will be no "webs" of wires.
- Programming. Thanks to ready-made libraries, working with this module is easy, all functions are already registered. And if you need to add your character, it takes only a couple of minutes.
Cons
During the time of use by thousands of radio amateurs, no big minuses have been identified, only there are cases of buying a marriage, since Chinese display options are mainly used
This article discussed how to connect the LCD 1602 display to the Arduino, and also presented sample programs for working with this display. It really is one of the best in its category, it is not just that thousands of radio amateurs choose it for their projects!