the Internet Windows Android

Programming LCD indicators I2C for Arduino. Connecting LCD LCD LCM1602 with I2C to Arduino

Perhaps one of the most popular screens in the market. Signed on the popular HD44780U controller. From the name of the model it follows that the screen consists of two rows of 16 characters. Support for Russian language in this specific model not.

SH2S data bus allows two wires to connect up to 127 devices, and simultaneously. This I2C is implemented at the PCF8574T chip.

Connection diagram:

Blue thing - variable resistance, allows you to adjust the contrast of the screen.

The jumper on the left - is responsible for the screen backlight.

The block of 4 contacts is connected to Arduino so:

GND - GND.
VCC - 5V.
SDA - A4 (if Arduino Mega, then to D20)
SCL - A5 (if Arduino Mega, then to D21)

Library

Sketch

The display may have another IIC address, instead of 0x27 may be 0x3F. To accurately determine the address you can use the I2C devices scanner.

#Include. #Include. // Set the LCD address 0x27, 16 characters, 2 lines LiquidCrystal_i2c LCD (0x27, 16, 2); void setup () (lcd.init (); // Initialize the screen // Turn on the backlight lcd.backlight (); // Install the position starting with which the text is displayed. LCD.Setcursor (2, 0); // withdraw the string 1 lcd.print ("Hello, WORLD!"); // Similarly display the second string LCD.Setcursor (1, 1); lcd.print ("www.site"); ) void loop () ()

LCD I2C Module allows you to connect the character display to the Arduino board of all over two signal wires.

Components used (buy in China):

. Managing fee

. Connecting wires

Basic specifications:

Display: Symbol 16x02 or 20x04
. Illumination: blue with white symbols
. Contrast: configured potentiometer
. Supply voltage: 5V
. Interface: I2C.
. I2C Address: 0x27
. Sizes: 82mm x 35mm x 18mm

Connect to Arduino.

The module is equipped with a four-pin 2.54mm standard connector

SCL.: Serial Clock Serial Clock

SDA: Sequential data line (Serial Data)

VCC.: "+" power

GND.: "-" Power

Conclusions responsible for the I2C interface on arduino boards On the basis of various controllers differ

To work with this module, you must install the library LiquidCrystal_i2C1602V1

Download, unpack and throw in the Libraries folder in the Arduino folder. In case, at the time of adding the library, Arduino IDE has been open, rebooting the environment.

Go directly to the sketch. IN this example Withdraw the standard "Hello, World!" And for the address of our community.

sample program code:

#Include. #Include. LiquidCrystal_i2c LCD (0x27,16,2); / * Set the address and dimension of the display. When using the LCD I2C module with a display of 20x04, nothing in the code cannot be changed, it should only set the correct dimension * / Void. setup. () (lcd.init (); // Initialization LCD. lcd.backlight (); // Turn on the backlight // The cursor is at the beginning of the 1st line lcd.print ("Hello, WORLD!"); // Display text LCD.Setcursor (0, 1); // Install the cursor at the beginning of 2 lines lcd.print ("Site"); // Tell text) void loop. () { }

Creating your own characters

With the conclusion of the text figured out, the letters of the English alphabet are sewn into the memory of the controller inside the display and there are no problems with them. But what to do if the desired symbol There is no controller in the memory?

Not trouble, the desired symbol can be done manually. This method In part, the restriction of 7 characters will help solve the output problem.

The cell, in the displays under consideration, has a resolution of 5x8 points. Everything that the task of creating a symbol is reduced to write a bit mask and arrange a single one in it in places where there should be a point and noliki where there is no.

In the example above, draw a smiley.

sample program code:

// Tested on Arduino IDE 1.0.5 // add the necessary libraries #Include. #Include. // Bit Mask Symbol Smile BYTE SMILE \u003d (B00010, B00001, B11001, B00001, B11001, B00001, B00010,); LiquidCrystal_i2c LCD (0x27,20.4); // Set the address and dimension of the display. Void. setup. () (lcd.init (); // Initialization LCD. lcd.backlight (); // Turn on the backlight // Create a character at number 0 LCD.CREATECHAR (1, SMILE); lcd.setcursor (0, 0); // Set the cursor to top 1 line lcd.print ("\\ 1"); // Display emoticons (symbol at number 1) - "\\ 1" ) Void loop. () { }

Program for easy creation of characters

In the comments, the community participant threw the link to the symbol generator

I got here from good shop Chip resistor next device for studying and applications in useful devices. This device turned out to be sharpened to manage the LCD display running the HD44780 controller, in 4-bit mode. For this purpose, a microcircuit is installed on the board, which is the I2C bus converter to a parallel 8 bit port.

The fee is divorced in such a way that it can be immediately crushed with the LCD display. The input serves power and I2C lines. The board immediately installed pull-up resistors on the SCL and SDA lines, the potentiometer for adjusting the contrast and the power of the display itself.

Jumper on the right turns on / disconnects the backlight. Next, armed with a tester was drawn up the following plate. After studying the module, it was revealed. P3 Manages backlight. If the jumper is set, then 1 turns on the backlight, and 0 turns off. When the jumper is removed, the backlight is always turned off. Next, it was decided to supplement the AXLIB library to work with the I2C bus (software implementation) and functions for managing the PCF8574 microcircuit. In a nutshell, how the module works. In order to display parallel byte, for this you need to send a microcircuit address to the I2C bus (it is equal to 0x4e. You can also change the address by switching jumpers on the board and changing the value of three younger address discharges), then after receiving ACK, the data byte is sent. After the chip responds with ACK, the byte appears on the parallel port of the chip. To control the LCD display, I took the functions from the AxLib library and redid them a little to work with the I2C bus. #Include. #Include. #Include. #Include. #Define Add 0x4e // Microcircuit address / * LCD Microcircuit RS P0 RW P1 EN P2 D4 P4 D5 P5 D6 P6 D7 P7 on the foot of P3 connect the backlight. 1 incl, 0 off. * / // Data output com | \u003d 0x04; // e a unit PCF8574_BYTE_OUT (COM, Add); // Data output COM & \u003d 0XFB; // e in zero PCF8574_BYTE_OUT (COM, Add); // Data output ) Void Init (Void) (_delay_ms (30); COM (0x30); _delay_us (40); COM (0x30); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x30); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x20); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x20); // Set parameters COM (0x80); // Set parameters COM (0x00); // Turn off the display COM (0x80); // Turn off the display COM (0x00); // Clean the display COM (0x10); // Clean the display COM (0x00); COM (0x60); // Install the data entry mode COM (0x00); COM (0xc0); // Turn on the display with the selected cursor ) Void Char_out (BYTE DATA) (BYTE DATA_H \u003d ((DATA & 0XF0) + 0X09); byte data_l \u003d ((data // Transferring older 4 bits Data_H | \u003d 0x04; PCF8574_BYTE_OUT (Data_H, Add); // Transferring senior 4 bits // Transferring senior 4 bits // Transfer of Junior 4 Bit // Transfer of Junior 4 Bit // Transfer of Junior 4 Bit ) Void str_out ((* STR)! \u003d "\\ 0") (char_out (* STR); STR ++;)) Int Main (Void) (init (); str_out ("Epґbet MґP!" ); While (1) ()) Actually what happens here. First connect libraries for I2C and for PCF8574. I wrote about I2c already, so it will be cut once again, but I will tell you in PCF8574.H. The library includes only three functions.
Byte PCF8574_TEST (byte Add) (byte Ask \u003d ACK; Add & \u003d 0xfe; i2c_start (); Ask \u003d i2c_send_byte (add); i2c_stop (); Return ASK;) The first function was written to check the availability of a device on the bus. In principle, it can be used to search for any device located on the tire. The function takes the address of the desired device and if it responds, it returns zero. If there is no device with this address on the bus, then will return the unit.
BYTE PCF8574_BYTE_OUT (BYTE ASK \u003d ACK; Add & \u003d 0xfe; i2c_start (); ask \u003d i2c_send_byte (add); if (! ASK) Ask \u003d I2C_SEND_BYTE (DATA); i2c_stop (); Return ASK; ) This feature is already sharpened clean under this chip. As an argument, bytes are transmitted to transfer to the tire and the address of the microcircuit. The function will first ask for a chip at the address and then send bytes. If the chip received byte and answered ACK, the function will finish working with the microcircuit and return zero as a successful package of bytes. A chip at this time will display this byte in your parallel port. Otherwise, we get NACK and refund units, the transfer failed.
Byte pcf8574_str_out (byte * data, byte col, byte add) (byte ask \u003d ack; add & \u003d 0xfe; i2c_start (); ask \u003d i2c_send_byte (add); for (byte i \u003d 0; i This feature is created for the experiment. Accepts a pointer to an array of single-byte data, the number of these bytes and the microcircuit address. Actually an attempt to transfer all the data by one session, and not one byte for the session. The function works, but so for the LCD display and did not fit. And now let's go back to the main program. After connecting the libraries, we prescribe the address of the chip. Next, create three functions by analogy with LCD.H. The difference is only in the principle of data transfer.
Void COM (byte COM) (com | \u003d 0x08; // P3 per unit, in order not to burn illumination PCF8574_BYTE_OUT (COM, Add); // Data output com | \u003d 0x04; // e a unit PCF8574_BYTE_OUT (COM, Add); // Data output COM & \u003d 0XFB; // e in zero PCF8574_BYTE_OUT (COM, Add); // Data output } This feature transmits only the display commands. From here there was a first line with a logical fold of the command from 0x08. This bjaka is needed due to the fact that we pass bytes not directly to the port of the LCD display, but through our repeater. That is, if we ran a byte, and then we need to withdraw only one bit, then you will give a deign to the previous byte and send it to the port again. Here is such a confusion. Addition from 0x08 is necessary for the permanent retention of the unit on the third discharge. Remember about the backlight? That is this addition and turns on the backlight. After you call the bus transfer function in the bus. It is written above. Then we pass byte by bus in the microcircuit. Next, it should be placed in a unit E than actually a logical addition of bytes with 0x04 is engaged. After zeroing E. In this way, you can send any command to the display only by passing the command itself as an argument. Void Init (Void) (_delay_ms (30); // pause after power supply COM (0x30); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x30); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x30); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x20); // transition to 4 bit mode _delay_us (40); // Delay to execute the command COM (0x20); // Set parameters COM (0x80); // Set parameters COM (0x00); // Turn off the display COM (0x80); // Turn off the display COM (0x00); // Clean the display COM (0x10); // Clean the display COM (0x00); // Install the data entry mode COM (0x60); // Install the data entry mode COM (0x00); // Turn on the display with the selected cursor COM (0xc0); // Turn on the display with the selected cursor } This feature is only engaged in the initialization of the display. Sequence of commands are taken from a datashet on the LCD display. void char_out (byte data) (BYTE Data_H \u003d ((Data & 0xF0) + 0x09); byte data_l \u003d ((data // Transferring senior 4 bits data_h | \u003d 0x04; pcf8574_byte_out (data_h, add); // Transferring senior 4 bits Data_H & \u003d 0xF9; PCF8574_BYTE_OUT (Data_H, Add); // Transferring senior 4 bits PCF8574_BYTE_OUT (Data_L, Add); // Transfer of Junior 4 Bit data_l | \u003d 0x04; PCF8574_BYTE_OUT (Data_L, Add); // Transfer of Junior 4 Bit Data_L & \u003d 0xF9; PCF8574_BYTE_OUT (Data_L, Add); // Transfer of Junior 4 Bit } This feature transmits data LCD data. It is performed in the same way as the commands except that the transfer of the byte first comes first by the senior semi-core, and then the younger. And the rest is the same. Void Str_out (BYTE * STR) (While ((* Str)! \u003d "\\ 0") (char_out (* STR); STR ++;)) Well, this feature is clean to transmit the display string. Actually, it has nothing to do with our topic.

Project for ATmelstudio 6.2

Literate 01.08.15 17:11

The comma is skipped. Right: "Hi, peace!" And this device is sharpened not only for HD44780. Tightening resistors are put on the part of the wizard. According to the specification, the data record to the LCD controller goes on the decline of E. From here the first function is simplified: Void COM (byte COM) (COM | \u003d 0x08; // Illumination PCF8574_BYTE_OUT (COM | 0x04, add); // Data output PCF8574_BYTE_OUT (COM , Add); // e in zero) and the rest are also significantly less than less. For example, Void Char_out (Byte Data) will be only two calls, and even more so without additional variables. LCD initialization is performed with violations of the timing specification.

Alexey 02.08.15 19:11

Due to the lack of a comma, the display will not suffer. This device is just sharpened precisely under displays with such or similar controller. But it is the microcircuit that is a simple port expander. About E I agree. Additional variables are needed. If you transmit the function argument with some kind of actions with logic, glitches may occur. Already came across such. Initialization is performed without trimming violations. The documentation says that a pause of 40 μs is put between the teams. Due to the fact that the transmission goes along the I2C bus, and that in turn software and slow, then periods are performed with interest. If you still do not too lazy, then write your own option and send me. I will publish it. In the end, this site is intended for an amateur audience and everyone who wants to express their opinion and the vision of the Life of MK.

Alexey 06.08.15 09:14.

Tyamenga has been added when initializing the display by remarking the respected "competent"

Dmitry 06/14/16 21:57

Hello Alexey. You can add a library to work with PCF8574 into the code generator.

Alexey 14.06.16 22:32

I'll think about it.))

ruslan 12/21/16 19:54
Alexey 21.12.16 21:53

Oh yeah. Especially the code on the Asma. Arduries will appreciate the full)))

Pi.Sy.
Even if you do not lick on AFM, then there the prog is written under the PIC controller. For AVRs, this is "very" useful information? Especially beginner))) I have nothing against PIC, but even AFM in PIC and AVR is different. And about the details of the work of the LCD display, then you can look))) True, I still wrote it under CVAVR but all the teams are dismantled and decomposed on the shelves. But in any case, decide where it is clearer it says))) The author writes, the reader chooses.

Gek 04.01.17 12:52

"I2C Microcircuit Address (by default it is 0x4e"

Senior 4 bit addresses are fixed,
PCF8574 prefix is \u200b\u200b0100, and PCF8574a - 0111
Younger 3 bits depend on the state of the inputs of the A2-A0 chip. By default, all 3 jumpers are open, respectively, the microcircuit address takes the value 0111111.
// A2 A1 A0 PCF8574 PCF8574A
// 1 1 1 0x20 0x38
// 1 1 0 0x21 0x39
// 1 0 1 0x22 0x3a
// 1 0 0 0x23 0x3b
// 0 1 1 0x24 0x3c
// 0 1 0 0x25 0x3d
// 0 0 1 0x26 0x3e
// 0 0 0 0x27 0x3f

Alexey 04.01.17 14:27

Something you confused.
Extract from the documentation for the microcircuit

0B01001110 This is 0x4e
So everything is right here. And if you need to change the address, then just need to change it in define.

Yuri 14.12.17 21:26

Good day! And you can still code the LCDGOTOXY and LCDClear function to work with the adapter on PCF8574.

Alexander 20.05.18 18:14

Good day! How do you withdraw Russian text.

Alexey 20.05.18 23:04

This is the domestic display from MELT. He is in memory of Cyrillic.

