Starting from:

$30

CS341-Lab 5 Solved

In this lab, you will learn about interfacing I/O devices to the Arduino computer. In particular, you will program them to display text and time to a Liquid Crystal Display (LCD)  and play tones on the piezoelectric speaker. The starter code can be found on GitHub under Lab 5.

 

 

Some Background Info
You can display 2 lines (16 characters per line) of text using the LCD Display in the Arduino library. It has a parallel interface that allows the computer to manipulate in order to display the desired characters. In addition to showing alphanumeric characters, the Arduino can also control the display contrast, and turn on and off the LED backlight. You can find a good description of the functions of the LCD interface pins, diagrams on how to connecting them and programming snippets here.  

A piezoelectric speaker (buzzer) is made out of a certain crystal. It generates sounds when electricity is applied to it. These speakers are cheap and they are commonly used in alarm devices, computers and timers. They produce tone frequency ranging from 20 - 20,000 Hz. As a reference, human speech signals are around 3,000 – 4,000 Hz and music instruments (e.g. violins) can generate notes as high as 16,000 Hz (https://gomixing.com/sound-theory/musicequalizer-how-to-use-audio-equalizers-and-everything-else-about-equalization-in-music/). You can find a description on how to hook up the speaker and programming snippets here.

 

 

Program the LCD display and Piezo Speaker
To begin the lab, connect the LCD display and piezoelectric speaker to Arduino computer using the provided bread board as shown in the diagram. Specifically, you will be connecting the following Arduino interface pins:

Arduino Digital pin                                       LCD or Speaker Function 

    2,3,4,5                                             (D7,D6,D5,D4) control what character to display

11                                                                                       (E) enable writing to the registers

12                                                                                       (R/S) select writing to either the Data register or the

          Control Register     8                                          control the speaker

 

 

 

 

Use the provided starter code to verify the correctness of your circuit connection. When the program is running, you should see the first 16 characters of the string “Welcome CS341 Students! ” displayed on line 1 and the time elapsed in seconds displayed at the middle of line 2. You should also hear an intermittent tone of 1500 Hz. The LCD’s display contrast pin (V0) is connected to the wiper of a 10K potentiometer (variable resistor). You can change the contrast of the display by moving the center dial of the potentiometer. The leftmost position setting results in the highest contrast.

For this lab, you are asked to write a program to show a ticker tape display of the string p[ ] using the LCD display:

                        char p[ ]= “Welcome CS341 Students! ”; 

When the program is running, the string p[ ] will appear to scroll along the LCD display. To achieve this effect, your program has to:

1)     Display a different section of the string at a time in a circular fashion (Remember the tail program in CS240). Initially, you show:

 

“Welcome CS341 Students! ”  Then you show: 

“elcome CS341 Students! W”.  Then you show: 

“lcome CS341 Students! We”   and so on. 

2)     Since the LCD can only display 16 (DISPLAY_LEN) characters at a time and the length of the string is 24, the best way is to save the appropriate 16 characters from the string p[] into a temporary buffer for display and then output it using:

 

                        char buffer[DISPLAY_LEN + 1]; 

                        load 16 bytes of p[] in a circular fashion into buffer[]  

                                       lcd.setCursor(0, LINE_1);  

lcd.print(buffer); 

You can write some code in the loop function if you want to experiment with that capability.  If you do, it would be a good idea to include one or more delay() calls in the loop function so that you have time to see or hear the results of each pass before the next pass is made.

More products