Difference between revisions of "Arduino/C2/Arduino-with-LCD/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
Line 211: Line 211:
 
|-
 
|-
 
| style="border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| point to data pins
 
| style="border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| point to data pins
| style="border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| We are using only 4 data lines for our experiment.
+
| style="border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| We are using only 4 data lines for our experiment.
 +
Pin 15 and Pin 16 are connected for the backlight of the LCD.
 +
Connect Pin15 to VCC and pin16 to ground as shown here.
  
 
|-
 
|-

Latest revision as of 17:32, 27 February 2018

Title of script: Arduino with LCD

Author: Manivel and Nirmala Venkat

Keywords: Arduino UNO board, Arduino IDE, Compile and upload, LCD, Video tutorials


Visual Cue Narration
Slide 1: Welcome to the Spoken Tutorial on Interfacing Arduino with LCD.
Slide 2:

Learning objectives

In this tutorial, we will learn to:
  • Connect an LCD to Arduino board
  • Write a program to display a text message on the LCD
Slide 3:

Pre-requisites

To follow this tutorial, you should have:
  • Basic knowledge of Electronics and
  • Basic knowledge of C or C++ programming language
Slide 4:

System Requirement

Here I am using:
  • Arduino UNO Board
  • Ubuntu Linux 14.04 operating system
  • Arduino IDE
Slide 5(a):

External devices

We also require some external devices such as:
  • LCD 16 by 2
  • Potentiometer
  • Breadboard
  • Pin header
  • Jumper Wires
Slide 5(b);

External devices

* Soldering Iron
  • Soldering Stand
  • Soldering Lead
  • Soldering Paste
Now, let us see the details of the circuit connection.
Show Image of LCD Pins Here we see that there are 16 pins in the LCD.
Point to Pin 1 or GND and Pin 2 or VCC Pin 1 is the ground pin represented by GND.

Pin 2 is the power supply pin of 5 volts which is represented by VCC.

Point to Pin 3 (VO) VO is the LCD contrast pin. Here you have to connect a potentiometer.

This will allow a variable voltage to control the contrast of the LCD.

Point to Pin 4 – RS

Text to be displayed:

Pin (High) – writing data to the LCD

Pin(Low) – Instructions or Commands

RS stands for Register Select.

It can be used as a command register or a data register.

Command register is used for placing the command to be displayed.

And the data register is used to place the data.

Point to Pin 5 – RW

Text to be displayed:

Pin(High) – Read from LCD

Pin(Low) – Write to LCD

RW is a Read Write pin.

We can either read data from the LCD or write to the LCD.

Point to Pin 6 – Enable pin E represents the Enable pin. This enables LCD to accept information.
Point to Pin D0-D7 These are data pins.

The data and commands are sent to the LCD through these pins.

Point to LCD Backlight pins. These are LCD Backlight pins.

These are used to power the LCD, control the display contrast, turn on or off the LCD backlight etc.

Point to Pin 15-16

Text to be displayed:

Pin 15 - Anode of the back light LCD

Pin 16 - Cathode of the back light LED

Pin 15 is the Anode of the backlight LCD.

Pin 16 is the Cathode of the backlight LCD.

So far, we have seen the pin details of the LCD.
Let us switch to the soldering stations to see how we can do the soldering.
Here, we have:
  • 16 by 2 LCD
  • This means, it can display 16 characters per line and there are 2 such lines.
  • Extension pin which needs to be soldered to LCD so that we can connect easily to the breadboard
  • Soldering iron which is already powered
  • Solder paste
  • Solder wire
First, put the external pin on the LCD, as shown.
Next, apply the solder paste to the tip of the external pins, as shown in the video.
Then connect it again.

Place the LCD with the external pin firmly on the flat surface, as shown.

Then it will not shake while we do the soldering.

Take the solder rod with little paste and touch the tip of the wire, as shown.

Hold it for few seconds so that the wire melts and apply to the external pin, as shown.

I have done soldering for two pins. See the close up of the soldering done for the two pins.

Likewise, do the soldering for the rest of the pins.

Let us now switch to the circuit diagram for this experiment.
Potentiometer is connected as shown to control the contrast of the LCD.

Potentiometer is a small sized electronic component used to measure voltage.

Pin number 11 is connected to enable and pin number 12 is connected to register select.

Read write pin is connected to ground which means we are writing to the LCD.

point to data pins We are using only 4 data lines for our experiment.

Pin 15 and Pin 16 are connected for the backlight of the LCD. Connect Pin15 to VCC and pin16 to ground as shown here.

I have setup the Arduino and LCD, as per the circuit diagram.

Our aim is to write two strings on the LCD display.

Switch to Arduino IDE Now we will write the program in the Arduino IDE.

Switch to Arduino IDE.

First we will go through the reference manual for the Liquid crystal library.
Click Help >> reference In the Menu bar, click Help and then Reference.

This will open an offline page.

Click on Reference >> Libraries Under Reference section, click on Libraries.
Scroll down Then scroll down to see the available Standard Libraries.
Click on LiquidCrystal.

Highlight the instruction

Click on LiquidCrystal.

Read the description to know more about the available functions.

Highlight the manual and then show the circuit diagram It says, it works with 4 bit or 8 bit data lines.
Point to the manual Next, let us see the LiquidCrystal function and its parameters.
Click on LiquidCrystal function. It is always a good practice to refer to the manual for its functions.

Click on LiquidCrystal function.

Highlight the 8 bit and then the 4 bit The syntax shows how it is used for 8 bit or 4 bit.
Highlight the First line in the syntax heading For our experiment, we will use the first line syntax.
Switch to the Arduino IDE Switch to the Arduino IDE.
First we will include the Liquid crystal library here.
Click Sketch>>Include Library >> LiquidCrystal

Point to the inserted file

In the Menu bar, click Sketch and Include Library.

Then select LiquidCrystal.

This will insert the LiquidCrystal.h file, as shown.

Type LiquidCrystal lcd(12,11,5,4,3,2) Now, type the code as shown.

Let me explain the parameters.

Point to lcd variable lcd is a variable of type Liquid crystal.
Point to first parameter First parameter is Register Select.

Register Select is connected to pin 12 of Arduino board.

Point to second parameter Second parameter is Enable. It is connected to pin 11.
Point to next 4 parameters The next 4 parameters are data lines of LCD.
Highlight the source code d4, d5, d6 and d7 of LCD are connected to pins 5, 4, 3 and 2 of the Arduino board.
Highlight the source code We are initializing the library with pins.

This line of code can be outside the void setup function.

Type lcd.begin In the void setup function, we will write the initial setups required for the experiment.

There is a function called begin.

Switch back to the reference manual. Let us see the manual for the description and the parameters for this function.

Switch back to the reference manual.

Highlight the description and read it. The manual says-
  1. Initializes the interface to the LCD screen.
  2. Specifies the dimensions (width and height) of the display.
  3. Needs to be called before any other LCD library commands.
Highlight the parameters. Now, let us see the parameters.

lcd: A variable of type liquid crystal


cols: the number of columns that the display has.

We have 16 columns in our LCD.


rows: the number of rows that the display has.

We have 2 rows.

Switch back to Arduino IDE. Switch back to the Arduino IDE.
Type,

lcd.begin(16,2);

Now, type: lcd.begin open bracket 16 comma 2 close bracket semicolon.
Type,

lcd.setCursor(0,0);

Set Cursor command will position the cursor in the specified row and column in the LCD.

Zero comma zero means zeroth row and zeroth column.

There is another command called print which will print text on the LCD.
Show the print command in the manual. Let us refer the manual for the description and syntax.
Type,

lcd.print(“First row”);

Type: lcd.print and enter some text, say “First Row”.
Let me explain the program.
Highlight each line This program will print on a 16 by 2 configuration LCD.

Set the cursor to first position.

lcd.print will print the text “First row” in the LCD.

Click on compile and upload button on the toolbar Let us compile and upload the program.
Point to the output “First Row” We can see the output “First row” displayed on the first line.
Point to the second row There is nothing displayed on the second row.
Let us change the program to print on the second line also.
Copy and paste the above three lines. Copy and paste the code.
Remove the first line Remove the line “lcd.begin” as it is initialized at the starting of the program.
Change the setcursor code to 0 and 1 Change the setcursor command to 0th column and 1st row as shown.
Change the text to “second row” Change the print command text to “second row”
Click on compile and upload button on the toolbar Now let us compile and upload the program.
Point to the output in the second row The text is displayed in the second row as well.
Point to the void loop() We didn't use any code in the void loop.

But, still we need to keep the loop template.

This is because a loop function is required by the Arduino syntax.

Once the text is sent, it is there forever.
Change the program Let us change the cursor position to the 3rd column in the second line.
Compile and upload the program Again, compile and upload the program.
Point to the output Note the change in the column position in the second row.
Show the manual function list Switch back to our function list in the manual.
Point to the various functions in the manual We can see there are many more functions such as scrollDisplayRight, scrollDisplayLeft etc.


Explore these functions on your own.

This brings us to the end of this tutorial. Let us summarize.
Slide 10:

Summary

In this tutorial, we learnt to:
  • Connect an LCD to Arduino board
  • Write a program to display a text message on LCD
Slide 11:

Assignment

Do the following assignment.
  • Change the same program to display the text “Hello World” in the second row.
  • Place the cursor in the 4th column.
  • Compile and upload the program
  • Observe the text displayed in the LCD.
Slide 12:

About Spoken Tutorial project

The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

Slide 13:

Spoken Tutorial workshops

The Spoken Tutorial Project Team

  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact@spoken-tutorial.org
The Spoken Tutorial Project Team:
  • conducts workshops and
  • gives certificates.

For more details, please write to us.

Slide 14:

Forum for specific questions

Please post your timed queries in this forum.
Slide 15:

Acknowledgement

  • Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at
  • http://spoken-tutorial.org/NMEICT-Intro
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at

this link.

This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.  

Thanks for watching.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat