Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

I2C Liquid Crystal Display

Available Languages
Picture
Picture

Introduction 

Picture
In this tutorial you will learn how to use an I2C LCD 16x2 display (and 20x4, e.t.c.) with Arduino uno. With I2C module you will be able to connect the LCD with Arduino board with only two cables! The i2c module has a built in potentiometer for contrast adjustment. 

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard (optional)
  • I2C LCD 16x2
Picture

I2C Address

​Some of I2C LCD interfaces have pins (or solder pads) that can be changed to change the address. They are usually labelled as A0-A1-A2 . Here's how the address change from a default 0x27 or 0x3F,  if you connect the address pads together. (1 = Not Connected. 0 = Connected):
Picture

The Circuit

The connections are easy,
  • GND to GND
  • Vcc to 5V
  • SDA to Analog 4
  • ​SCL to Analog 5

I2C Address Scanner

I found the below code here, you can scan and find the i2c address of your display.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (9600);
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}
i2c_find_address.zip
File Size: 0 kb
File Type: zip
Download File

Gearbest Flash Sale: Up to 80% Off promotion
Flash Sale: Up to 80% Off

The code

The LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE) init the library, change the LCD I2C address, try 0x27 if it's not working.

The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20x4).

The lcd.print("--message--") command print a message to first column and row of lcd display. The "message" must have maximum length equal to lcd columns number. For example, for 16 columns display max length is equal with 16 and for 20 columns display max length is equal with 20.
​
The lcd.setCursor(0,1) command will set cursor to first column of second row. If you have an LCD 20x4 and you want to print a message to column five and third row you have to use: lcd.setCursor(4,2).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/* I2C LCD 16x2 Arduino Tutorial
 * More info http://www.ardumotive.com/i2clcd(en).html
 * Dev: Michalis Vasilakis Date: 19/11/2016 Ver. 1.0 */

//Libraries 
#include <Wire.h>  
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address, if it's not working try 0x27.

void setup(){
  lcd.begin(16,2);   // iInit the LCD for 16 chars 2 lines
  lcd.backlight();   // Turn on the backligt (try lcd.noBaklight() to turn it off)
  lcd.setCursor(0,0); //First line
  lcd.print("I2C LCD Tutorial");
  lcd.setCursor(0,1); //Second line
  lcd.print("*Ardumotive.com*");
}

void loop(){
}
Download the code from here and open it with Arduino IDE. Inside you will also find additional libraries.
lcd_i2c_16x2_tutorial.zip
File Size: 0 kb
File Type: zip
Download File

You can keep playing with that and start making your own modifications to the code. For example, try to change message on first and second row.

Well done!

Picture
You have successfully completed one more Arduino "How to" tutorial and you learned how to use an i2c LCD display with Arduino uno.
I hope you liked this, let me know in the comments.
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates