This week we are introduced to LCD (Liquid crystal display) screen.
Connecting the LCD screen on to the arduino board:
- Black (LCD Screen) – Gnd > Gnd (Arduino board)
- Red (LCD Screen) – +5V > Vcc (Arduino board)
- Blue (LCD Screen) – SDA > A4 (Arduino board)
- Yellow (LCD Screen) – SCL > A5 (Arduino board)
The Contrast on the LCD screen has to be adjust this is simply done using a blue trimming tool that was provided to us, and rotating a dial which is located at the back of the screen.
Code for LCD Screen:
[code]
#include <Wire.h> // Comes with Arduino IDE
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <LiquidCrystal_I2C.h>
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup()
{
Serial.begin(9600); // Used to type in characters
lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines, turn on backlight
//——– Write characters on the display ——————
// NOTE: Cursor Position: Lines and Characters start at 0
// lcd.setCursor(Horizontal position,Line)
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print(“yo”);
lcd.setCursor(0,1); //Next start at character 0 on line 1
lcd.print(“hi”);
delay(1000);
lcd.setCursor(0,2); // This start at charater 0 line 2
lcd.print(“there”);
delay(1000);
}
void loop() // it will run the code constently
{
{
// when characters arrive over the serial port…
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
}
[/code]
Here is the Outcome:
Overall I found that the set up for this task to be much easier to do compared to stepper motor which has multiple components that has to connect in a specific way in order for it to work. Compared to this you only have to place 4 pins on the LCD screen to 4 specific location on the arduino board. In terms of coding it was relatively easy to understand as I only have to replace/ edit certain areas to an existing code.
Leave a Reply