School of the Future Name: Mr. Z / Physics II Date:

Arduino Exploration #20: Displaying Text with LCDs

CHALLENGE: Figure out how to display messages on an LCD.

LCDs (“Liquid Crystal Displays”) are devices that can be used to display text. They come in many different sizes, shapes, and colors. Some even come with speakers built onto the board! They are made by many different companies, so their structure varies widely.

Resources for LCDs

1. LCD Display Blue 1602 IIC I2C from YourDuino.com (this is the one we have in class) a. http://yourduino.com/sunshop2/index.php? l=product_detail&p=170 b. Be sure to look through the tutorial under the “Additional Resources” section at the bottom of this page. 2. LCD-Blue-I2C Tutorial by ArduinoInfo.Info a. http://arduino-info.wikispaces.com/LCD-Blue-I2C b. See LCD Version 1 3. New LiquidCrystal Library from Malpartida a. https://bitbucket.org/fmalpartida/new- liquidcrystal/downloads b. This library needs to be downloaded and installed. It will make working with the LCD very easy for the ones we’re using. 4. LiquidCrystal Library from Arduino.cc a. https://www.arduino.cc/en/Reference/LiquidCrystal b. This is the original Arduino library for using LCDs. It won’t work with our particular LCD, but the functions in this library are identical to the ones in the New LiquidCrystal library we’ll be using. 5. Google “Arduino LCD 1602 I2C”

Arduino Exploration #20: Displaying Text with LCDs

CHALLENGE: Figure out how to display messages on an LCD.

SETUP:

NOTE: The only connections you are actually making are to the four pins coming off the LCM1602 module, which is mounted on the back of the LCD.

CODE: //Get necessary libraries #include #include

// Set the LCD I2C address LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {

//Tell the Arduino the size of your LCD (text spaces, rows) lcd.begin(16,2);

//Flash the backlight to let the user know you're getting started lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); lcd.backlight();

//Set a blinking cursor (totally optional) lcd.blink();

//Set the "cursor" to the first space (that's where text will appear) lcd.setCursor(0,0);

//Write a message. You can use write() or print() here. lcd.write("Hey Friend!");

//Set the cursor to the next line and write a message. lcd.setCursor(0,1); lcd.write("How are you doing today?"); delay(1000);

//Scroll the text to the left so you can read the whole message. for (int i = 0; i < 8; i++){ lcd.scrollDisplayLeft(); delay(400); } delay(1000); //Clear the display and print a new message. lcd.clear(); lcd.print("Good to hear!");

}

void loop() { // put your main code here, to run repeatedly:

}