Devices & Components
Arduino Uno Rev3
IIC I2C TWI 1602 Serial LCD Module Display for Arduino R3 Mega 2560 16x2
Resistor 220 ohm
Hardware & Tools
Materia 101
Software & Tools
Arduino IDE
Project description
Code
LCD_i2c_example.ino
c_cpp
1//Compatible with the Arduino IDE 1.0 2//Library version:1.1 3//Code by Dana Dietz with the help of Jeremy Blum, Sunfounder and others who wrote lcd code 4//My first code using I2C 5//LCD 1602A with backpack PCF85724T (I2C) 6//This example shows you how to use the LCD with an I2C backpack 7//It shows you how the I2C only accepts one bit at a time by printing only the first character of an array 8//It then shows you how to print several characters at once either staying in one position, or scrolling, in this case, to the left 9 10#include <Wire.h> //wire library 11#include <LiquidCrystal_I2C.h> //liquid crystal with I2C library 12 13LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display 14 15char array1[] = "Hello! "; //an array to print on line 0 16char array2[] = "You did it!"; //an array to print on line 1 17char array3[] = "Oops! "; 18char array4[] = "1 Bit at a time!"; 19 20 21void setup() 22{ 23 lcd.init(); // initialize the lcd 24 25 lcd.backlight(); //Turn on backlight 26 27 28} 29 30void loop() 31{ 32 //show that I2C only accepts one byte at a time 33 lcd.setCursor(0, 0); //set cursor at top left 34 lcd.print(array1);//will only print the first letter of the array 35 lcd.setCursor(0, 1); //set cursor at left space on 2nd row 36 lcd.print(array2);//will only print the first letter of the array 37 delay(2000); 38 39 lcd.clear(); 40 lcd.setCursor(0, 0); 41 for ( int positionCounter1 = 0; positionCounter1 < 17; positionCounter1++) 42 { 43 44 lcd.print(array3[positionCounter1]); //prints a 17 character array without scrolling 45 delay(250); 46 47 } 48 49 { 50 lcd.setCursor(0, 1); 51 for (int positionCounter2 = 0; positionCounter2 < 17; positionCounter2++) 52 { 53 lcd.print(array4[positionCounter2]);//prints a 17 character or array without scrolling 54 } 55 delay(3000); 56 lcd.clear(); 57 } 58 { 59 lcd.setCursor(15, 0); // set the cursor to column 15, line 0 60 for ( int positionCounter1 = 0; positionCounter1 < 11; positionCounter1++) 61 { 62 lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left. 63 lcd.print(array1[positionCounter1]); // Print 12 character array 64 delay(500); 65 } 66 delay(1000); 67 lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. 68 69 lcd.setCursor(15, 1); // set the cursor to column 15, line 1 70 for (int positionCounter2 = 0; positionCounter2 < 11; positionCounter2++) 71 { 72 lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left. 73 lcd.print(array2[positionCounter2]); // Print a message to the LCD. 74 delay(500); 75 } 76 delay(5000); 77 } 78 lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. 79} 80
Downloadable files
LCD 1602 w I2c Communication PCF8574T
Display text on the LCD using I2C Communication
LCD 1602 w I2c Communication PCF8574T
LCD 1602 w I2c Communication PCF8574T
Display text on the LCD using I2C Communication
LCD 1602 w I2c Communication PCF8574T
Comments
Only logged in users can leave comments