Alexander 21.05.18 04:55

Good day! I write as you have in the project for ATMELStudio 6.2 "YPґBET MґP!" That displays normal
And if you write "Hello the world!" Displays nonsense all. I have two
Options of displays from one Cyrillic sewn. Second Chinese.

Alexey 21.05.18 09:22

I would have written the test program to start a test program. Switch through all memory with displaying characters and their addresses. And then to exit the problem. Most likely the character table does not coincide with the ASCII table.

Andrey 03.09.18 08:32

Good afternoon!

And you can't throw a scheme for Proteus?

Andrey 03.09.18 10:22

Or nobody checked in Proteuse?

Andrei 03.09.18 10:56.

Used Main_init

Paul 30.05.19 23:35

Curious thing, display address 0x4e, and if the same display is connected to Arduux then address 0x27

Paul 31.05.19 11:04.

Thank you so much for your work! I rummaged the entire Internet, none of the above examples except for yours earned. The only one in the project archive in the display initialization function is not spelled out the delay _delay_, and it does not work accordingly

Alexey 01.06.19 09:52

Well, this is more demonstration project. According to a good, the AxLib library is to rewrite, but taking into account the fact that STM32 and STM8 moves seven-mile steps, no sense in AVR is no longer at all.

Paul 05.06.19 12:57

STM has no DIP enclosures, it is more difficult to make printed circuit boards. For my projects, AVR features enough with a margin, on one ATMEGA 8 you can fit very much

Alexey 05.06.19 15:20

Yes, but how much is ATmega8 and STM8S003))))

Dmitry 07.06.19 00:41.

