0% found this document useful (0 votes)
11 views6 pages

Lab 5 LCD Screen and Joystick Basics

Lab 5 introduces students to interfacing an LCD screen and joystick with an Arduino, structured into three exercises focusing on LCD display, joystick control, and a combination of both. Students are required to follow specific programming guidelines, utilize provided libraries, and submit Arduino sketches along with demonstration videos. The lab emphasizes hands-on experience and understanding of embedded systems programming.

Uploaded by

ryann82553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Lab 5 LCD Screen and Joystick Basics

Lab 5 introduces students to interfacing an LCD screen and joystick with an Arduino, structured into three exercises focusing on LCD display, joystick control, and a combination of both. Students are required to follow specific programming guidelines, utilize provided libraries, and submit Arduino sketches along with demonstration videos. The lab emphasizes hands-on experience and understanding of embedded systems programming.

Uploaded by

ryann82553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab 5 - LCD Screen and Joystick Basics

In Lab 5, students are introduced to the basics of interfacing an LCD screen and a joystick with
an Arduino microcontroller. This lab is structured to provide hands-on experience with these
components, enhancing the students' understanding and skills in embedded systems
programming. The lab is divided into three main exercises, each focusing on different aspects of
LCD and joystick interfacing.

Wiring diagram for the first exercise is available in this document. We will help you out during
the Office hours and Slack if you face any issues with the wiring of course. Launch the Arduino
IDE and create a new sketch. Ensure your Arduino is selected using the "Select Board" option
at the top left of the IDE.

For all of the exercises, please follow the instructions provided on Zybooks and make use of the
Timer.h library available in Google Drive. You are allowed to use RIBS (alpha) to generate the C
code and then modify it for Arduino.

For all of the exercises please follow the instructions provided on Zybooks section 2.4 from
Week 2 about programming State Machines in C. You are allowed to use RIBS (alpha) to
generate the C code and then modify it for Arduino. Please do not use delay() as you will be
penalized for it.

1. Software Requirement
a. Arduino IDE
b. Note: Mild bouncing is ok so long as the LED maintains state when you are not
pressing the button. You can also increase the period to remove any bouncing
effects.
c. Using the timer.h header file with Arduino Sketch:
i. Open Arduino IDE.
ii. Go to File > New to create a new sketch.
iii. Save the sketch with a relevant name.
iv. Click on the three dots on the top right corner of the IDE and choose
"New Tab".
v. A dialog box will appear, asking for the name of the new file. Type
Timer.h and click OK.
vi. Copy and paste the provided Timer.h code into this new tab.
d. Another way to use the timer.h header file:
i. Save your ino sketch on your computer and then copy the timer.h header
file to the same location as that of your sketch.
e. Don’t forget to user #include <LiquidCrystal.h>
2. Parts while working with LCD display
a. Key components from previous labs
b. LEDs
c. Joystick
d. LCD Screen
e. Male-to-Female Dupont Wires (for joystick)

LCD (Liquid Crystal Display)


The LCD used in these exercises is controlled via the Arduino library LiquidCrystal.h. This
library provides functions to interact with character LCDs.

Initialization
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

This line of code creates an LCD object named lcd. The numbers inside the parentheses are
the Arduino pin numbers connected to the LCD's RS, EN, D4, D5, D6, and D7 pins,
respectively.

● RS (Register Select): Controls where in the LCD's memory you're writing data to. You
can select either the data register, which holds what goes on the screen, or an
instruction register, which is where the LCD's controller looks for instructions on what to
do next.
● EN (Enable): Used to enable the writing to the registers.
● D4 to D7: These are the data pins used for sending data.

Functions and Their Arguments

● lcd.begin(cols, rows): Initializes the interface to the LCD screen, and specifies
the dimensions (width and height) of the display. For a 16x2 LCD, you'd call
lcd.begin(16, 2).
● lcd.print(data): Prints data to the LCD. data can be a string, a number, or other
types of data.
● lcd.setCursor(col, row): Sets the cursor to a specific location on the LCD screen.
col and row are the column and row indices, respectively.
● lcd.clear(): Clears all the content on the LCD screen.

