Acoptex.Com

Learn ESP32, ESP8266, Arduino, and Raspberry Pi

Arduino tutorial: scrolling text on LCD1602 I2C Display

We are going to learn how to make the text scrolling on LCD 1602 I2C Display attached to the Arduino board.

Tag: Project 011 1602 lcd display arduino i2c scrolling text

Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you. Acoptex.com

Project resources

  • Libraries: We have used the library – NewliquidCrystal_1.3.4.zip which we downloaded, unzipped, changed the name of folder to LiquidCristal and added to libraries in our PC, for example C:\Users\acoptexCom\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. If you have LiquidCristal folder in this location already – delete this folder and copy folder, which was made by you, to this location.
  • Code: sketch;
  • Datasheets: NXP Semiconductors and Texas Instruments;
  • Other: Fritzing drawings and views.

Parts required

1. Arduino Uno R3 1 pc (you can also use the other version of Arduino);

Arduino Uno

2. LCD1602 I2C Display module 1 pc;

LCD16x2 (LCD1602) I2C display

3. Arduino IDE ( you can download it from here  )

4. Jumper cables F-M 4 pcs.

jumper cables

Understanding LCD1602 I2C module

If you have ever tried to connect an LCD1602 display with an Arduino board, you may have noticed that it is using a lot of Arduino board pins. Even in 4-bit mode, the Arduino still requires 7 connections – that is half of Arduino’s available digital I/O pins. The best solution is to use an LCD1602 I2C Display. It consumes only two I/O pins that are not even part of a set of digital I/O pins and can also be shared with other I2C devices.

A typical LCD1602 I2C Display consists of a HD44780 based character LCD Display (LCD1602 Display) and an I2C LCD adapter.

LCD16x2 (LCD1602) I2C display

The meaning of LCD1602 (LCD16x2) marking is Liquid Cristal Display 16 characters by 2 rows, it can display 32 ASCII characters in two rows with 16 characters on each row of either 5×7 or 5×8 dot matrix characters. The LCD is available in a 16 pin package. It consists of LED backlight and contrast adjustment function and each dot matrix has 5×8 dot resolution.

If you look closely, you can actually see the little rectangles for each character on the display and the pixels that make up a character. Each of these rectangles is a grid of 5×8 or 5×7 pixels.

Each of these rectangles is a grid of 5×8 or 5x7 pixels.

At the heart of the I2C LCD Adapter is an 8-Bit I/O Expander chip – PCF8574. This chip converts the I2C data from an Arduino into the parallel data required by the LCD display. The board also comes with a small trimpot to make display’s contrast adjustments. There is a jumper on the board that supplies power to the backlight. To control the intensity of the backlight, you can remove the jumper and apply an external voltage to the header pin that is marked as LED.

LCD1602 I2C Display backside

If you are using multiple devices on the same I2C bus, you may need to set a different I2C address for the board, so that it does not conflict with another I2C device. To do so, the board has three solder jumpers (A0, A1 and A2) or solder pads. Each of these is used to hardcode the address. If a jumper is shorted with a blob of solder, it sets the address. An important point here is that many 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.

solder pads of I2C Display adapter

Signals and connections of LCD1602 I2C module

I2C address

If your LCD16x2 I2C Display has a PCF8574 chip from Texas Instruments:

According to the Texas Instruments’ datasheet, three address selection bits (A0, A1 and A2) are placed at the end of the 7-bit I2C address register.

I2C address

As there are 3 address inputs, which can take 2 states, either HIGH/LOW, we can therefore create 8 (23) different combinations(addresses). By default, all the 3 address inputs are pulled HIGH using onboard pullups, giving PCF8574 a default I2C address of 0100111 Binary or 0x27 Hex.

By shorting the solder jumpers, the address inputs are puled LOW. If you were to short all three jumpers, the address would be 0x20. The range of all possible addresses spans from 0x20 to 0x27. Please refer the below table.

If your LCD16x2 I2C Display has a PCF8574 chip from Texas Instruments

If your LCD16x2 I2C Display has a PCF8574 chip from NXP Semiconductors:

According to the NXP Semiconductors’ datasheet, three address selection bits (A0, A1 and A2) are also placed at the end of the 7-bit I2C address register. But other bits in the Address Register are different.

I2C address

The 3 address input can have 2 states, either HIGH / LOW, giving us 8 (23) different combinations.

By default, all the 3 address inputs are pulled HIGH using onboard pullups, giving PCF8574 a default I2C address of 0111111 Binary or 0x3F Hex.

By shorting the solder jumpers, the address inputs are puled LOW. If you were to short all three jumpers, the address would be 0x38. The range of all possible addresses spans from 0x38 to 0x3F. Please refer the below table.

If your LCD16x2 I2C Display has a PCF8574 chip from NXP Semiconductors

Pinout

LCD16x2 I2C module has 4 pins.

GNDa ground pin and should be connected to the ground of Arduino board.
VCCsupplies power to the module and the LCD. Connect it to the 5V
output of the Arduino or a separate power supply.
SDAa Serial Data pin. This line is used for both transmit and receive. Connect to the SDA pin on the Arduino board.
SCLa Serial Clock pin. This is a timing signal supplied by the Bus Master device. Connect to the SCL pin on the Arduino board.

Wiring

It is much easier to connect an LCD16x2 I2C Display than to connect a LCD16x2. You only need to connect 4 pins instead of 12. Start by connecting VCC(VIN) pin to the 5V output on the Arduino board and connect GND to ground.

Now we are remaining with the pins that are used for I2C communication. Note that each Arduino Board has different I2C pins which should be connected accordingly. On the 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).

If you are using a different Arduino board, please refer below table.

Board / PinsSDASCL
Arduino UnoA5A4
Arduino NanoA5A4
Arduino Mega2120
Leonardo/Micro32
Wiring LCD16x2 (LCD1602) I2C display with Arduino Uno | Acoptex.com
Wiring LCD16x2 (LCD1602) I2C display with Arduino Uno | Acoptex.com

Step by Step instruction

  1. Do wiring. 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.
  2. Plug your Adruino Uno board into your PC/Laptop USB port. You should see the backlight light up. Now rotate the potentiometer until the first line of the rectangle appears.
  3. Open Arduino IDE. Select the correct board and COM port.
  4. It is recommended that you find out the actual I2C address of the LCD16x2 I2C Display before using. It depends on the manufacturer: if your LCD has a PCF8574 chip from Texas Instruments, its default I2C address is 0x27. If your LCD has a PCF8574 chip from NXP semiconductors, its default I2C address is 0x3F.
  5. Open and upload the sketch from http://playground.arduino.cc/Main/I2cScanner and follow the instructions to use it.  
  6. Open Arduino Serial Monitor at 9600 baud and Arduino board will find the actual I2C address.  Even though the documentation said it was 0x27, this sketch can detect different (in my case 0x3F)
  7. Modify the sketch: the line LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE) (See part marked bold)
  8. Verify and upload the sketch to your Adruino Uno.
  9. You should now see your LCD1602 I2C Display scrolling this text: 1602 serial – Acoptex.com. If you want you can change the text of the message.
scrolling text on LCD1602 I2C Display with Arduino board | Acoptex.com

Code

#include <LiquidCrystal_I2C.h> // first we include the LiquidCrystal_I2C library

/*Next an object of LiquidCrystal_I2C class is created. This object uses many parameters LiquidCrystal_I2C(addr,en,rw,rs,d4,d5,d6,​d7,bl,blpol). This is where you will need to change the default address to the address you found earlier if it happens to be different -marked with bold.*/
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//Once the LiquidCrystal_I2C object is declared, you can access special methods that are specific to the LCD
void setup()
 {    
    lcd.begin (16,2); // define the LCD as 16 column by 2 rows 
    
    // switch on the backlight
    lcd.setBacklightPin(3,POSITIVE);
    lcd.setBacklight(HIGH);
        
    lcd.setCursor(0,0); // go to first column (column 0) and first line (Line 0)     
    lcd.print("1602 serial"); // print at cursor location
        
    lcd.setCursor(0,1); // go to first column (column 0) and second line (line 1)
    lcd.print("- Acoptex.com");
    
 }
void loop(){ }

Wrapping up

We have learned about the LCD1602 I2C Display, how to use it with Arduino board and printed the first message on LCD16x2 I2C Display.

There are other libraries available for LCD16x2 I2C Display: LiquidCrystal I2C library by Frank de Brabander. You will need to use different code with each library to run your LCD16x2 I2C Display

Thank you for reading!

Other similar posts

Arduino tutorial for LCD1602 I2C display (LiquidCrystal_I2C library)

Check for more DIY projects on Acoptex.lt and Acoptex.com!

If you are looking for high quality PCBs PCBWay is the best choice: