Taillieu.Info

More Than a Hobby..

DS1307

DS1307

Enhanced LiquidCrystal_I2C LCD1602 Module

Introduction

This is another great LCD display from DFRobot. With the limited pin resources, your project may be out of resources using normal LCD shield. With this I2C interface LCD module, you only need 2 lines (I2C) to display the information. If you already has I2C devices in your project, this LCD module actually cost no more resources at all. Fantastic for Arduino based project. 

See also: Arduino LCD KeyPad Shield 

 

connect SDA to pin A4 and SCL to pin A5 on your Arduino


 

A2 A1 A0 地址
0 0 0 0x20
0 0 1 0x21
0 1 0 0x22
0 1 1 0x23
1 0 0 0x24
1 0 1 0x25
1 1 1 0x26
1 1 1 0x27

Sample sketch: Control the back light of the I2C LCD1602 Module

 


/* LCD_I2C_demo.ino */

/*-----( Import needed libraries )-----*/ 

#include <Wire.h>

//#include <LCD.h>

#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

 

/*-----( Declare Constants )-----*/

#define I2C_ADDR    0x27  // Define I2C Address for the PCF8574A 

//---(Following are the PCF8574 pin assignments to LCD connections )----

// This are different than earlier/different I2C LCD displays

#define BACKLIGHT_PIN  3  //7

#define En_pin  2  //4

#define Rw_pin  1

#define Rs_pin  0  //6

#define D4_pin  4  //0

#define D5_pin  5  //1

#define D6_pin  6  //2

#define D7_pin  7  //3

 

#define pinBusyLed13

#define BusyLed_ON digitalWrite( pinBusyLed, HIGH ) // Turn of BusyLED

#define BusyLed_OFF digitalWrite( pinBusyLed, LOW ) // Turn on BusyLED

 

/*-----( Declare objects )-----*/  

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE ); //NEGATIVE, POSITIVE

 

void setup()   /*----( SETUP: RUNS ONCE )----*/

{

  // initialize the digital pin as an output.

  pinMode(pinBusyLed, OUTPUT); 

  BusyLed_ON ;

  

  // Serial Setup

  Serial.begin (115200);

 

  // Leonardo: wait for serial port to connect

  while (!Serial) 

    {

    }

// I2C Scan

  Serial.println ();

  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).");

// __________________________________________________________

 

// initialize the lcd   

  Serial.println ("initialize the lcd");  

  lcd.begin (20,4);  // initialize the lcd 

// Reset the display  

  lcd.clear();

  lcd.noBacklight();

  delay(100);

  lcd.home();

  lcd.backlight();// ------- Quick blinks of backlight  -------------

 

  BusyLed_OFF ;

}// END Setup

 

void loop()   /*----( LOOP: RUNS OVER AND OVER AGAIN )----*/

{

  BusyLed_ON;

 

// Reset the display  

  lcd.clear();

  delay(1000);

  lcd.home();

  

// Print our characters on the LCD

  lcd.backlight();  //Backlight ON if under program control

  lcd.setCursor(0,0); //Start at character 0 on line 0

  lcd.print("Hello, world!");

  delay(500);

  BusyLed_OFF;

 

  lcd.setCursor(0,1); //Start at character 0 on line 1

  lcd.print("16 by 2 Display");

  delay(500);

 

  lcd.setCursor(2,2); //Start at character 0 on line 2

  lcd.print("20 by 4 Display");

  delay(500);

 

  lcd.setCursor(0,3); //Start at character 0 on line 3

  lcd.print("12345678901234567890");

  delay(1000);

 

} // END Loop