Loading [MathJax]/extensions/MathZoom.js

Monday, 10 August 2020

LCD Display and Arduino


This blog describes the steps taken to setup a 20 x 4 Character LCD Display. The one I'm using has a small add on board at the back of the display that requires only 4 connections to the Arduino.

The LiquidCrystal_I2C library needs to be downloaded and installed on the Arduino IDE. The source and zip can be downloaded from GitLab https://gitlab.com/tandembyte/LCD_I2C

Then in the Arduino IDE select Sketch -> Include Library -> Add .ZIP Library...

The pin assignments for the LCD to Arduino are:

LCD Arduino
GND GND
VCC 5V
SDA A4
SCL A5

The Arduino code is simple, first you need to #include <LiquidCrystal_I2C.h> and create the instance. The parameters are the address of the LCD (typically 0x27), the number of columns (20 for my model) and the number of rows (4).

#include <Wire.h> // Library for I2C Communication
#include <LiquidCrystal_I2C.h>
// 0x27 is the address of the LCD
LiquidCrystal_I2C lcd(0x27,20,4);
char *names[] = {" Scrolling ", " LCD ", " Testing ", " Changing Rows "};
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(names[0]);
lcd.setCursor(0,1);
lcd.print(names[1]);
lcd.setCursor(0,2);
lcd.print(names[2]);
lcd.setCursor(0,3);
lcd.print(names[3]);
}
int index0 = 0;
int index1 = 1;
int index2 = 2;
int index3 = 3;
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
lcd.setCursor(0,0);
lcd.print(names[index0]);
lcd.setCursor(0,1);
lcd.print(names[index1]);
lcd.setCursor(0,2);
lcd.print(names[index2]);
lcd.setCursor(0,3);
lcd.print(names[index3]);
index0 = ++index0 % 4;
index1 = ++index1 % 4;
index2 = ++index2 % 4;
index3 = ++index3 % 4;
}
view raw lcd_test.ino hosted with ❤ by GitHub
The snippet below scrolls 4 rows vertically. Note the padding in the data to align and clear the previous value.

Of course the first time I uploaded this the backlight turned on but no characters were visible. This was because the contrast was set to its lowest value. After adjusting  this pot on the back of the LCD everything was perfectly visible.



No comments:

Post a Comment