Project 6: Arduino print hello
In this aricle, I’ll explain how to connect LCD (Liquid Crystall Display) on an Arduino and all the different ways you can program it, print msg, scroll msg, make custom characters, blink msg, and position msg.
Before going to to print hello or any text on LCD (Liquid Crystall Display ) you must know a brief about i2c communication .
I2C LCD comes handy making use of only 2 pins (SDA & SCL) and this will help you to reduce number of wires in our circuit
SCL is the clock signal
SDA is the data signal.
Hardware Required
1 | × | Arduino UNO or Genuino UNO | ||||||||||||||||||||||||||||||||||||||||||
1 | × | USB 2.0 cable type A/B | ||||||||||||||||||||||||||||||||||||||||||
1 | × | LCD | ||||||||||||||||||||||||||||||||||||||||||
n | × | Jumper Wires and BreadBoard |
CONNECTION PART
This sketch prints "Egerton, University!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
/* LCD 16x2 Arduino Tutorial
* Dev: ORENGO DICKSON
Date: 19/10/2020 */
// include the library code:
#include <Wire.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("EGERTON");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print("STUDYROOM APP");
}
Code
Download library here
Code Information
2. The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20x4).
The display I’m using is a 16×2 LCD means 16×2 that the LCD has 2 row or line, and can display 16 characters per row. Therefore, 16×2 LCD screen can display up to 32 characters at once.
3. lcd.setCursor(0,0); Defining positon to write from first row,first (row, column,).
Other Examples
lcd.createChar()
Used for customization , the syntax allows you to create your own custom characters. Each character of a 16×2 LCD has a 5 pixel width and an 8 pixel height. Up to 8 different custom characters can be defined in a single program.
To design characters, you’ll need to make a binary matrix of your custom character from an LCD character generator or map it yourself.
The code below will create power 2
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte customChar[8] = {
0b00110,
0b01001,
0b01001,
0b00110,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup() {
lcd.createChar(2, customChar);
lcd.begin(16, 2);
lcd.write((uint8_t)2);
}
void loop() {
}
The code below will animate characters
#include <LiquidCrystal.h>
// initialize the library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte heart[8] = { // 1
0b00000,
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
byte smiley[8] = { // 2
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};
byte frownie[8] = { // 3
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};
byte armsDown[8] = { // 4
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};
byte armsUp[8] = { // 5
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};
void setup()
{
lcd.createChar(1, heart);
lcd.createChar(2, smiley);
lcd.createChar(3, frownie);
lcd.createChar(4, armsDown);
lcd.createChar(5, armsUp);
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.write(1);
lcd.print(" EGERTON");
lcd.write(2);
lcd.setCursor(4, 1);
lcd.print( " UNIVERSITY ");
delay(5000);
}
void loop()
{
delay(500);
lcd.clear();
lcd.setCursor(4, 1);
lcd.write(5);
lcd.setCursor(13, 0);
lcd.write(3);
delay(500);
lcd.clear();
lcd.setCursor(4, 1);
lcd.write(4);
lcd.setCursor(13, 0);
lcd.write(2);
}
Comments
Post a Comment