Hello, Alexey.
Tell me, please, how to read from the PCF8574 state of the port?
I want to make an external block, 8 GPIO via the I2C bus - it sam.

Dmitry 07.06.19 17:56.

I am answering myself
The function returns bytes - the state of the microcircuit ports
UINT8_T PCF8574_BYTE_RCV (UINT8_T ADDR)
{
UINT8_T ASK \u003d ACK;
ADDR | \u003d 0B01; // Read.
UINT8_T DATA \u003d 0;
i2c_start ();
ASK \u003d I2C_SEND_BYTE (ADDR);
if (! ASK) Data \u003d I2C_READ_BYTE (NACK);
i2c_stop ();

RETURN DATA;
}

Paul 07.06.19 20:37

How much costs, 150 rubles, at the price of the relyushka in general), and how do you divor the fees under STM? LUT unreliable, CNC Freser is not sure that it will take (not tried)

  • The FC-113 module is made on the basis of the PCF8574T chip, which is an 8-bit shift register - the "expander" of the outputs for the serial tire of the I2C. In the figure of the microcircuit is designated DD1.
  • R1 is a rapid resistor to adjust the contrast of the LCD display.
  • J1 jumper is used to turn on the display backlight.
  • Conclusions 1 ... 16 are used to connect the module to the outputs of the LCD display.
  • Contact platforms A1 ... A3 are needed to change the I2C address of the device. Seating the corresponding jumpers, you can change the address of the device. The table shows the conformity of addresses and jumpers: "0" corresponds to the rupture of the chain, "1" - the adjustable jumper. By default, all 3 jumpers open and device address 0x27.

2 Arduino LCD Display Connection Schemeaccording to I2C.

Connecting a module to Arduino is carried out standard for the I2C bus: the sda \u200b\u200boutput of the module is connected to the analog port A4, the SCL output to the analog port of A5 Arduino. The module is powered by voltage +5 V from Arduino. The module itself is connected by the conclusions 1 ... 16 with the corresponding conclusions of 1 ... 16 on the LCD display.


3 Library for workaccording to I2C.

Now you need a library to work with the LCD via the I2C interface. You can use, for example, this (link in the "Download Sample Code and Library" row).

Downloaded Archive LiquidCrystal_i2cv1-1.rar. Unzip in the folder \\ Libraries \\which is located in the Arduino IDE directory.

The library supports a set of standard functions for LCD screens:

FunctionPurpose
LiquidCrystal () creates a variable of type LiquidCrystal and accepts the display settings (pin numbers);
begin () initialization of the LCD display, setting parameters (number of rows and symbols);
clear () cleaning the screen and return the cursor to the initial position;
home () return the cursor to the initial position;
setcursor () installation of the cursor to the specified position;
write () displays a symbol on the LCD screen;
print () displays the text on the LCD screen;
cursor () shows the cursor, i.e. Underclination at the next symbol seat;
nocursor () hides the cursor;
blink () flashing cursor;
noblink () cancel blinking;
nodisplay () turn off the display while saving all the displayed information;
dISPLAY () turn on the display while saving all the displayed information;
scrollDisplayLeft () scrolling the contents of the display on the first position to the left;
scrollDisplayRight () scrolling the contents of the display on 1 position to the right;
autoScroll () inclusion of auto-contracting;
noautoscroll () turning off the auto lober;
lefttoright () specifies the direction of the text from left to right;
rightToleft () the direction of the text on the right to the left;
createChar () creates a custom symbol for the LCD screen.

4 Sketch for text outputon LCD screen via I2C bus

Let's open the sample: File Samples LiquidCrystal_i2c CustomChars And he alterate him a little. We will withdraw a message at the end of which the flashing symbol will be. In the comments to the code, all sketch nuances are commented.

