Using Arduino I2C LCD Screen
Using Arduino I2C LCD Screen
From time to time, I write articles about Arduino and explain things like how to combine different parts. Now, while tinkering with the I2C LCD screen I got the other day, I thought I'd share this as well—both to provide content and to help anyone who's curious—so I'm writing this post.
This is the LCD screen I have and there are 4 pins on the back: GNC, VCC, SDA, and SCL pins.
If we talk about the connection of these pins, since I don't use the default Arduino library and not all Arduinos have SDA and SCL pins, I will explain using the Analog In input pins.
Connect the GND on the screen to the GND Pin on the Arduino,
Connect the VCC on the screen to the 5V Pin on the Arduino,
Connect the SDA on the screen to Analog 4 on the Arduino,
Connect the SCL on the screen to Analog 5 on the Arduino,
that will be enough.
Moving on to the code, first click here and download the library we are going to use.
To install the library you downloaded to Arduino, go to Sketch > Add Library > Add ZIP and select the file you downloaded to add it.
Library features
- I2C LCD Control Features
- init() //Initializes the LCD.
- clear() //Clears the LCD screen
- home() //Moves the cursor to position 0.
- setCursor() //Sets the cursor position
- cursor() //Enables the underlined cursor
- noCursor() //Disables the underline cursor
- blink() //Enables the blinking cursor
- noBlink() //Disables the blinking cursor
- display() //Turns on the display
- noDisplay() //Turns off the display
- backlight() //Turns on the backlight
- noBacklight() //Turns off the backlight
- scrollDisplayLeft() //Scrolls to the left
- scrollDisplayRight() //Scrolls to the right
If you want to display regular text, here's a sample code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
lcd.init();
lcd.backlight();
lcd.print("UrhobA");
lcd.setCursor(0,1);
lcd.print("www.urhoba.net");
}
void loop()
{
}If you are looking for a sample code to display scrolling text.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
lcd.init();
lcd.backlight();
lcd.print("UrhobA");
lcd.setCursor(0,1);
lcd.print("www.urhoba.net");
}
void loop()
{
lcd.scrollDisplayRight();
delay(500);
}



Yorum Gönder