Joystick
The joystick module typically has five pins: VCC, GND, VRx, VRy, and SW.

● VCC: Connects to power.


● GND: Connects to ground.
● VRx: Outputs an analog voltage proportional to the X position.
● VRy: Outputs an analog voltage proportional to the Y position.
● SW: The state of the push button on the joystick. It is usually connected to a digital pin on
the Arduino.

Reading Joystick Values

You can read the X and Y positions of the joystick using the analogRead() function. The
values read from VRx and VRy will range from 0 to 1023.

int xValue = analogRead(A0); // Assume VRx is connected to A0

int yValue = analogRead(A1); // Assume VRy is connected to A1

Reading Button State

You can read the button state of the joystick using the digitalRead() function.

int buttonState = digitalRead(2); // Assume SW is connected to digital


pin 2

Functions and Their Arguments

● analogRead(pin): Reads the value from the specified analog pin. The argument pin
is the number of the analog input pin to read (from 0 to 5 on most Arduino boards).
● digitalRead(pin): Reads the value from a specified digital pin, either HIGH or LOW.
The argument pin is the number of the digital pin you want to read.

By understanding these details, you should be able to effectively program the Arduino to interact
with the LCD and joystick in the exercises provided.
Exercise Descriptions
Exercise 1: My First LCD

Objective: Learn to display text on an LCD screen using Arduino.

Components Used:
● LCD Screen
● Arduino Board

Procedure:
1. Initialize the LCD screen with the correct pin numbers and dimensions.
2. Clear the LCD screen.
3. Prompt the user to enter a short text string via the Serial Monitor.
4. Display the first string on the top row of the LCD screen.
5. Prompt the user to enter a short text string via the Serial Monitor.
6. Set the cursor to the beginning of the second row.
7. Display the second string on the second row of the LCD screen.
8. Ensure that both strings include at least 3 unique special characters.

Exercise 2: My First Joystick


Objective: Learn to control LEDs using a joystick.
Components Used:
● LEDs
● Joystick
● Arduino Board

Procedure:
1. Connect five LEDs to the Arduino and initialize them.
2. Connect the joystick to the Arduino, ensuring to connect the X-axis, Y-axis, and
button pins.
3. In the main loop, continuously read the joystick's position and button state.
4. Use the joystick's X-axis position to determine which LED should be lit.
5. Use the joystick's button state to toggle the current LED on or off.
6. Implement logic to handle edge cases, such as when the joystick is moved to the
extreme left or right:
a. If the joystick is moved to the extreme left, ensure that the first LED is lit
and all others are off.
b. If the joystick is moved to the extreme right, ensure that the last LED is lit
and all others are off.

Exercise 3: Joystick + LCD Combo


Objective: Combine the use of the joystick and LCD screen to create an interactive
application.
Components Used:
● LCD Screen
● Joystick
● Arduino Board
Procedure:
1. Initialize both the LCD screen and the joystick.
2. Use the joystick to move a cursor on the LCD screen.
3. Pressing the joystick button should print a character at the current cursor
position.
4. Implement logic to handle the LCD screen's boundaries. Ensure the cursor wraps
around to the beginning of the line if it reaches the end of the line (column 15).
5. If more than 5 characters are present on the screen, clear it and reset the cursor
to the top left corner.

Submission Requirements
● Submit three separate Arduino sketch files (.ino), one for each exercise.
● Submit a PDF document containing links to three YouTube videos, each demonstrating
one of the exercises.
● Ensure all code is well-commented and follows good programming practices.

Tips for Success


● Start early and allocate enough time to understand how the components work.
● Use the Arduino reference documentation to understand the functions and methods
used.
● Test each part of your code incrementally to ensure it works before moving on to the next
part.
● Seek help if you are stuck, and make use of office hours and discussion forums.

You might also like