Arduino LCD1602 / 2004

Arduino LCD1602 / 2004

This page is to Setup and Config LCD1602 / 2004

Hardware and Software

Hardware

LCD1602 / 2004

Software

Arduino IDE

Example : https://arduino-info.wikispaces.com/LCD-Blue-I2C

Sanki Notes

    • Address : 0x27 default or A0, A1 A2 - 0x23 - 0x27

Examples

This example is Display on 1602 and 2004

          1. /* YourDuino.com Example Software Sketch

          2. 16 character 2 line I2C Display

          3. Backpack Interface labelled "A0 A1 A2" at lower right.

          4. ..and

          5. Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"

          6. MOST use address 0x27, a FEW use 0x3F

          7. terry@yourduino.com */

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

          9. #include <Wire.h> // Comes with Arduino IDE

          10. // Get the LCD I2C Library here:

          11. // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

          12. // Move any other LCD libraries to another folder or delete them

          13. // See Library "Docs" folder for possible commands etc.

          14. #include <LiquidCrystal_I2C.h>

          15. /*-----( Declare Constants )-----*/

          16. /*-----( Declare objects )-----*/

          17. // set the LCD address to 0x27 for a 16 chars 2 line display

          18. // A FEW use address 0x3F

          19. // Set the pins on the I2C chip used for LCD connections:

          20. // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol

          21. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

          22. /*-----( Declare Variables )-----*/

          23. //NONE

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

          25. {

          26. Serial.begin(9600); // Used to type in characters

          27. lcd.begin(20,4); // initialize the lcd for 16 chars 2 lines, turn on backlight

          28. // lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight

          29. // ------- Quick 3 blinks of backlight -------------

          30. for(int i = 0; i< 3; i++)

          31. {

          32. lcd.backlight();

          33. delay(250);

          34. lcd.noBacklight();

          35. delay(250);

          36. }

          37. lcd.backlight(); // finish with backlight on

          38. //-------- Write characters on the display ------------------

          39. // NOTE: Cursor Position: (CHAR, LINE) start at 0

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

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

          42. delay(100);

          43. lcd.setCursor(0,1);

          44. lcd.print("HI!YourDuino.com");

          45. delay(100);

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

          47. lcd.print("Sanki Poon");

          48. delay(100);

          49. lcd.setCursor(0,3);

          50. lcd.print("iMediaBank.com");

          51. delay(4000);

          52. // Wait and then tell user they can start the Serial Monitor and type in characters to

          53. // Display. (Set Serial Monitor option to "No Line Ending")

          54. lcd.clear();

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

          56. lcd.print("Use Serial Mon");

          57. lcd.setCursor(0,1);

          58. lcd.print("Type to display");

          59. lcd.setCursor(0,2);

          60. lcd.print("Anything");

          61. lcd.setCursor(0,3);

          62. lcd.print("********");

          63. }/*--(end setup )---*/

          64. void loop() /*----( LOOP: RUNS CONSTANTLY )----*/

          65. {

          66. {

          67. // when characters arrive over the serial port...

          68. if (Serial.available()) {

          69. // wait a bit for the entire message to arrive

          70. delay(100);

          71. // clear the screen

          72. lcd.clear();

          73. // read all the available characters

          74. //lcd.setCursor(0,2);

          75. while (Serial.available() > 0) {

          76. // display each character to the LCD

          77. lcd.write(Serial.read());

          78. }

          79. }

          80. }

          81. }/* --(end main loop )-- */

          82. /* ( THE END ) */