#Include. // Connect the Wire #InClude library // We connect the library of the LCD #Define PrintByte (Args) Write (Args); // uint8_t heart \u003d (0x0.0xa, 0x1f, 0x1f, 0xe, 0x4.0x0); // Bit mask Symbol "Heart" LiquidCrystal_i2c LCD (0x27, 16, 2); // Set the address 0x27 for LCD display 16x2 void setup () ( lcd.init (); // Initialization of LCD display LCD.Backlight (); // Turn on the LCD.CREATECHAR display backlight (3, Heart); // Create the Heart Symbol in 3 LCD.HOME () memory cell; // Put the cursor to the upper left corner, to the position (0.0) LCD.! "); // Print the LCD.Setcursor text string (0, 1); // Transfer a cursor to a string 2, a symbol 1 lcd.print ( "i"); // Print a message on a line 2 LCD.PrintByte (3); // Print the symbol "Heart", located in the 3rd cell LCD.Print ("Arduino"); } void loop () ( // Blinking the last LCD.Setcursor symbol (13, 1); // Transfer cursor to string 2, symbol 1 lcd.print ("\\ t"); Delay (500); LCD.Setcursor (13, 1); // Transfer cursor to string 2, symbol 1 lcd.print (""); Delay (500); }

By the way, the characters recorded by the team lcd.createchar ();, remain in the display of the display even after power off, because Recorded in the 1602 MFU.

5 Creating your own charactersfor LCD Display

Little more details, consider the issue of creating your own characters for LCD screens. Each symbol on the screen consists of 35 points: 5 in width and 7 in height (+1 backup string for undercuting). In line 6 of the given Sketch, we set an array of 7 numbers: (0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0). We transform 16-riche numbers in binary: {00000, 01010, 11111, 11111, 01110, 00100, 00000} . These numbers are nothing but a bit mask for each of the 7 lines of the symbol, where "0" denote a light point, and "1" - dark. For example, a heart symbol specified in the form of a bit mask will look on the screen as shown in the figure.

6 Office LCD screenon the I2C bus

Drive Sketch in Arduino. On the screen will appear the inscription with the flashing cursor at the end.


7 What is "for"tire i2c.

As a bonus, consider a temporary diagram of the output of Latin characters "A", "B" and "C" on the LCD display. These characters are available in the display ROM and are displayed simply by the transmission of their address. The diagram is removed from the conclusions RS, RW, E, D4, D5, D6 and D7 display, i.e. Already after the FC-113 converter "I2C parallel bus". We can say that we plunge a little "deeper" in the "iron".


Temporary diagram of the output of Latin characters "A", "B" and "C" on the LCD display 1602

The diagram shows that the characters that are in the DVLD ROM (see page 9.11 datasheet, the reference below) is transmitted by two ghee, the first of which defines the table of the table column, and the second is the line number. At the same time, the data "snatch" on the front front E. (Enable), and line RS. (Register SELECT, register selection) is in a state of logical unit, which means data transfer. The low state status of the RS line means the transmission of instructions that we see before the transfer of each symbol. In this case, the Code of the carriage return instruction is transmitted to the position (0, 0) LCD display, as you can also find out by studying the technical description of the display.

And one more example. On this time diagram shows the output of the "Heart" symbol on the LCD display.


Again, the first two impulses Enable Compliant instructions Home () (0000 0010 2) - Return of the carriage to the position (0; 0), and the second two - the output on the LCD display stored in the memory cell 3 10 (0000 0011 2) the "Heart" symbol (instruction lCD.CREATECHAR (3, HEART); Sketch).

LCD display - Frequent guest in Arduino projects. But in sophisticated schemes, we may have a problem lack of Arduino ports due to the need to connect a screen that has very many contacts. Exit in this situation can be I2C / IIC Adapter that connects almost standard for Arduino Screen 1602 to UNO, Nano or Mega payments just with 4 pins. In this article we will see how you can connect the LCD screen with the I2C interface, which you can use the libraries, write a short sketch example and examine typical errors.

Liquid Crystal Display (Liquid Crystal Display) LCD 1602. It is a good choice to display characters lines in various projects. It is inexpensive, there are various modifications with different backlight colors, you can easily download ready-made libraries for sketches Arduino. But the most important disadvantage of this screen is the fact that the display has 16 digital conclusions, of which the minimum of 6 are mandatory. Therefore, the use of this LCD screen without I2C adds serious restrictions for Arduino Uno or Nano boards. If the contacts are missing, then you will have to buy the Arduino Mega fee or save contacts, including by connecting the display via I2C.

Brief description Pins LCD 1602

Let's look at the findings of LCD1602 more close:

Each of the conclusions has its purpose:

  1. GND land;
  2. Nutrition 5 V;
  3. Installation of the contrast of the monitor;
  4. Command, data;
  5. Recording and reading data;
  6. Enable;

7-14. Data lines;

  1. Plus backlighting;
  2. Minus backlight.

Technical Display Specifications:

  • Symbol display type, it is possible to load characters;
  • Neon lights;
  • HD44780 controller;
  • 5V supply voltage;
  • Format 16x2 characters;
  • Operating temperature range from -20cd to + 70c, storage temperature range from -30c to +80 s;
  • The viewing angle is 180 degrees.

LCD connection circuit to Arduino board without i2c

The standard monitor connection diagram directly to the Arduino microcontroller without i2c is as follows.

Due to the large number of connected contacts, there may not be enough space to attach the desired elements. The use of I2C reduces the number of wires to 4, and the occupied pins up to 2.

Where to buy LCD screens and shields for Arduino

LCD screen 1602 (and option 2004) is quite popular, so you can easily find it in both domestic online stores and foreign sites. Here are some links to the most accessible options:

LCD1602 + I2C module with blue screen, compatible with Arduino Simple LCD1602 display (green backlight) cheaper than 80 rubles Large screen LCD2004 with I2C HD44780 for Arduino (blue and green backlight)
Display 1602 with IIC adapter and blue backlight Another option LCD1602 with an I2C I2C module PORT IIC / I2C / TWI / SPI adapter module for Screen 1602, compatible with Arduino
Display with RGB backlight! LCD 16 × 2 + Keypad + Buzzer Shield for Arduino Shield for Arduino with buttons and screen LCD1602 LCD 1602 LCD display for 3D printer (SMART Controller for Ramps 1.4, Text LCD 20 × 4), SD and MicroSD Cardrider Module

Description of the I2C protocol

Before discussing the display of the Arduino display via the I2C adapter, let's talk about the I2C protocol itself.

I2C / IIC.(Inter-Integrated Circuit) is a protocol originally created to communicate integrated circuits inside the electronic device. Development belongs to Philips. The i2C protocol is based on the use of an 8-bit bus that is needed to communicate blocks in control electronics, and the addressing system, which can be communicated by the same wires with multiple devices. We simply pass the data to one one, then another device, adding the identifier of the desired item to the data packets.

The simplest I2C scheme may contain one drive device (most often this is an Arduino microcontroller) and several slaves (for example, LCD display). Each device has an address in the range from 7 to 127. Two devices with the same address in one scheme should not be.

Arduino supports I2C at a hardware level. You can use A4 and A5 pins to connect devices for this protocol.

In I2C, you can select several advantages:

  • For operation, only 2 lines are required - SDA (data line) and SCL (synchronization line).
  • Connecting a large number of drive devices.
  • Reducing the development time.
  • To control the entire set of devices, only one microcontroller is required.
  • The possible number of microcircuits connected to one bus is limited only to the maximum capacity.
  • High degree of data safety due to a special filter of the overwhelming burst embedded in the circuit.
  • A simple procedure for diagnosing emerging failures, fast failover.
  • The tire is already integrated into the Arduino itself, so you do not need to develop an additional bus interface.

Disadvantages:

  • There is a capacitive limitation on the line - 400 PF.
  • Difficult programming of the I2C controller if there are several different devices on the bus.
  • With a large number of devices, the difficulty of localization of the failure occurs if one of them erroneously sets the state of the low level.

I2C module for LCD 1602 Arduino

The fastest and most convenient way to use the I2C display in Arduino is the purchase of a finished screen with built-in support protocol. But there are no such screens a lot of impacts they are not cheap. But a variety of standard screens has already been released a huge amount. Therefore, the most affordable and popular option is the purchase and use of a separate I2C module - an adapter that looks like this:

On the one side of the module, we see the conclusions of I2C - Earth, meals and 2 for data transmission. With another adapter, we see the external power connectors. And, naturally, there are many legs on the board, with the help of which the module is soldered to the standard outputs of the screen.


I2c outputs are used to connect to the Arduino board. If you need, we connect external nutrition for a contraction. Using the built-in trimming resistor, we can configure custom contrast values \u200b\u200bJ

On the market you can find LCD 1602 modules with already soldered adapters, their use is most susceptible. If you bought a separate adapter, you will need to pre-solder it to the module.

Connecting the LCD screen to Arduino via I2C

Arduino, display, duct, connecting wires, and potentiometer are needed for connectivity.

If you use a special separate I2C adapter, you must first solder it to the screen module. It is difficult to make mistakes there, you can guide such a scheme.


The I2C-supported liquid crystal monitor is connected to the board using four wires - two wires for data, two wires for power supply.

  • The GND output is connected to the GND on the board.
  • VCC output - on 5V.
  • SCL connects to Pin A5.
  • SDA connects to Pina A.

And it's all! No paouth of wires in which it is very easy to get confused. At the same time, the difficulty of implementing the I2C protocol we can simply entrust the libraries.

Libraries to work with I2C LCD display

For the interaction of Arduino C LCD 1602 via I2C bus, you will need at least two libraries:

  • The Wire.h library for working with I2C is already available in the Standard Arduino IDE program.
  • LIQUIDCRYSTAL_I2C.H library, which includes a wide variety of commands to control the monitor over the I2C bus and allows you to make a sketch easier and shorter. You need to additionally install the library after connecting the display you need to additionally install the LiquidCrystal_i2c.h library

After connecting to the Sketch of all the necessary libraries, we create an object and can use all of its functions. For testing, let's drive the following standard sketch from the example.

#Include. #Include. // Library Connection // # INCLUDE // Connect the alternative library LiquidCrystal_i2c LCD (0x27,16,2); // Indicate the I2C address (the most common value), as well as the screen parameters (in the case of LCD 1602 - 2 lines of 16 characters in each // LiquidCrystal_PCF8574 LCD (0x27); // Option for the PCF8574 Void setup library () (lcd.init (); // Initialization of the LCD.BackLight () display; // Connecting the LCD.Setcursor backlight (0,0); // Setting the cursor to the beginning of the first line LCD.Print ("Hello"); // Set of text on the first row LCD.Setcursor (0,1); // Installing the cursor to the beginning of the second line LCD.Print ("ArduinoMaster"); // Text Set on the second line) void loop () ()

Description of the functions and methods of LiquidCrystal_i2c library:

  • home () and Clear () - The first function allows you to return the cursor to the beginning of the screen, the second too, but at the same time removes everything that was on the monitor before.
  • write (CH) - allows you to output a single CH symbol on the screen.
  • cursor () and Nocursor () - Shows / Hides the cursor on the screen.
  • blink () and noblink () - the cursor flashes / does not flash (if it is turned on to display).
  • display () and Nodisplay () - allows you to connect / disable the display.
  • scrollDisplayLeft () and ScrollDisplayRight () - scrolls the screen to one sign left / right.
  • autoScroll () and Noautoscroll () - Allows you to enable / disable auto-rotation mode. In this mode, each new character is written in the same place, displacing previously written on the screen.
  • lefttoright () and RightToleft () - Setting the direction of the output text - from left to right or right left.
  • cREATECHAR (CH, BITMAP) - Creates a symbol with CH (0 - 7) code using Bitmap bitmasse array to create black and white dots.

Alternative Library for Working with I2C Display

In some cases, when using the specified library with devices equipped with PCF8574 controllers, errors may occur. In this case, as an alternative, you can offer the library LiquidCrystal_pcf8574.h. It expands LiquidCrystal_i2c, so there should be no problems with its use.

I2C LCD Display Connection Problems

If after downloading the Sketch you did not have any inscription on the display, try the following steps.

First, you can increase or decrease the contrast of the monitor. Often symbols are simply not visible due to the contrast and backlight mode.

If it does not help, then check the correct contacts to connect whether the backlight is connected. If you used a separate I2C adapter, then check the quality of the contact soldering.

Another common reason for the lack of text on the screen can be incorrect I2c address. Try first to change the device address in the Sketch with 0x27 0x20 or 0x3F. Different manufacturers can be sewn different default addresses. If it did not help, you can run the Sketch of the I2C scanner, which views all connected devices and determines their address by the method of extinguishing. Example Sketch I2C scanner.

If the screen still remains not working, try to disappear adapter and connect the LCD in the usual way.

Conclusion

In this article, we reviewed the basic issues of using the LCD screen in the complex projects Arduino, when we need to save free kicks on the board. The simple and inexpensive I2C adapter will allow you to connect the LCD screen 1602, occupying only 2 analog pins. In many situations, it can be very important. Fee for convenience - the need to use an optional module - converter and library. In our opinion, not at all high price for convenience and we extremely recommend using this opportunity in projects.