Introduction
What you will need - Hardware
For this tutorial you will need:
|
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):
The Circuit
The connections are easy,
|
|
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() {} |
![](http://www.weebly.com/weebly/images/file_icons/gz.png)
i2c_find_address.zip | |
File Size: | 0 kb |
File Type: | zip |
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).
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.
|
![]()
|
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!
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.
I hope you liked this, let me know in the comments.