1. /*
  2. ** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens
  3. ** Readily found on eBay or http://www.sainsmart.com/
  4. ** The LCD2004 module appears to be identical to one marketed by YwRobot
  5. **
  6. ** Address pins 0,1 & 2 are all permenantly tied high so the address is fixed at 0x27
  7. **
  8. ** Written for and tested with Arduino 1.0
  9. ** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
  10. ** https://bitbucket.org/fmalpartida/new-liquidcrystal
  11. **
  12. ** Edward Comer
  13. ** LICENSE: GNU General Public License, version 3 (GPL-3.0)
  14. */
  15. #include <Wire.h>
  16. #include <LCD.h>
  17. #include <LiquidCrystal_I2C.h>
  18.  
  19. #define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is
  20. #define BACKLIGHT_PIN     3
  21. #define En_pin  2
  22. #define Rw_pin  1
  23. #define Rs_pin  0
  24. #define D4_pin  4
  25. #define D5_pin  5
  26. #define D6_pin  6
  27. #define D7_pin  7
  28.  
  29. int n = 1;
  30.  
  31. LiquidCrystal_I2C   lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  32.  
  33. void setup()
  34. {
  35.   lcd.begin (20,4);
  36.  
  37. // Switch on the backlight
  38.   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  39.   lcd.setBacklight(HIGH);
  40.   lcd.home ();                   // go home
  41.  
  42.   lcd.print("SainSmart I2C test");  
  43.   lcd.setCursor ( 0, 1 );        // go to the next line
  44.   lcd.print("F Malpartida library");
  45.   lcd.setCursor ( 0, 2 );        // go to the next line
  46.   lcd.print("Test By Edward Comer");
  47.   lcd.setCursor ( 0, 3 );        // go to the next line
  48.   lcd.print("Iteration No: ");
  49. }
  50.  
  51. void loop()
  52. {
  53.   // Backlight on/off every 3 seconds
  54.   lcd.setCursor (14,3);        // go col 14 of line 3
  55.   lcd.print(n++,DEC);
  56.   lcd.setBacklight(LOW);      // Backlight off
  57.   delay(3000);
  58.   lcd.setBacklight(HIGH);     // Backlight on
  59.   delay(3000);
  60. }