logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

DIY Guide to Setting Up an LCD with Arduino

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at February 20, 2018
Categories
  • Arduino
Tags
  • Arduino
  • arduino diy
  • arduino lcd
  • lcd
Arduino_LCD

Driving an LCD Screen with an Arduino

Purpose

This tutorial describes how to use an Arduino to drive an LCD screen.

Overview

Arduinos are popular microcontroller boards and a common desired functionality is to use them to drive LCD screens, usually to relay information to the user. In this tutorial, I will teach you how to use the Adafruit I2C/SPI LCD Backpack with an Arduino microcontroller board to drive a LCD.

Equipment

  1. Arduino Uno R3 – https://www.adafruit.com/product/50
  2. I2C/SPI LCD Backpack – https://www.adafruit.com/product/292
  3. RGB LCD 20×4 – https://www.adafruit.com/product/499
  4. 9V, 1A Power Adapter – https://www.adafruit.com/product/63
  5. Jumper Wires – https://www.amazon.com/GenBasic-Female-Solderless-Breadboard-Prototyping/dp/B01MS9GY7W/ref=sr_1_1_sspa?s=electronics&ie=UTF8&qid=1515705634&sr=1-1-spons&keywords=jumper+wires&psc=1
  6. USB Cable (A-to-B) – https://www.amazon.com/AmazonBasics-USB-2-0-Cable-Male/dp/B00NH11KIK
  7. Breadboard – https://www.amazon.com/Elegoo-Breadboard-Solderless-Distribution-Connecting/dp/B01EV6LJ7G/ref=sr_1_1_sspa?s=electronics&ie=UTF8&qid=1515705714&sr=1-1-spons&keywords=breadboard&psc=1

Table of Contents

  1. Wiring the Circuit
  2. Writing the Code
    1. Configuration
    2. Setup
    3. Loop
  3. Uploading and Running the Code

Procedure

1. Wiring the Circuit

LCDs require many connections to a driver to work. Managing all these connections all the time can become both cumbersome and annoying. Luckily, Adafruit has made an I2C/SPI LCD Backpack that works with most LCDs. This backpack conveniently reduces the number of connections between your microcontroller and the LCD to 4.

I always like to make a wiring diagram (Figure 1: Arduino-LCD Schematic) using Fritzing, an open-sources schematic capture and PCB routing software. You can download Fritzing using the following link (optional): http://fritzing.org/home/

Figure 1: Arduino-LCD Schematic

Pin 1 on the LCD goes to Pin 1 on the LCD Backpack. The rest of the pins are wired sequentially. This can be done on a breadboard or the backpack can be soldered to LCD as I have done.

I2C and SPI are two very popular serial interface buses. This tutorial covers interfacing your Arduino to the LCD Backpack using I2C, but the LCD Backpack can interface with SPI too. You can set the I2C address (A0, A1, A2) or enable SPI (SPI Enable) by jumpering the solder jumpers on the backpack (Figure 2: Solder Jumpers on LCD Backpack). The only circuit using I2C in the tutorial is the LCD Backpack, so we do not need to change the current configurations. This means the LCD Backpack will have an I2C address of 0 (0x00).

Figure 2: Solder Jumpers on LCD Backpack

To interface the LCD Backpack to the Arduino, connect 5V and a ground pin on the Arduino to the 5V and ground pin on the LCD Backpack. This will provide the LCD and LCD Backpack with power. Note: The LCD requires 5V minimum to work properly. The next two connections are serial data and serial clock. The serial clock connection (orange wire) is between the SCL pin on the Arduino and the CLK pin on the backpack. The serial data connection (blue wire) is between the SDA pin on the Arduino and the DAT pin on the backpack.

Figure 3: LCD Backpack Pinout

2. Writing the Code

2.1 Configuration

The first part of the code is to include the Adafruit_LiquidCrystal header file. This allows you to use the functions in this library. Because the Adafruit_LiquidCrystal library is automatically downloaded with Arduino IDE, this tutorial doesn’t cover downloading Arduino libraries.

Next, we set our LCD Backpack address to 0 (remember, we have not jumpered any of the solder jumpers).

Finally, I make one global variable called timer that I will use in the loop section later.

2.2 Setup

Before writing to the LCD, it needs to be initialized. The “begin” function does this by telling the LCD Backpack how many characters are on the display. Since the LCD I am using has a backlight, I also turn the backlight on.

Now that the LCD is initialized, I write “Test Code” to check that everything is working. This code sets the cursor to a starting position, writes “Test” to the display, waits 2 seconds, and then clears the display.

Figure 4: Setup Code

2.3 Loop

The loop part of the code uses the millis() function and divides by 1000 to compute how long the program has been running. The code then uses the print and setCursor functions to display the program time across the LCD. The loop then waits a second before repeating.

Figure 5: Loop Code

3. Uploading and Running the Code

Upload the code to the Arduino. Make sure the Arduino is connected using the 9V Power Adapter because power over USB is not sufficient to power both the Arduino and the LCD display. Once the program begins you should see “Test” across the LCD display as the program runs through setup (Figure 2: LCD Displaying “Test”). When the program loop begins you will see the time program displayed and updating every second (Figure 3: LCD Display Program Runtime – 8(s)). Congrats! You now have an easy-to-use LCD screen for your Arduino board and can use it as a display for future projects. A tip to keep in mind: I2C is a slow bus and if you are constantly updating your LCD you will take time away from the controller performing other tasks.

Figure 6: LCD Displaying “Test”

Figure 7: LCD Display Program Runtime – 8(s)

Figure 8: LCD Displaying Program Runtime – 28(s)

Appendix: Arduino_LED Code in Text

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*       Project: Arduino LCD
*       Written by: Chris Marella                            
*       Date: January 11, 2018                                                                    
*/                                                        
 
// include the Adafruit LCD Library:
#include
 
// Connect the the LCD Backpack via I2C, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);
 
//Global Variables
int timer;    //create a global variable for a timer
 
void setup() {
 
  //LCD Configuration
  lcd.begin(19,3);        //The begin function tells the LCD driver the size of your LCD screen (columns x rows)
  lcd.setBacklight(HIGH); //setBacklight controls the LCD backlight
 
  //Test Code
  lcd.setCursor(0,0);     //setCursor function sets the position of the character cursor (column x row)
  lcd.print("Test");      //Prints "Test" across the LCD
  delay(2000);            //Wait for 2 seconds
  lcd.clear();            //clear function clears the LCD screen
 
}
 
void loop() {
  timer = millis()/1000;  //set timer variable to how long program has been running in seconds
 
  lcd.setCursor(0,0);     //set LCD cursor to 0,0
  lcd.print("Time:");     //print time on LCD row 1
  lcd.setCursor(0,1);     //move LCD cursor to row 2
  lcd.print(timer);       //print the current program run time
  lcd.setCursor(0,2);     //move LCD cursor to row 3
  lcd.print("(s)");       //print "(s)" for seconds
  delay(1000);            //wait 1 second to update
}

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • How To MacGyver A Laser Tripwire Using ArduinoHow To MacGyver A Laser Tripwire Using Arduino
  • ESP-WROOM-02 Wifi Setup Guide – AT CommandsESP-WROOM-02 Wifi Setup Guide – AT Commands
  • Make a Smart Automatic Pet Feeder with Arduino UnoMake a Smart Automatic Pet Feeder with Arduino Uno
  • DIY RepRap 3D Printer for Beginners – Part 2: WireDIY RepRap 3D Printer for Beginners – Part 2: Wire
  • Using ESP-WROOM-02 Wifi Module As Arduino MCUUsing ESP-WROOM-02 Wifi Module As Arduino MCU
  • Smart Pet Feeder Part 2 – Feeding App with Speech RecognitionSmart Pet Feeder Part 2 – Feeding App with Speech Recognition
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort