This is a simple project to interface the 20x4 LCD
Module by SainSmart using the Arduino Uno. I got my LCD module in Amazon, listed as SainSmart LCD Module For Arduino 20 X 4, PCB Board, White On Blue.
Based on customer reviews, the module may or may not come with a I2C module depending on which seller it comes from (mine was BeesClover). Also, the package may not include the datasheet and some components. This LCD module can be considered cheap if you have Amazon Prime, since shipping would have added 40-50% to the cost.
Based on customer reviews, the module may or may not come with a I2C module depending on which seller it comes from (mine was BeesClover). Also, the package may not include the datasheet and some components. This LCD module can be considered cheap if you have Amazon Prime, since shipping would have added 40-50% to the cost.
Fig 1. SainSmart 20x4 LCD
Fig 2. SainSmart 20x4 LCD
Fig 3. I2C Adapter. The rotary knob controls the contrast.
4. Find the I2C address for the module in the datasheet. Otherwise, use the I2cScanner library to find the address in your device.
The file with this code can be downloaded from my repository https://github.com/sphanlung/Arduino under the name SainsmartLCD.ino
Fig 5. LCD displaying Hello World
Fig 6. Datasheet - Page 1
Fig 7. Datasheet - Page 2
Below are the instructions to test the LCD module with an I2C adapter:
1. Do an online search and download the Arduino library file LiquidCrystal_V1.2.1.zip. This file was developed by F. Malpartida and modifies the Arduino default LCD library to be compatible with the Hitachi HD44780 and compatible chipsets.
2. Replace the default LiquidCrystal Arduino library with the folder contained in the new file. You'll need a program like 7zip to decompress the ZIP file.
3. Connect the pins in the I2C adapter to the Arduino Uno, matching the 5V and GND pins on both boards, the SDA pin to A4 and SCL with A5.
Note: Pins vary for other Arduino boards. For Mega2560, use pins 20, 21; for Leonardo, pins 2, 3; for Due, pins 20, 21, SDA1, SCL1.
1. Do an online search and download the Arduino library file LiquidCrystal_V1.2.1.zip. This file was developed by F. Malpartida and modifies the Arduino default LCD library to be compatible with the Hitachi HD44780 and compatible chipsets.
2. Replace the default LiquidCrystal Arduino library with the folder contained in the new file. You'll need a program like 7zip to decompress the ZIP file.
3. Connect the pins in the I2C adapter to the Arduino Uno, matching the 5V and GND pins on both boards, the SDA pin to A4 and SCL with A5.
Note: Pins vary for other Arduino boards. For Mega2560, use pins 20, 21; for Leonardo, pins 2, 3; for Due, pins 20, 21, SDA1, SCL1.
4. Find the I2C address for the module in the datasheet. Otherwise, use the I2cScanner library to find the address in your device.
5. Load the code sample below into the Arduino. The display should read "Hello World" in each row while turning on and off every second. Make sure that the address in #define I2C_ADDR matches the value in the datasheet.
#include <Wire.h> // Loads I2C interface library
#include <LiquidCrystal_I2C.h> // Loads LCD library for I2C
#define I2C_ADDR 0x27 // Set I2C device address
//Define pins in LCD controller for I2C interface. Don't change.
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin, D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin (20,4,LCD_5x8DOTS); //Define type of LCD display
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
}
// Start LCD display loop
void loop()
{
lcd.setBacklight(HIGH); // Turn on LCD backlight
lcd.clear(); // Clear LCD characters
lcd.print("HELLO WORLD 1 "); // Print rows 1 through 4
lcd.print("HELLO WORLD 2 ");
lcd.print("HELLO WORLD 3 ");
lcd.print("HELLO WORLD 4 ");
delay(1000); // Wait 1000 ms (1 sec)
lcd.clear(); // Clear LCD characters
lcd.setBacklight(LOW); // Turn off LCD backlight
delay(1000); // Wait 1000 ms (1 sec)
}
The file with this code can be downloaded from my repository https://github.com/sphanlung/Arduino under the name SainsmartLCD.ino
Fig 4. Arduino interfacing with LCD
Fig 6. Datasheet - Page 1
Fig 7. Datasheet - Page 2
Great blog as there is nothing better than technical project blogs. Yours is filled with fantastic information and is for sure set to become one of my favorite. I love doing various projects and fixing electrical stuff. I start by going online to find great sites to learn from and once I do it is all perfect from that aspect.
ReplyDeleteBrian Hopkins @ Microtips USA
Thank you. Happy to know people find these posts useful.
DeleteThis is a very well written post and very informative. It's not for the faint of hearted or for beginners but there is lots of useful information in there for us "techies" so I guess what I'm trying to say is, Keep up the good work. I look forward to reading more about your progress and future projects.
ReplyDeleteRaymond @ CKS Global Solutions LTD