Difference between revisions of "I²C LCD1602"

From Wiki
Jump to: navigation, search
(Experimental Procedures)
(Experimental Procedures)
Line 97: Line 97:
  
 
[http://www.sunfounder.com/wiki/index.php?title=File:I2C_LCD1602_Test_Experiment_for_Arduino.zip I2C_LCD1602_Test_Experiment_for_Arduino][[File:ZIP.jpg]]<br>
 
[http://www.sunfounder.com/wiki/index.php?title=File:I2C_LCD1602_Test_Experiment_for_Arduino.zip I2C_LCD1602_Test_Experiment_for_Arduino][[File:ZIP.jpg]]<br>
[http://www.sunfounder.com/wiki/index.php/File:I2C_LCD1602_Test_Experiment_for_Raspberry_Pi.zip I2C_LCD1602_Test_Experiment_for_Raspberry_Pi][[File:ZIP.jpg]]<br>[[File:ZIP.jpg]]<br>
+
[http://www.sunfounder.com/wiki/index.php/File:I2C_LCD1602_Test_Experiment_for_Raspberry_Pi.zip I2C_LCD1602_Test_Experiment_for_Raspberry_Pi][[File:ZIP.jpg]]<br>
 +
 
 
[http://www.sunfounder.com/wiki/index.php/File:PCF8574T_datasheet.pdf PCF8574T_datasheet][[File:PDF.jpg]]
 
[http://www.sunfounder.com/wiki/index.php/File:PCF8574T_datasheet.pdf PCF8574T_datasheet][[File:PDF.jpg]]

Revision as of 09:47, 29 March 2016

Introduction

As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness. When they are connected to a controller, multiple IOs will be occupied of the controller which has no so many outer ports. Also it restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed to solve the problem.
I2C bus is a type of serial bus invented by PHLIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple host system. I2C bus has only two bidirectional signal lines, Serial Data Line (SDA) and Serial Clock Line (SCL). The blue potentiometer on the I2C LCD1602 is used to adjust backlight to make it easier to display on the I2C LCD1602.
Back.png

Components

- 1 *SunFounder Uno board
- 1 * I2C LCD1602 module
- 1 * USB cable
- Several jump wires

Experimental Principle

In this experiment, we will let I2C LCD1602 display “SUNFOUNDER" and “hello, world" by programming.
I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers. Alternatively I²C is spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).
I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers. Alternatively I²C is spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).
I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.
For more information about I2C operation principle, please visit I²C.

Experimental Procedures

Step 1: Connect the circuit
See the following table for connection between the I2C LCD1602 and the SunFounder Uno board:

I2C LCD1602 SunFounder Uno board
GND GND
VCC 5V
SDA A4
SCL A5
Experiment.png

Note: The wiring of I2C LCD1602 is the same through the following lessons.

Step 2: Program

/********************************
 * name:I2C LCD1602
 * function:You should now see your I2C LCD1602 display the flowing characters: "SunFounder" and "hello, world".
 ********************************/
//Email:support@sunfounder.com
//Website:www.sunfounder.com

/********************************/
// include the library code
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
/**********************************************************/
char array1[]=" SunFounder               ";  //the string to print on the LCD
char array2[]="hello, world!             ";  //the string to print on the LCD
int tim = 500;  //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
/*********************************************************/
void setup()
{
  lcd.init();  //initialize the lcd
  lcd.backlight();  //open the backlight 
}
/*********************************************************/
void loop() 
{
  lcd.setCursor(15,0);  // set the cursor to column 15, line 0
  for (int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++)
  {
    lcd.scrollDisplayLeft();  //Scrolls the contents of the display one space to the left.
    lcd.print(array1[positionCounter1]);  // Print a message to the LCD.
    delay(tim);  //wait for 250 microseconds
  }
  lcd.clear();  //Clears the LCD screen and positions the cursor in the upper-left corner.
  lcd.setCursor(15,1);  // set the cursor to column 15, line 1
  for (int positionCounter = 0; positionCounter < 26; positionCounter++)
  {
    lcd.scrollDisplayLeft();  //Scrolls the contents of the display one space to the left.
    lcd.print(array2[positionCounter]);  // Print a message to the LCD.
    delay(tim);  //wait for 250 microseconds
  }
  lcd.clear();  //Clears the LCD screen and positions the cursor in the upper-left corner.
}
/************************************************************/

Step 3: Compile the code
Before compiling the code, you need to add the LiquidCrystal_I2C file to the libraries of Arduino. If you don't know the libraries path, you can open Arduino IDE ,click File ->Preferences, as shown in the follwing diagram. Then add LiquidCrystal_I2C to the folder Libraries under the path

I2c lcd1602 2.png

Step 4: Upload the sketch to the SunFounder Uno board You should now see your I2C LCD1602 display the flowing characters "SunFounder" and "hello, world".

I2c lcd102 1.png

I2C_LCD1602_Test_Experiment_for_ArduinoZIP.jpg
I2C_LCD1602_Test_Experiment_for_Raspberry_PiZIP.jpg

PCF8574T_datasheetPDF.jpg