principles of embedded system lab manual
TRANSCRIPT
-
7/24/2019 Principles of Embedded System Lab Manual
1/93
1
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES
PRINCIPLE OF EMBEDDED SYSTEM
LABORATORY ACTIVITY MANUAL
By:
Engr. Ronnie M. Dysangco
Engr. Maria Cecilia A. Venal
-
7/24/2019 Principles of Embedded System Lab Manual
2/93
2
Table of Contents
INTRODUCTION .................................................................................................................................3
ACTIVITIES .........................................................................................................................................5
Activity No. 1 .........................................................................................................................6
SERIAL MONITOR DISPLAY .........................................................................................6
Activity No. 2 ....................................................................................................................... 10
LIGHT EMITTING DIODE (LED) DISPLAY ..................................................................... 10
Activity No. 3 ....................................................................................................................... 15
RGB (LED) DISPLAY ................................................................................................... 15
Activity No. 4 ....................................................................................................................... 21
LED LIGHTS, SHIFT REGISTER AND SERIAL MONITOR ................................................. 21
Activity No. 5 ....................................................................................................................... 30
DIGITAL INPUTS ....................................................................................................... 30
Activity No. 6 ....................................................................................................................... 34
RGB LED FADER ........................................................................................................ 34
Activity No. 7 ....................................................................................................................... 39
ANALOG INPUTS ...................................................................................................... 39
Activity No. 8 ....................................................................................................................... 44
SENSOR AND SOUNDS .............................................................................................. 44
Activity No. 9 ....................................................................................................................... 50
LCD DISPLAY ............................................................................................................ 50
Activity No. 10 ..................................................................................................................... 56
MOTORS .................................................................................................................. 56
Appendix ......................................................................................................................................... 70
-
7/24/2019 Principles of Embedded System Lab Manual
3/93
3
INTRODUCTION
Embedded System
It is housed on a single microprocessorboard with theprograms stored inROM.Virtually all appliances thathave adigital interface -- watches, microwaves, VCRs, cars -- utilize embedded systems. Some embedded
systems include anoperating system,but many are specialized where the entire logic can be implemented
as a single program.
Breadboard
Breadboard is a way of constructing electronics without having to use a soldering iron. Components are
pushed into the sockets on the breadboard and then extra 'jumper' wires are used to make connections.
The middle section of the board has two columns, each with 30 strips of connector, like the one pulled out
and to the side of the breadboard. These connect together anything that is pushed through from the frontinto one of those five holes.
On either edge of the board are much longer sections of clip that join together the columns of holes marked
by the blue and red lines on the front of the breadboard. These are generally used for GND (blue) and 5V
(red).
Getting Started
Figure A. Device Detection
http://www.webopedia.com/TERM/B/board.htmlhttp://www.webopedia.com/TERM/P/program.htmlhttp://www.webopedia.com/TERM/R/ROM.htmlhttp://www.webopedia.com/TERM/D/digital.htmlhttp://www.webopedia.com/TERM/O/operating_system.htmlhttp://www.webopedia.com/TERM/O/operating_system.htmlhttp://www.webopedia.com/TERM/D/digital.htmlhttp://www.webopedia.com/TERM/R/ROM.htmlhttp://www.webopedia.com/TERM/P/program.htmlhttp://www.webopedia.com/TERM/B/board.html -
7/24/2019 Principles of Embedded System Lab Manual
4/93
4
Figure B. Update Driver Software
-
7/24/2019 Principles of Embedded System Lab Manual
5/93
5
ACTIVITIES
-
7/24/2019 Principles of Embedded System Lab Manual
6/93
6
Activity No. 1
SERIAL MONITOR DISPLAY
Course Code: CPE 131 Program:
Course Title: Principle of Embedded System Date Performed:Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software. This activityalso provides students with knowledge and skills on how to develop a program using the Arduinoprogramming software.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a program that displays a string output and some mathematical operation.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Serial Library is used to communicate from the Arduino/Gizduino board back to the computer over theUSB port. Serial data transfer sequence is through one bit data transfer at a time, in which theinformation is passed back & forth between the computer and Arduino/ Gizduino board by, essentially,setting the pin into a high or low status. Just like using the LED lights as an indicator for the output. The
connection of the Arduino/Gizduino board as shown in Figure 1-1 emphasizes the data transfer physicalprocedure from the software going to the Arduino/Gizduino board.
Figure 1-1 Hardware Connection
-
7/24/2019 Principles of Embedded System Lab Manual
7/93
7
Creating a program file with Arduino/Gizduino board is the same as the C language source code.
Reference:http://www.ladyada.net/learn/arduino/lesson4.html
4. Materials and Equipment:
1.
Arduino/Gizduino board2. Computer3. USB Cable4. Power Source
5. Procedure:
1. Open installed Arduino IDE.2. Select board and serial port in the action bar.3. Create a new sketch.4. Copy the source code in Figure 1-2.
Figure 1-2 String sample source code5. Compile the program.6. Save the program as Activity 1-1.7. Simulate the program.8. Write the output at the data and results.
http://www.ladyada.net/learn/arduino/lesson4.htmlhttp://www.ladyada.net/learn/arduino/lesson4.htmlhttp://www.ladyada.net/learn/arduino/lesson4.htmlhttp://www.ladyada.net/learn/arduino/lesson4.html -
7/24/2019 Principles of Embedded System Lab Manual
8/93
8
9. Create a new sketch.10.Copy the source code below.
/* * Math is fun! * */
int a = 5;int b = 10;
int c = 20;
void setup() // run once, when the
sketch starts
{
Serial.begin(9600); // set up Serial library
at 9600 bps
Serial.println("Mathematical Operation: ");
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.print("c = ");
Serial.println(c);
Serial.print("a + b = "); // add
Serial.println(a + b);
Serial.print("a * c = "); // multiply
Serial.println(a * c);
Serial.print("c / b = "); // divide
Serial.println(c / b);
Serial.print("b - c = "); // subtract
Serial.println(b - c);
}
void loop() // we need this to be
here even though its empty
{}
11.Compile the program.12.Save the file as Activity 1-2.13.Simulate the program.14.Write the output at the data and results.
-
7/24/2019 Principles of Embedded System Lab Manual
9/93
9
6. Data and Results:
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
10/93
10
Activity No. 2
LIGHT EMITTING DIODE (LED) DISPLAY
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan LED output. This activity also provides students knowledge and skills on how to develop a circuitusing different resistor in controlling the LED using the Arduino programming software.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display a different LED.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Light Emitting Diode
LEDs are one of the good electronic outputs that make a great light indicator output. It is an electronic
device that uses a very little electricity. The most common of all LEDs a 5mm red LED refers to thediameter of the LED. Other common sizes are 3mm and the large fun 10mm LEDs. This electronicdevice cannot be connected directly to a battery or any voltage source because of it s voltage necessity.The polarity of each leg needs to be attached to a resistor to limit or choke the amount of currentflowing to avoid the burn out probability.
Resistors
It is an electronic component that resists the electricity flow, in which the higher the value of the resistor,the more it can resist the electrical charge and produce less electrical current within the circuitry. Todetermine the amount of resistance of each resistor, Figure 2-1 shows the proper way on reading the
resistor color coding values.
Blink Source Code
Blinking is one of the methods in controlling the LED light output of the Arduino/Gizduino board. It is alsothe basic programming technique on how to manipulate and embedded a program on the said board.Figure 2-2 shows the source code in creating a blinking program.
-
7/24/2019 Principles of Embedded System Lab Manual
11/93
11
Figure 2-1 Resistor Color Coding
Figure 2-2 Blink Program
-
7/24/2019 Principles of Embedded System Lab Manual
12/93
12
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable
4.
Power Source5. Bread board6. LED7. Resistors (470, 2.2K, and 10K)8. 74HC595 Shift Register9. Connecting wires
5. Procedure:
1. Open Sketch software.2. Choose example at file menu.3. Select basic then blink.
4.
Write the source code at the data and results.5. Save the file as Activity 2-A.6. Attach the Arduino or Gizduino Board with the USB cable.7. Click the upload button.8. Simulate the program.9. Write the binary sketch size and error message at data and results.10.Change and write the observation as the delay values change using Table 2-1.11.Create a connection as shown in Figure 2-3.
Figure 2-3 Bread board interface
12.
Write the output at Table 2-2.13.Create a connection as shown in Figure 2-4.
-
7/24/2019 Principles of Embedded System Lab Manual
13/93
13
Binary Sketch size:
Error Message
Figure 2-4 Blinking Connection
14.Modify the int led values as using the data in Table 2-3.15.Simulate the program.16.Fill-out Table 2-3.
6. Data and Results:
Source Code (Procedure 4)
-
7/24/2019 Principles of Embedded System Lab Manual
14/93
14
Table 2-1 Delay
Delay Values Observation
1. 100
2. 3003. 500
4. 700
5. 900
Table 2-2 LED Output
ResistorValue
Output
1. 470
2. 2.2K
3. 10K
Table 2-3 Blinking Output
int led Value Observation
1. 13
2. 7
3. 10
4. 100
5. 30
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
15/93
15
Activity No. 3
RGB (LED) DISPLAY
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan RGB LED output. This activity also provides students with knowledge and skills on how to develop acircuit using RGB LED controlled by C programming.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display a RGB LED output.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
RGB LEDs
It is a type of LED that contains different color combination such as Red, Green and Blue inside a single
LED bulb. A common anode RGB LED is nothing more complicated than three one colour LEDs (onered, one green, and one blue) housed in a single package. Rather than having 6 leads (a cathode andanode for each LED) it has only 4 one cathode for each colour, and one common anode. (see theschematic diagram below) A common anode RGB LED is the most popular type. It is commonly found ineither a 5mm bulb size or as a 5mm pirahna form factor as shown in Figure 3-1.
Figure 3-1 RGB LED Pin-out
-
7/24/2019 Principles of Embedded System Lab Manual
16/93
16
Current Limiting Resistors (270 ohm) (red-purple-brown)
Most LEDs are designed to work with a voltage between 1.5v and 3v. As most microcontrollers(including the Arduino) operate on 5 volts a current limiting resistor is required.
Consult your LEDs datasheet for maximum ratings but we like to use 270 ohm resistors. This limits thecurrent to ~20mA, well within most LEDs and microcontroller ratings. Figure 3-1 shows the testschematic for RGB LED.
Figure 3-1 RGB Test SchematicPulse Width Modulation (PWM)
It is a technique for power controlling. It is also used to control the brightness of each RGB LEDs.Roughly every 1/500 of a second, the PWM output will produce a pulse. The length of this pulse iscontrolled by the 'analogWrite' function. So 'analogWrite(0)' will not produce any pulse at all and'analogWrite(255)' will produce a pulse that lasts all the way until the next pulse is due, so that the
output is actually on all the time. If the specify value in the analogWrite that is somewhere in between 0and 255 then it will produce a pulse. If the output pulse is only high for 5% of the time then whatever weare driving will only receive 5% of full power. However, the output is at 5V for 90% of the time then theload will get 90% of the power delivered to it.
Reference:www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer
3.
USB Cable4. Power Source5. Bread board6. RGB LED7. Resistors (270 , 470, 500, and 1K)8. Connecting wires
http://www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/http://www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/http://www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/http://www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/ -
7/24/2019 Principles of Embedded System Lab Manual
17/93
17
5. Procedure:
1. Open Sketch software.2. Create a circuit and board connection as shown in Figure 3-4.
Figure 3-4. RGB Breadboard Connection
-
7/24/2019 Principles of Embedded System Lab Manual
18/93
18
3. Copy the source code at Figure 3-5.
Figure 3-5 RGB LED Source Code
4. Simulate the program.5.
Determine the output at Table 3-1.6. Draw the PWM graph at the data and results for the given signals below
a. 1/20b. 10/20c. 18/20
7. Draw a PCB design at the space provided.
-
7/24/2019 Principles of Embedded System Lab Manual
19/93
19
6. Data and Results:
Table 3-1 Color Settings
Color Settings Output
1. 255,0,02. 0,255,0
3. 0,0,2554. 255,255,0
5. 80,0,80
6. 0,255,255
7. 0x4B,0x0,0x82
8. 0x3A,0xDF,0x00
9. 0x24,0x3B,0x0B
10. 0x00,0xFF,0x00
1/20 10/20 18/10
-
7/24/2019 Principles of Embedded System Lab Manual
20/93
20
PCB Design
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
21/93
21
Activity No. 4
LED LIGHTS, SHIFT REGISTER AND SERIAL MONITOR
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan LED and serial monitor output using Shift Register IC. This activity also provides students withknowledge and skills on how to develop a circuit using Shift Register IC controlled by C programmingcode.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display an LED and serial monitor output.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
74HC595 as an "8-bit serial-in, serial or parallel-out shift register with output latches; 3-state." In otherwords, it can be used to control 8 outputs at a time while taking only a few pins on the microcontroller. It
can be link multiple registers together to extend to even more output. (Users may also wish to search forother driver chips with "595" or "596" in their part numbers, there are many. The STP16C596 forexample will drive 16 LED's and eliminate the series resistors with built-in constant current sources.)
This integrated circuit work in a "synchronous serial communication," i.e. it can pulse one pin up anddown thereby communicating a data byte to the register bit by bit. It's by pulsing second pin, the clockpin, which can delineate between bits. This is in contrast to using the "asynchronous serialcommunication" of the Serial.begin() function which relies on the sender and the receiver to be setindependently to an agreed data rate.
Once the whole byte is transmitted to the register the HIGH or LOW messages held in each bit get
parceled out to each of the individual output pins. This is the "parallel output" part, having all the pins doall at once.
The "serial output" part of this component comes from its extra pin which can pass the serial informationreceived from the microcontroller out again unchanged. This means that it can transmit 16 bits in a row(2 bytes) and the first 8 will flow through the first register into the second register and be expressedthere.
-
7/24/2019 Principles of Embedded System Lab Manual
22/93
22
"3 states" refers to the fact that can set the output pins as either high, low or "high impedance." Unlikethe HIGH and LOW states, it cannot set pins to high impedance state individually. It can only set thewhole chip together. This is a pretty specialized thing to do for example think of a LED array that mightneed to be controlled by completely different microcontrollers depending on a specific mode setting built
into a project. Figure 4-1 shows the pin configuration of 74HC595
Figure 4-1 595 Pin Configuration
http://en.wikipedia.org/wiki/High_impedancehttp://en.wikipedia.org/wiki/High_impedance -
7/24/2019 Principles of Embedded System Lab Manual
23/93
23
Shift registers hold an eight memory location as shown in Figure 4-2.
Figure 4-2 Pin Configuration and Pulse
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer
3.
USB Cable4. Power Source5. Bread board6. 8 LED7. 8 Resistors (270 )8. Connecting wires
-
7/24/2019 Principles of Embedded System Lab Manual
24/93
24
5. Procedure:
1. Create a Circuit and board connection as shown in Figure 4-3.
Figure 4-3 8 LED Lights Circuit2. Open Sketch software.3. Copy the source code at Figure 4-4
-
7/24/2019 Principles of Embedded System Lab Manual
25/93
25
Figure 4-4 8 LED Lights Code
4. Simulate the program.5. Fill-up Table 4-1.6. Save the program as Activity 4-1.
-
7/24/2019 Principles of Embedded System Lab Manual
26/93
26
7. Create a new file.8. Copy the program at Figure 4-5.
Figure 4-5 Shift RegisterBrightness Source Code
9. Simulate the program.
-
7/24/2019 Principles of Embedded System Lab Manual
27/93
27
10.Fill-out Table 4-2.11.Save the program as Activity 4-2.12.Create a new file.13.Copy the program at Appendix A.14.Save the program as Activity 4-3.
15.
Simulate the program.16.Draw the sequential output at the data and results.17.Create a new file.18.Copy the program at Figure 4-6.
Figure 4-6 Serial Monitor Code
19.Determine the output at COM4.20.Write the COM4 output at the data and results21.Fill-out Table 4-3.
-
7/24/2019 Principles of Embedded System Lab Manual
28/93
28
Sequential Output
6. Data and Results:
Table 4-1. Display Modification
Case Output Observation
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)led=1
i=1
i>8
i--
delay(100)
delay(1000)
delay(1500)
BothdigitalWrite(latchPin,High)
Both
digitalWrite(latchPin,Low)
Table 4-2. Brightness Modification
Case Output Observation
setBrightness(400), delay(1000)
setBrightness(300), delay(1000)
setBrightness(200), delay(1000)
setBrightness(100), delay(1000)
setBrightness(50), delay(1000)
-
7/24/2019 Principles of Embedded System Lab Manual
29/93
29
Table 4-3. Baud Rate
Case COM4 Output Observation
4800 baud
14400 baud19200 baud
28800 baud38400 baud
57600 baud
115200 baud
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
30/93
30
Activity No. 5
DIGITAL INPUTS
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan LED light output controlled by a tactile push switch. This activity also provides students withknowledge and skills on how to develop a circuit using C-programming codes.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1Create a runnable program that will display an LED light output controlled by a switch.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Switches are really simple electronic components. When the user presses a button or flips a lever, itconnects two contacts together so that electricity can flow through the circuit. The little tactile switches
are a kind of switch that has four connections, which can be a little confusing. In reality, there are onlytwo electrical connections, as inside the switch package pins B and C are connected together, like the Aand D as shown in Figure 5-1.
Figure 5-1 Tactile Switch
-
7/24/2019 Principles of Embedded System Lab Manual
31/93
31
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable
4.
Power Source5. Bread board6. 2 Tactile push switch7. 8 LED Lights8. 8 Resistors (270 )9. Connecting wires
5. Procedure:
1. Create a circuit connection as shown in Figure 5-2.
Figure 5-2 Breadboard Connection
-
7/24/2019 Principles of Embedded System Lab Manual
32/93
32
2. Open Sketch software.3. Copy the program in Figure 5-3
Figure 5-3 Source Code4. Fill-out Table 5-1.5. Save the program as Activity 5-1.6. Draw a schematic diagram for the circuit at the data and results7. Write a runnable program at the data and result using whilefunction.
6. Data and Results:
Table 5-1. Display Modification
Case Output Observation
pinMode(latchPin,INPUT)
pinMode(buttonApin,INPUT_PULLDOWN)
pinMode(buttonBpin,INPUT_PULLDOWN)
pinMode(buttonApin,INPUT_PULLDOWN)pinMode(buttonBpin,INPUT_PULLDOWN)
digitalWrite(ledPin,LOW)
digitalRead(buttonBpin)==HIGH
-
7/24/2019 Principles of Embedded System Lab Manual
33/93
33
Schematic Diagram While function Source Code
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
34/93
34
Activity No. 6
RGB LED FADER
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan RGB LED lights common cathode output. This activity also provides students with knowledge andskills on how to develop a circuit using C programming source code.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display an RGB LED lights output controlled by a C-
program.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
LEDs (ell-ee-dees) are a particular type ofdiode that convert electrical energy into light. In fact, LEDstands for Light Emitting Diode. This is reflected in the similarity between the diode and LED schematic
symbols:
In short, LEDs are like tiny lightbulbs. However, LEDs require a lot less power to light up by comparison.They are also more energy efficient, so they do not tend to get hot like conventional light bulbs do. Thismakes them ideal for mobile devices and other low-power applications.
RGB LED in a 5mm diffused epoxy case. - Common Cathode (common ground) as shown in Figure 6-18,000mcd- 100,000nhour lifetime as shown in Table 6-1.
Table 6-1 RGB Colors Description
Red: 2V ~ 2.4V20
mA
Green:3.2V ~3.6V
20mA
Blue:3.2V ~3.6V
20mA
https://learn.sparkfun.com/tutorials/diodes/introductionhttps://learn.sparkfun.com/tutorials/diodes/introduction -
7/24/2019 Principles of Embedded System Lab Manual
35/93
35
Figure 6-1 RGB Pin Configuration
Reference:www.chromationsystems.com/store/index.php?main_page=product_info&products_id=182
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable4. Power Source5. Bread board6. RGB LED (Common Cathode)7. 3 Tactile Push Switches8. 8 Resistors (270 )
9.
2x2 Printed Circuit Board10.Ferric Chloride11.Plastic Container12.Permanent Marker13.Masking Tape14.Mini Drill15.Connecting wires
-
7/24/2019 Principles of Embedded System Lab Manual
36/93
36
5. Procedure:
1. Create a Breadboard connection as shown in Figure 6-1.
Figure 6-1 RGB and Switches Breadboard Connection
2.
Draw a schematic diagram at the data and results.3. Open Sketch software.4. Copy the program in Figure 6-2.
-
7/24/2019 Principles of Embedded System Lab Manual
37/93
37
Figure 6-2 Source Code5. Simulate the program.6.
Save the file as Activity 6-1.7. Fill-out Table 6-1 at the data and results.8. Design a PCB layout for Figure 6-1.
-
7/24/2019 Principles of Embedded System Lab Manual
38/93
38
Schematic Diagram
6. Data and Results:
Table 6-1. Display Modification
Case Output Observation
if (digitalRead(redSwitchPin)==HIGH)red--
if(red
-
7/24/2019 Principles of Embedded System Lab Manual
39/93
39
Activity No. 7
ANALOG INPUTS
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan EIGHT LED lights output controlled by a Variable resistor and design PCB Circuit and connection.This activity also provides students with knowledge and skills on how to develop a circuit using analoginput circuit controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program and a PCB circuit that will display an EIGHT LED lights output
controlled by a Variable resistor.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:Variable Resistors (Pots)
Are often called 'pots' which is short for 'potentiometers'. The Serial Monitor and the pot is somehow,varying the voltage at A0 and the little test sketch is converting this voltage into a number between 0and 1023.
Figure 7-1 Variable Resistor (Pots)
Pot has a circular 'track' that acts as a resistor; in this case it is a 10 k resistor. However, the differencewith a pot is that there is also a middle connection called the 'slider'. This connection is rotated whenturning the pot. So if it is connected to one end of the pot to 5V and the other is to the GND, then thevoltage at the slider will vary between 0 and 5V.
-
7/24/2019 Principles of Embedded System Lab Manual
40/93
40
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable4. Power Source
5.
Bread board6. 8 LED (any color)7. 10K Variable resistor (pot)8. Potentiometer9. 8 Resistors (270 )10.74HC595 Shift Register11. IC Socket12.2x2 Printed Circuit Board13.Ferric Chloride14.Plastic Container15.Permanent Marker
16.
Masking Tape17.Mini Drill18.Connecting wires
5. Procedure:
1. Create a bread board layout as shown in Figure 7-2.
Figure 7-2 Bread Board Connection
-
7/24/2019 Principles of Embedded System Lab Manual
41/93
41
2. Copy the program in Appendix B3. Simulate the program.4. Save file as Activity 7-1.5. Write the COM4 output at the data and results
6.
Fill-out Table 7-1.7. Create a new program as shown in Figure 7-3.
Figure 7-3 Source Code8. Fill-up Table 7-2.
-
7/24/2019 Principles of Embedded System Lab Manual
42/93
42
6. Data and Results:
Table 7-1. Baud Rate
Case COM4 Output Observation4800 baud
14400 baud
19200 baud
28800 baud
38400 baud
57600 baud115200 baud
Table 7-2. Display Modification
Case Output Observation
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)
i--
-
7/24/2019 Principles of Embedded System Lab Manual
43/93
43
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
44/93
44
Activity No. 8
SENSOR AND SOUNDS
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan EIGHT LED lights and serial monitor output controlled by a photocell electronic component. Thisactivity also provides students with knowledge and skills on how to develop a circuit using photocellelectronic component that will transmit a data through the use of C program codes.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display an Eight LED lights and serial monitor output by a
photocell electronic component.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
A sensor is a converter that measures aphysical quantity and converts it into a signal which can be read
by an observer or by an (today mostlyelectronic) instrument. For example, amercury-in-glassthermometer converts the measured temperature into expansion and contraction of a liquid which canbe read on a calibrated glass tube. Athermocouple converts temperature to an output voltage which canbe read by avoltmeter.For accuracy, most sensors arecalibrated against knownstandards.
Sensors are used in everyday objects such as touch-sensitive elevator buttons (tactile sensor) andlamps which dim or brighten by touching the base. There are also innumerable applications for sensorsof which most people are never aware. Applications include cars, machines, aerospace, medicine,manufacturing and robotics.
A sensor is a device, which responds to an input quantity by generating a functionally related output
usually in the form of an electrical or optical signal. A sensor's sensitivity indicates how much thesensor's output changes when the measured quantity changes. For instance, if the mercury in athermometer moves 1 cm when the temperature changes by 1 C, the sensitivity is 1 cm/C (it isbasically the slope Dy/Dx assuming a linear characteristic). Sensors that measure very small changesmust have very high sensitivities. Sensors also have an impact on what they measure; for instance, aroom temperature thermometer inserted into a hot cup of liquid cools the liquid while the liquid heats thethermometer. Sensors need to be designed to have a small effect on what is measured; making the
http://en.wikipedia.org/wiki/Physical_quantityhttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Mercury-in-glass_thermometerhttp://en.wikipedia.org/wiki/Mercury-in-glass_thermometerhttp://en.wikipedia.org/wiki/Thermocouplehttp://en.wikipedia.org/wiki/Voltmeterhttp://en.wikipedia.org/wiki/Calibrationhttp://en.wikipedia.org/wiki/Standard_(metrology)http://en.wikipedia.org/wiki/Tactile_sensorhttp://en.wikipedia.org/wiki/Tactile_sensorhttp://en.wikipedia.org/wiki/Standard_(metrology)http://en.wikipedia.org/wiki/Calibrationhttp://en.wikipedia.org/wiki/Voltmeterhttp://en.wikipedia.org/wiki/Thermocouplehttp://en.wikipedia.org/wiki/Mercury-in-glass_thermometerhttp://en.wikipedia.org/wiki/Mercury-in-glass_thermometerhttp://en.wikipedia.org/wiki/Electronicshttp://en.wikipedia.org/wiki/Physical_quantity -
7/24/2019 Principles of Embedded System Lab Manual
45/93
45
sensor smaller often improves this and may introduce other advantages. Technological progress allowsmore and more sensors to be manufactured on a microscopic scale as microsensorsusingMEMS technology. In most cases, a microsensor reaches a significantly higher speed andsensitivity compared withmacroscopic approaches.
A photoresistor or light-dependent resistor (LDR) or photocell is a light-controlled variableresistor.Theresistance of a photoresistor decreases with increasing incident light intensity; in other words, itexhibitsphotoconductivity.A photoresistor can be applied in light-sensitive detector circuits, and light-and dark-activated switching circuits.
A photoresistor is made of a high resistancesemiconductor. In the dark, a photoresistor can have aresistance as high as a few megaohms (M), while in the light, a photoresistor can have a resistance aslow as a few hundred ohms. If incident light on a photoresistor exceeds acertainfrequency,photons absorbed by the semiconductor give boundelectrons enough energy to jumpinto theconduction band. The resulting free electrons (and theirhole partners) conduct electricity,thereby loweringresistance.The resistance range and sensitivity of a photoresistor can substantially
differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently tophotons within certain wavelength bands.
A photoelectric device can be either intrinsic or extrinsic. An intrinsic semiconductor has its ownchargecarriers and is not an efficient semiconductor, for example, silicon. In intrinsic devices the only availableelectrons are in the valence band, and hence the photon must have enough energy to excite theelectron across the entire bandgap. Extrinsic devices have impurities, also calleddopants,and addedwhose ground state energy is closer to the conduction band; since the electrons do not have as far tojump, lower energy photons (that is, longer wavelengths and lower frequencies) are sufficient to triggerthe device. If a sample of silicon has some of its atoms replaced by phosphorus atoms (impurities),there will be extra electrons available for conduction. This is an example of an extrinsic semiconductor.
SoundSound waves are vibrations in the air pressure. The speed of the vibrations (cycles per second or Hertz)is what makes the pitch of the sound. The higher the frequency of the vibration, the higher the pitch, asshown in Figure 8-1.
Figure 8-1 Piezo Sounder
http://en.wikipedia.org/wiki/Microscopic_scalehttp://en.wikipedia.org/wiki/Microelectromechanical_systemshttp://en.wikipedia.org/wiki/Macroscopichttp://en.wikipedia.org/wiki/Resistorhttp://en.wikipedia.org/wiki/Electrical_resistancehttp://en.wikipedia.org/wiki/Photoconductivityhttp://en.wikipedia.org/wiki/Semiconductorhttp://en.wikipedia.org/wiki/Frequencyhttp://en.wikipedia.org/wiki/Photonhttp://en.wikipedia.org/wiki/Electronhttp://en.wikipedia.org/wiki/Conduction_bandhttp://en.wikipedia.org/wiki/Electron_holehttp://en.wikipedia.org/wiki/Electrical_resistancehttp://en.wikipedia.org/wiki/Charge_carrierhttp://en.wikipedia.org/wiki/Charge_carrierhttp://en.wikipedia.org/wiki/Valence_bandhttp://en.wikipedia.org/wiki/Dopantshttp://en.wikipedia.org/wiki/Dopantshttp://en.wikipedia.org/wiki/Valence_bandhttp://en.wikipedia.org/wiki/Charge_carrierhttp://en.wikipedia.org/wiki/Charge_carrierhttp://en.wikipedia.org/wiki/Electrical_resistancehttp://en.wikipedia.org/wiki/Electron_holehttp://en.wikipedia.org/wiki/Conduction_bandhttp://en.wikipedia.org/wiki/Electronhttp://en.wikipedia.org/wiki/Photonhttp://en.wikipedia.org/wiki/Frequencyhttp://en.wikipedia.org/wiki/Semiconductorhttp://en.wikipedia.org/wiki/Photoconductivityhttp://en.wikipedia.org/wiki/Electrical_resistancehttp://en.wikipedia.org/wiki/Resistorhttp://en.wikipedia.org/wiki/Macroscopichttp://en.wikipedia.org/wiki/Microelectromechanical_systemshttp://en.wikipedia.org/wiki/Microscopic_scale -
7/24/2019 Principles of Embedded System Lab Manual
46/93
46
Middle C is usually defined as a frequency of 261 Hz. If it turns a digital output on and off again 261times every second then that output will be middle C. To hear the output, it one needs to attachsomething that will convert the electrical signal into sound waves. This can be done with a loudspeakeror piezo sounder. Piezo sounders use a special crystal that expands and contracts as an electrical
signal passes through it.
Reference: http://en.wikipedia.org/wiki4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable4. Power Source5. Bread board6. 8 LED (any color)7. Photocell (Light Dependent Resistor)
8.
8 Resistors (270 )9. 1 Resistor (1k )10.Piezo Sounder11.74HC595 Shift Register12. IC Socket13.2x2 Printed Circuit Board14.Ferric Chloride15.Plastic Container16.Permanent Marker17.Masking Tape18.Mini Drill
19.
Connecting wires
5. Procedure:
1. Create a Breadboard connection as shown in Figure 8-2.
Figure 8-2 Breadboard Connection
-
7/24/2019 Principles of Embedded System Lab Manual
47/93
47
2. Remove and replace the pot by a photocell.3. Open Sketch software.4. Copy the source code at Appendix C5. Upload the program.
6.
Save the file as Activity 8-1.7. Fill-out Table 8-1.8. Design a PCB circuit for Figure 8-1.9. Draw a schematic diagram at the data and results.10.Create a PCB and Arduino/Gizduino board connection.11.Create a new breadboard circuit connection as shown in Figure 8-3.
Figure 8-3. Breadboard connection using Piezo Sounder
12.Copy the source code at Appendix D13.Upload the program.14.Save the file as Activity 8-2.15.Create a new file.16.Save the file as Activity 8-3.17.
Copy the Source code at Figure 8-4.
-
7/24/2019 Principles of Embedded System Lab Manual
48/93
48
Figure 8-4 Loop Sound Source Code18.Upload the program.19.Answer the question at the data and results.
6. Data and Results:
Table 8-1. Display Modification
Case Output Observation
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)
i--
int lightpin= 5;
int latchpin=6;
int clockpin=4;int datapin=0;
Schematic Diagram
Is there an output sound produced by the piezo sounder? ______
-
7/24/2019 Principles of Embedded System Lab Manual
49/93
49
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
50/93
50
Activity No. 9
LCD DISPLAY
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will displayan LCD output. This activity also provides students with knowledge and skills on how to develop a circuitusing LCD display controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that will display an LCD output.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Liquid Cristal Display (LCD)
Description
Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If theformer, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied toground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters.
Syntax
LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)
Parameters
rs: the number of the Arduino pin that is connected to the RS pin on the LCDrw: the number of the Arduino pin that is connected to the RW pin on the LCD (optional)enable: the number of the Arduino pin that is connected to the enable pin on the LCD
-
7/24/2019 Principles of Embedded System Lab Manual
51/93
51
d0, d1, d2, d3, d4, d5, d6, d7: the numbers of the Arduino pins that are connected to the correspondingdata pins on the LCD. d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using onlythe four data lines (d4, d5, d6, d7).
Example:
#include
LiquidCrystallcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{lcd.begin(16,1);lcd.print("hello, world!");
}
void loop() {}
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable4. Power Source5. Bread board6. LCD Display (16x2 Characters)7. 10K Variable Resistor8. 1K Resistor
9.
Photocell10.TMP36 Temperature Sensor11.Connecting wires
-
7/24/2019 Principles of Embedded System Lab Manual
52/93
52
5. Procedure:
1. Create a connection as shown at Figure 9-1.
Figure 9-1 LCD Breadboard Connection2. Open Sketch software.3. Copy the program at Figure 9-2.
-
7/24/2019 Principles of Embedded System Lab Manual
53/93
53
Figure 9-2 LCD Source Code
4. Upload the program.5. Draw the LCD output at the data and results6. Save the file as Activity 9-1.7. Write a temperature program that will compute and display an output using a unit in Celsius.8. Draw a schematic diagram for Figure 9-1.
-
7/24/2019 Principles of Embedded System Lab Manual
54/93
54
6. Data and Results:
LCD Output
Program Source Code
Schematic Diagram
-
7/24/2019 Principles of Embedded System Lab Manual
55/93
55
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
56/93
56
Activity No. 10
MOTORS
Course Code: CPE 131 Program:Course Title: Principle of Embedded System Date Performed:
Section: Date Submitted:
Name : Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that willproduce a motor movement output. This activity also provides students with knowledge and skills onhow to develop a circuit with motor application that is controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:2.1Create a runnable program that can control a motor.2.2Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Transistor and DC Motor
The small DC motor is likely to use more power than an Arduino digital output can handle directly. If it is
tried to connect the motor straight to an Arduino pin, there is a good chance that it could damage theArduino. A small transistor like the PN2222 can be used as a switch that uses just a little current fromthe Arduino digital output to control the much bigger current of the motor, as shown in Figure 10-1.
Figure 10-1 Transistor
-
7/24/2019 Principles of Embedded System Lab Manual
57/93
57
The transistor has three leads. Most of the electricity flows from the Collector to the Emitter, but this willonly happen if a small amount is flowing into the Base connection. This small current is supplied by theArduino digital output. The diagram below is called a schematic diagram (Figure 10-2). Like abreadboard layout, it is a way of showing how the parts of an electronic project are connected together.
Figure 10-2 Motor Connection Schematic Diagram
The pin D3 of the Arduino is connected to the resistor. Just like when using an LED, this limits thecurrent flowing into the transistor through the base. There is a diode connected across the connectionsof the motor. Diodes only allow electricity to flow in one direction (the direction of their arrow).
-
7/24/2019 Principles of Embedded System Lab Manual
58/93
58
Servo Motor
The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulseroughly every 20 milliseconds. If that pulse is high for 1 millisecond, then the servo angle will be zero, ifit is 1.5 milliseconds, then it will be at its centre position and if it is 2 milliseconds it will be at 180degrees, as shown in Figure 10-3.
Figure 10-3 Servo Motor Cycle
The end points of the servo can vary and many servos only turn through about 170 degrees.
L293D
This is a very useful chip. It can actually control two motors independently. Most of the pins on the right
hand side of the chip are for controlling a second motor. As shown in Figure 10-4.
-
7/24/2019 Principles of Embedded System Lab Manual
59/93
59
Figure 10-4 L293 Pin Configuration
A second motor would be attached between OUT3 and OUT4. Three more control pins are needed tocontrol the EN2 that is connected to a PWM enabled output pin on the Arduino IN3 and IN4 areconnected to digital outputs on the Arduino. The L293D has two +V pins (8 and 16). The pin '+Vmotor(8) provides the power for the motors, and +V (16) for the chip's logic. Connect both of these to theArduino 5V pin. However, if there are more powerful motor, or a higher voltage motor, it would providethe motor with a separate power supply using pin 8 connected to the positive power supply and the
-
7/24/2019 Principles of Embedded System Lab Manual
60/93
60
ground of the second power supply that is connected to the ground of the Arduino.
Stepper Motor
Stepper motors use a cogged wheel and electro magnets to nudge the wheel round a 'step' at a time , as
shown in Figure 10-5.
Figure 10-5 Stepper Motor
By energizing the coils in the right order, the motor is driven round. The number of steps that the steppermotor has in a 360 degree rotation is actually the number of teeth on the cog. This motor has 48 steps,
but then the motor also incorporates a reduction gearbox of 1:16 that means that it needs 16 x 48 = 768steps. This connection is only provided if a different type of drive circuit that does not allow the current ineach coil to be reversed. Having a center connection to each coil means that it can both energize the leftor right side of the coil, and get the effect of reversing the current flow without having to use a circuit thatcan reverse the current. Since, L293D is very good at reversing the current, there no need this forcommon connection, the supply current can either direct go to the whole of each of the coils.
-
7/24/2019 Principles of Embedded System Lab Manual
61/93
61
4. Materials and Equipment:
1. Arduino/Gizduino board2. Computer3. USB Cable
4.
Power Source5. Bread board6. Connecting wires7. 1 Small 6V DC Motor8. 1 PN2222 Transistor9. 1 1N4001 diode10.1 Resistor (270)11.1 Servo Motor12.10k Variable Resistor13.1 Capacitor (100 F)14.1 L293D IC
15.
1 Tactile Push Switch16.1 5V Stepper Motor
5. Procedure:
1. Create a circuit and board connection as shown in Figure 10-6.
Figure 10-6 DC Motor Board Connection
-
7/24/2019 Principles of Embedded System Lab Manual
62/93
62
2. Open Sketch software.3. Copy the source code at Figure 10-7.
Figure 10-7 DC Motor Source Code
-
7/24/2019 Principles of Embedded System Lab Manual
63/93
63
4. Save the file as Activity 10-1.5. Compile the program.6. Write the COM4 output at the data and results.7. Reverse the connection.
8.
Compile the program.9. Write the COM4 output at the data and results.10.Create a new circuit and board connection as shown in Figure 10-8.11.Create a new program12.Copy the program at Figure 10-9.13.Save the file as Activity 10-2.14.Compile the program.15.Write the COM4 output at the data and results.16.Reverse the connection.17.Compile the program.18.Write the COM4 output at the data and results.
19.
Create a new circuit and board connection as shown in Figure 10-10.20.
Create a new program21.Copy the program at Figure 10-11.22.Save the file as Activity 10-3.23.Compile the program.24.Write the COM4 output at the data and results.25.Reverse the connection.26.Compile the program.27.Write the COM4 output at the data and results.28.Create a new circuit and board connection as shown in Figure 10-12.29.Create a new program30.Copy the program at Figure 10-13.31.
Save the file as Activity 10-4.32.Compile the program.33.Write the COM4 output at the data and results.34.Reverse the connection.35.Compile the program.36.Write the COM4 output at the data and results.
-
7/24/2019 Principles of Embedded System Lab Manual
64/93
64
Figure 10-8 Servo Motor Connections
-
7/24/2019 Principles of Embedded System Lab Manual
65/93
65
Figure 10-9A Sweep Movement Figure 10-9B Knob Movement
Figure 10-9 Servo Motor Code
Figure 10-10 DC Reverse Board Connection
-
7/24/2019 Principles of Embedded System Lab Manual
66/93
66
Figure 10-11 Source Code for Bi-directional Movement
Figure 10-12 Stepper Motor Board Connection
-
7/24/2019 Principles of Embedded System Lab Manual
67/93
67
Figure 10-13 Stepper Motor Code
6. Data and Results:
-
7/24/2019 Principles of Embedded System Lab Manual
68/93
68
-
7/24/2019 Principles of Embedded System Lab Manual
69/93
69
7. Data Analysis:
8. Assessment Rubric:
-
7/24/2019 Principles of Embedded System Lab Manual
70/93
70
Appendix
-
7/24/2019 Principles of Embedded System Lab Manual
71/93
71
Appendix A
/*
Shift Register Example
Turning on the outputs of a 74HC595 using an array
Hardware:
* 74HC595 shift register
* LEDs attached to each of the outputs of the shift register
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595int dataPin = 11;
//holders for infromation you're going to pass to shifting
function
byte data;
byte dataArray[10];
void setup() {
//set pins to output because they are addressed in the main
loop
pinMode(latchPin, OUTPUT);
Serial.begin(9600);
//Arduino doesn't seem to have a way to write binary straight
into the code
//so these values are in HEX. Decimal would have been fine,
too.
dataArray[0] = 0xFF; //11111111
dataArray[1] = 0xFE; //11111110dataArray[2] = 0xFC; //11111100
dataArray[3] = 0xF8; //11111000
dataArray[4] = 0xF0; //11110000
dataArray[5] = 0xE0; //11100000
dataArray[6] = 0xC0; //11000000
-
7/24/2019 Principles of Embedded System Lab Manual
72/93
72
dataArray[7] = 0x80; //10000000
dataArray[8] = 0x00; //00000000
dataArray[9] = 0xE0; //11100000
//function that blinks all the LEDs
//gets passed the number of blinks and the pause timeblinkAll_2Bytes(2,500);
}
void loop() {
for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
data = dataArray[j];
//ground latchPin and hold low for as long as you are
transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(300);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setupint i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
-
7/24/2019 Principles of Embedded System Lab Manual
73/93
73
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000// and proceeds to set pinState to 1.
if ( myDataOut & (1
-
7/24/2019 Principles of Embedded System Lab Manual
74/93
74
//has its full visual effect.
void blinkAll_2Bytes(int n, int d) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);delay(200);
for (int x = 0; x < n; x++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 255);
shiftOut(dataPin, clockPin, 255);
digitalWrite(latchPin, 1);
delay(d);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(d);
}
}
-
7/24/2019 Principles of Embedded System Lab Manual
75/93
75
Appendix B
-
7/24/2019 Principles of Embedded System Lab Manual
76/93
76
Appendix C
-
7/24/2019 Principles of Embedded System Lab Manual
77/93
77
Appendix D
-
7/24/2019 Principles of Embedded System Lab Manual
78/93
78
Appendix E
List of Functions for LCD Display
1.
begin()
Description
Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the
display. begin()needs to be called before any other LCD library commands.
Syntax
lcd.begin(cols, rows)
Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
2.clear()
Description
Clears the LCD screen and positions the cursor in the upper-left corner.
Syntax
lcd.clear()
Parameters
lcd: a variable of typeLiquidCrystal
3.home()
Description
Positions the cursor in the upper-left of the LCD. That is, use that location in outputting subsequent
text to the display. To also clear the display, use theclear()function instead.
Syntax
http://arduino.cc/en/Reference/LiquidCrystalClearhttp://arduino.cc/en/Reference/LiquidCrystalClearhttp://arduino.cc/en/Reference/LiquidCrystalClearhttp://arduino.cc/en/Reference/LiquidCrystalClear -
7/24/2019 Principles of Embedded System Lab Manual
79/93
79
lcd.home()
Parameters
lcd: a variable of typeLiquidCrystal
4.
setCursor()
Description
Position the LCD cursor; that is, set the location at which subsequent text written to the LCD will be
displayed.
Syntax
lcd.setCursor(col, row)
Parameters
lcd: a variable of typeLiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
5.
write()
Description
Write a character to the LCD.
Syntax
lcd.write(data)
Parameters
lcd: a variable of typeLiquidCrystal
data: the character to write to the display
Returns
byte
write()will return the number of bytes written, though reading that number is optional
-
7/24/2019 Principles of Embedded System Lab Manual
80/93
80
Example:
#include
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) {lcd.write(Serial.read());
}
}
6.
print()
Description
Prints text to the LCD.
Syntax
lcd.print(data)
lcd.print(data, BASE)
Parameters
lcd: a variable of typeLiquidCrystal
data: the data to print (char, byte, int, long, or string)
BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal
(base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).
Returns
byte
print() will return the number of bytes written, though reading that number is optional
-
7/24/2019 Principles of Embedded System Lab Manual
81/93
81
Example
#include
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
lcd.print("hello, world!");
}
void loop() {}
7.
cursor()
Description
Display the LCD cursor: an underscore (line) at the position to which the next character will be
written.
Syntax
lcd.cursor()
Parameters
lcd: a variable of typeLiquidCrystal
Example
cursor() and noCursor()
8.
noCursor()
Description
Hides the LCD cursor.
Syntax
lcd.noCursor()
Parameters
http://arduino.cc/en/Tutorial/LiquidCrystalCursorhttp://arduino.cc/en/Tutorial/LiquidCrystalCursor -
7/24/2019 Principles of Embedded System Lab Manual
82/93
82
lcd: a variable of typeLiquidCrystal
-
7/24/2019 Principles of Embedded System Lab Manual
83/93
83
Example
cursor() and noCursor()
9.
blink()
Description
Display the blinking LCD cursor. If used in combination with thecursor() function, the result will
depend on the particular display.
Syntax
lcd.blink()
Parameters
lcd: a variable of typeLiquidCrystal
Example
blink() and noBlink()
10.
noBlink()
Description
Turns off the blinking LCD cursor.
Syntax
lcd.noBlink()
Parameters
lcd: a variable of typeLiquidCrystal
Example
blink() and noBlink()
11.
display()
Description
http://arduino.cc/en/Tutorial/LiquidCrystalCursorhttp://arduino.cc/en/Reference/LiquidCrystalCursorhttp://arduino.cc/en/Reference/LiquidCrystalCursorhttp://arduino.cc/en/Tutorial/LiquidCrystalBlinkhttp://arduino.cc/en/Tutorial/LiquidCrystalBlinkhttp://arduino.cc/en/Tutorial/LiquidCrystalBlinkhttp://arduino.cc/en/Tutorial/LiquidCrystalBlinkhttp://arduino.cc/en/Reference/LiquidCrystalCursorhttp://arduino.cc/en/Tutorial/LiquidCrystalCursor -
7/24/2019 Principles of Embedded System Lab Manual
84/93
84
Turns on the LCD display, after it's been turned off withnoDisplay(). This will restore the text (and
cursor) that was on the display.
http://arduino.cc/en/Reference/LiquidCrystalNoDisplayhttp://arduino.cc/en/Reference/LiquidCrystalNoDisplayhttp://arduino.cc/en/Reference/LiquidCrystalNoDisplay -
7/24/2019 Principles of Embedded System Lab Manual
85/93
85
Syntax
lcd.display()
Parameters
lcd: a variable of type LiquidCrystal
Example
display() and noDisplay()
12.noDisplay()
Description
Turns off the LCD display, without losing the text currently shown on it.
Syntax
lcd.noDisplay()
Parameters
lcd: a variable of typeLiquidCrystal
Example
display() and noDisplay()
13.scrollDisplayLeft()
Description
Scrolls the contents of the display (text and cursor) one space to the left.
Syntax
lcd.scrollDisplayLeft()
Parameters
lcd: a variable of typeLiquidCrystal
Example
scrollDisplayLeft() and scrollDisplayRight()
http://arduino.cc/en/Tutorial/LiquidCrystalDisplayhttp://arduino.cc/en/Tutorial/LiquidCrystalDisplayhttp://arduino.cc/en/Tutorial/LiquidCrystalScrollhttp://arduino.cc/en/Tutorial/LiquidCrystalScrollhttp://arduino.cc/en/Tutorial/LiquidCrystalDisplayhttp://arduino.cc/en/Tutorial/LiquidCrystalDisplay -
7/24/2019 Principles of Embedded System Lab Manual
86/93
86
14.scrollDisplayRight()
Description
Scrolls the contents of the display (text and cursor) one space to the right.
Syntax
lcd.scrollDisplayRight()
Parameters
lcd: a variable of typeLiquidCrystal
Example
scrollDisplayLeft() and scrollDisplayRight()15.
autoscroll()
Description
It turns ON automatic LCD scrolling. This causes each character output to the display to push
previous characters over by one space. If the current text direction is left -to-right (the default), the
display scrolls to the left; if the current direction is right-to-left, the display scrolls to the right. This
has the effect of outputting each new character to the same location on the LCD.
Syntax
lcd.autoscroll()
Parameters
lcd: a variable of typeLiquidCrystal
16.
noAutoscroll()
Description
Turns off automatic scrolling of the LCD.
Syntax
lcd.noAutoscroll()
Parameters
lcd: a variable of typeLiquidCrystal
http://arduino.cc/en/Tutorial/LiquidCrystalScrollhttp://arduino.cc/en/Tutorial/LiquidCrystalScroll -
7/24/2019 Principles of Embedded System Lab Manual
87/93
87
17.leftToRight()
Description
Set the direction for text written to the LCD to left-to-right, the default. This means that subsequent
characters written to the display will go from left to right, but does not affect previously-output text.
Syntax
lcd.leftToRight()
Parameters
lcd: a variable of typeLiquidCrystal
18.rightToLeft()
Description
Set the direction for text written to the LCD to right-to-left (the default is left-to-right). This means
that subsequent characters written to the display will go from right to left, but does not affect
previously-output text.
Syntax
lcd.rightToLeft()
Parameters
lcd: a variable of typeLiquidCrystal
19.
rightToLeft()
Description
Set the direction for text written to the LCD to right-to-left (the default is left-to-right). This means
that subsequent characters written to the display will go from right to left, but does not affect
previously-output text.
Syntax
lcd.rightToLeft()
Parameters
lcd: a variable of typeLiquidCrystal
-
7/24/2019 Principles of Embedded System Lab Manual
88/93
88
20.createChar()
Description
Create a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are
supported (numbered 0 to 7). The appearance of each custom character is specified by an array of
eight bytes, one for each row. The five least significant bits of each byte determine the pixels in that
row. To display a custom character on the screen,write() its number.
NB : When referencing custom character "0", if it is not in a variable, you need to cast it as a byte,
otherwise the compiler throws an error. See the example below.
Syntax
lcd.createChar(num, data)
Parameters
lcd: a variable of typeLiquidCrystal
num: which character to create (0 to 7)
data: the character's pixel data
Example
#include
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
http://arduino.cc/en/Reference/LiquidCrystalWritehttp://arduino.cc/en/Reference/LiquidCrystalWrite -
7/24/2019 Principles of Embedded System Lab Manual
89/93
89
void setup() {
lcd.createChar(0, smiley);
lcd.begin(16, 2);
lcd.write(byte(0));
}
void loop() {}
-
7/24/2019 Principles of Embedded System Lab Manual
90/93
90
Appendix F
Sample for LCD Display
LiquidCrystal - Text Direction (leftToRight() and rightToLeft()
This example sketch shows how to use the leftToRight() and rightToLeft() methods. These methods control
which way text flows from the cursor.
rightToLeft()causes text to flow to the left from the cursor, as if the display is right-justified.
leftToRight()causes text to flow to the right from the cursor, as if the display is left-justified.
This sketch prints athrough lright to left, then mthrough rleft to right, then sthrough zright to left again.
Hardware Required
Arduino Board LCD Screen (compatible with Hitachi HD44780 driver) pin headers to solder to the LCD display pins 10k Potentiometer breadboard hook-up wire
Circuit
Before wiring the LCD screen to Arduino it is suggested to solder a pin header strip to the 14 (or 16) pin
count connector of the LCD screen, as you can see in the image above.
To wire your LCD screen to your Arduino, connect the following pins:
LCD RS pin to digital pin 12 LCD Enable pin to digital pin 11 LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4 LCD D6 pin to digital pin 3 LCD D7 pin to digital pin 2
Additionally, wire a 10K pot to +5V and GND, with its wiper (output) to LCD screens VO pin (pin3).
-
7/24/2019 Principles of Embedded System Lab Manual
91/93
91
Code
/*
LiquidCrystal Library - TextDirection
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
-
7/24/2019 Principles of Embedded System Lab Manual
92/93
92
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch demonstrates how to use leftToRight() and rightToLeft()
to move the cursor.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Reference:
Library originally added 18 Apr 2008 by David A. Mellis
library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009 by Tom Igoe
modified 22 Nov 2010 by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection
*/
// include the library code:
#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int thisChar = 'a';
-
7/24/2019 Principles of Embedded System Lab Manual
93/93
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// turn on the cursor:
lcd.cursor();
}
void loop() {
// reverse directions at 'm':
if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}// print the character
lcd.write(thisChar);
// wait a second:
delay(1000);
// increment the letter:
thisChar++;
}