Download EEE174 CpE185 Laboratory Spring 2016 Arduino Lab Part

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Heterodyne wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
EEE174 CpE185 Laboratory
Spring 2016
Arduino Lab
Part 1, 2, and 3: Arduino Projects
In this section, you will begin familiarizing yourself with the Arduino microcontroller
both hardware and software. You will use the Arduino Max32.
Examine the Arduino Tutorial documentation and code.
Complete 3 projects. See the following projects. You may choose 3 from the following
projects or similar projects approved by your lab instructor. Demonstrate the Arduino
circuits are functioning to your Lab Instructor.
Part 4: Max 32 with PicKit3 programmer – debugger
Complete a project of your choosing using the Microchip Max 32 and PicKit3 programmer
debugger.
Lab Report Due: Week 10
1
Arduino Music and Light Show Project using Max 32
Adapt the instructions below for the Uno to the Max32
Buzzers are widely used in computers, printers, copiers, alarms, electronic toys, automotive electronic
equipment, telephones, cell phones, timers, and etc...
A buzzer contains a crystal that changes shape slightly when voltage is applied to it. By applying high and low
voltages to a piezoelectric crystal at a rapid rate, it causes the crystal to rapidly change shape. The result is
vibration. Vibrating objects cause the air around them to vibrate also. This is what our ear detects as sounds
and tones. Every rate of vibration has a different tone.
Connect the Arduino Uno R3 compatible board with a breadboard and a passive buzzer, using jumper wires.
The following figure shows that the positive terminal of the buzzer is connected to the Uno’s digital I/O pin 7
and the negative terminal is connected to the ground.
Connect the Arduino Uno R3 compatible board with a breadboard using jumping wires, and serially connect
a 220Ω resistor with one Red light emitting diode (LED). The following figure shows that the positive terminal
of the LED is connected to the 220Ω resistor, and the 220Ω resistor is connected to the Uno’s digital I/O pin 8
and the negative terminal of the LED is connected to the ground.
Repeat the steps above again and connect another LED to the Uno’s digital I/O pin 9.
Write a c program, using the Arduino’s integrated development environment (IDE), to play a song that
contains a minimum of 30 music notes. Design your program to blink a minimum of two (2) lights after the
song to provide visual effects. Play the song again faster at 75%-80% of its original duration and follow with
another faster light show. (Blinking the lights during the song is encouraged but optional.)
The frequency of each key on a piano keyboard is listed on the following table.
Piano Key
Note
C
C sharp/D flat
D
D sharp/E flat
E
F
F sharp/G flat
G
G sharp/A flat
A
A sharp/B flat
B
Frequency
1
2
33
65
35
69
37
73
39
78
41
82
44
87
46
92
49
98
52
104
55
110
58
117
62
123
3
131
139
147
156
165
175
185
196
208
220
233
247
4
262
277
294
311
330
349
370
392
415
440
466
494
5
523
554
587
622
659
698
740
784
831
880
932
988
6
1047
1109
1175
1245
1319
1397
1480
1568
1661
1760
1865
1976
7
2093
2217
2349
2489
2637
2794
2960
3136
3322
3520
3729
3951
8
4186
4434
4698
4978
Zip the entire Sketch folder for Project Music and Light Show.
Rename the folder to LastNameFirstName_Proj_ML.zip and submit the zipped file on Moodle2 with your
report.
Demo the Project to your Lab Instructor.
Arduino Project – FM Radio Stations Display Adapt
the instructions below for the Uno to the Max32
Seven-segment displays are widely used in digital clocks, digital watch, microwaves, ovens, electronic meters,
temperature controllers, radio, CD, DVD, Blu-ray players, basic calculators, pedometers, and other electronic
devices that display numerical information.
A 7-segment display is an assembly of light emitting diode-bars (segments). Each bar can be powered
individually. They are arranged and labeled as shown in the diagram below. When all the segments are
powered on, the display shows the number 8. Powering up segments a, b, c, d, and g will display the number
3. Some single displays have an additional input pin for the decimal point (DP) in their lower right or left hand
corner.
Each individual 7-segment can display numbers from 0 to 9.
Potentiometers are commonly used to control electrical devices such as volume controls on audio equipment
and light dimmers. A potentiometer is a simple knob that provides a variable resistance. It is a three-terminal
resistor with a rotating or sliding contact that forms an adjustable voltage divider. It is used for measuring
electric potential (voltage).
Connect one of the outer pins of the potentiometer to ground.
Connect the other outer pin of the potentiometer to 5 volts.
Connect the middle pin of the potentiometer to the analog pin A0.
By turning the knob of the potentiometer, we change the amount of resistance of the potentiometer. The
voltage of the potentiometer changes between 0 volts and 5 volts. When we read the value from the analog
pin A0, we will read a value between 0 and 1023. If there is 0 volt going to the analog pin A0, we read 0. If
there is 5 volt going to the analog pin A0, we read 1023. The values in between is proportional to the amount
of voltage being applied to the pin.
A multi-digit 7-segment display is an integration of several 7-segment displays into a single package. To
reduce the total number of registers needed to control many digits, the segment pins are shared by all the
digits. There is a single pin that connects to all the “a” segments, a single pin that connects all the “b”
segments, etc. When all the segments are powered on at the same time, every digit will display the same
number.
Time division multiplexing allows each digit to take a turn to be enabled to display a particular digit. When
this is done fast enough, our eyes are not able to tell the difference. The numbers will appear to be lit at the
same time, although they are not.
There are 12 pins in one 4-digit 7-segment display. The pin numbers for the 4-digit 7-segment display are
shown below.
Connect the Arduino Uno R3 compatible board with a breadboard and a 4-digit 7-segment display module
using the circuit diagram below.
Instead of a button, connect a LED light to digital pin 13.
The FM broadcast band, used for FM broadcast radio by radio stations, usually spans from 87.5 to 108.0
megahertz (MHz).
Write a c program, using the Arduino’s integrated development environment (IDE), to simulate a FM
broadcast radio display. Rotating the Potentiometer should display radio frequency from 87.5 to 108.0
megahertz (MHz).
When the potentiometer is turned to the following FM radio stations, turn the LED light ON.
Frequency
88.9
90.9
92.5
96.9
102.5
107.9
Call Sign
KXPR
KXJZ
KBEB
KSEG
KSFM
KDND
Format
CSU-Sacramento
CSU-Sacramento
Country
Classic Rock
Hip Hop
Top 40
The LED light should be turned off when the 4-digit 7-segment display is not showing any FM radio station.
Turning the light on for additional FM radio stations is welcome.
When the radio frequencies are 3 digits, for example 88.9, the leading 0 should be omitted in the display.
Zip the entire Sketch folder for Project FM Radio Stations Display.
Rename the folder to LastNameFirstName_Proj_FM-Disp.zip and submit the zipped file on Moodle2 with your
report.
Demo the Project to your Lab Instructor.
Arduino Project – Multi-purpose Infrared Remote Control
Adapt the instructions below for the Uno to the Max32
Infrared remote controls are commonly used to control TVs, DVD players, stereos, cable boxes, and so on…
Infrared remote controls send a series of binary pulse code using infrared light signals. The signal between a
remote control handset and the device it controls consists of pulses of infrared light, which is invisible to the
human eye, but can be seen through a digital camera, video camera, or a phone camera.
The transmitter in the remote control handset sends out a stream of pulses of infrared light when the user
presses a button on the handset. A transmitter is often a light emitting diode (LED) which is built into the
pointing end of the remote control handset. The infrared light pulses form a pattern unique to that button.
The receiver in the device can be programmed to recognize the pattern and causes the device to respond
accordingly.
Connect the Arduino Uno R3 compatible board with a breadboard and a passive buzzer, using jumper wires.
The following figure shows that the positive terminal of the buzzer is connected to the Uno’s digital I/O pin 7
and the negative terminal is connected to the ground.
Connect the Arduino Uno R3 compatible board with a breadboard using jumping wires, and serially connect
a 220Ω resistor with one light emitting diode (LED). The following figure shows that the positive terminal of
the LED is connected to the 220Ω resistor, and the 220Ω resistor is connected to the Uno’s digital I/O pin 8
and the negative terminal of the LED is connected to the ground.
Repeat the steps above again and connect a different color LED to the Uno’s digital I/O pin 3, 4, 5, 6, 9, 10, and
11. Install a total of 8 LED lights (using I/O Pins 3, 4, 5, 6, 8, 9, 10, and 11) in one line.
Connect the 3 pins of the infrared receiver sensor to the bread board and add jumping wires as follows:
•
•
•
Connect VOUT to the Uno’s digital I/O pin 2.
Connect GND to the Uno’s GND.
Connect VCC to the Uno’s +5 v source. Ensure the power source of the Uno board is set to 5v.
Write a c program, using the Arduino’s integrated development environment (IDE), to utilize an infrared
remote controller to simulate the following:
1.
2.
3.
4.
A piano keyboard.
Garage door opener.
Sound volume controller.
Play a song.
The remote control buttons and actions are listed below:
Simulation
Piano
keyboard
Mode #
Press
Button
then
Initialize Mode 1 with all
the lights turned off.
Action
Play C note (frequency: 1047) for 0.5 sec. Turn on
light #1 during the note plays.
Play C sharp / D flat note (frequency: 1109) for 0.5
sec. Turn on light #1 and #2 during the note plays.
Play D note (frequency: 1175) for 0.5 sec. Turn on
light 2 during the note plays.
Play D sharp / E flat note (frequency: 1245) for 0.5
sec. Turn on light #2 and #3 during the note plays.
Play E note (frequency: 1319) for 0.5 sec. Turn on
light #3 during the note plays.
Play F note (frequency: 1397) for 0.5 sec. Turn on
light #4 during the note plays.
Play F sharp / G flat note (frequency: 1480) for 0.5
sec. Turn on light #4 and #5 during the note plays.
Play G note (frequency: 1568) for 0.5 sec. Turn on
light #5 during the note plays.
Play G sharp / A flat note (frequency: 1661) for 0.5
sec. Turn on light #5 and #6 during the note plays.
Play A note (frequency: 1760) for 0.5 sec. Turn on
light #6 during the note plays.
Play A sharp / B flat note (frequency: 1865) for 0.5
sec. Turn on light #6 and #7 during the note plays.
Play B note (frequency: 1976) for 0.5 sec. Turn on
light #7 during the note plays.
Garage
Door
Opener
Press
then
The
button
simulates the garage door
opener button.
Initialize Mode 2 with all
the lights turned off to
simulate a closed garage
door.
Sound
Volume
Control
Press
then
Initialize Mode 3 with all
the lights turned off.
Press this button the first time should sequentially
turn on an additional light per second, starting from
light #1. Play frequency 466 continuously to simulate
the garage door opening, until all the lights are on.
Press this button when all the lights are on should
sequentially turn off one light per second, starting
from light #8. Play frequency 156 continuously to
simulate the garage door closing until all the lights
are off.
Press this button during the garage door opening up
should pause the garage door. The buzzer should
stop humming and the number of lights turned on
should stop increasing. The next time when this
button is pressed, the garage door should move
down.
Press this button during the garage door closing
down should pause the garage door. The buzzer
should stop humming and the number of lights turned
off should stop increasing. The next time when this
button is pressed, the garage door should move up.
Press this button each time will sequentially
increment the number of lights on by 1, starting from
light #1. This button has no effect after all 8 lights are
on.
Press this button each time will sequentially
decrement the number of lights on by 1, starting
from light #8. This button has no effect after all 8
lights are off.
Welcome to reuse the music and light show from
Homework 4.
Play music
n/a
and light
Press
then
show
The millis() function in the Arduino Library (http://arduino.cc/en/reference/millis ) can be used to track time in
milliseconds after the program starts. The millis() function returns the number of milliseconds since the
Arduino board began running the current program. This number will go back to zero after approximately 50
days. To calculate the actual game time in milliseconds, the value returned by the millis() function call should
be compared to a value returned by a previous call to the millis() function. The millis() function call output is a
unsigned long data type.
IMPORTANT:
The Arduino IRremote library functions and the Arduino built-in tone() and noTone() functions can NOT be
used in the same program! Functions to send/receive infrared light frequency and the functions to produce
sound frequency are both trying to control the same hardware interrupt timer 2 on the Arduino board.
The workaround is to use the NewTone library functions to produce sound. The NewTone library functions
use the hardware interrupt timer 1 to produce the desired frequency.
To use the <NewTone.h> library functions, include the NewTone.h header file in the program.
The syntax of the NewTone() function call is:
NewTone(pin#, frequency, duration);
Using the <IRremote.h> library functions, we can capture and decode the signals send from each infrared
remote control buttons (for example):
#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume();
}
delay(100);
}
The IR decoded value of each button from the SainSmart remote control is listed below. The button IR
decode results need to be defined in your program for your program to recognize the IR signal.
Infrared Remote Control Button
Mode
+
-
Decoded Value in Hexadecimal Format
0xFF629D
0xFF906F
0xFFA857
0xFF9867
U/SD
0
1
2
3
4
5
6
7
8
9
0xFFB04F
0xFF6897
0xFF30CF
0xFF18E7
0xFF7A85
0xFF10EF
0xFF38C7
0xFF5AA5
0xFF42BD
0xFF4AB5
0xFF52AD
Zip the entire Sketch folder for Project Infrared Remote Control.
Rename the folder to LastNameFirstName_Proj_IR-Remote.zip and submit the zipped file on Moodle2 with
your report.
Demo the Project to your Lab Instructor.
Arduino Project – a Keypad Controlled Pink Panther and Detective Game
Adapt the instructions below for the Uno to the Max32
A keypad is a set of buttons arranged in a block or “pad” which usually bear digits, symbols and usually a
complete set of alphabetical letters. Keypads are commonly found on many alphanumeric keyboards
and on other devices such as calculators, telephones, microwaves, combination locks, and digital door
locks, which require mainly numeric input.
The keypad that comes with the Starter Kits has buttons arranged in 4 rows and 4 columns. A
connection is made between the corresponding row line and column line when a button is pressed.
When none of the button is pressed, there is no connection between the row or column lines.
Connect the left most pin of the keypad to the Uno’s digital I/O pin 9 and connect the remaining pins
in succession, so that the right most pin of the keypad connects to the Uno’s digital I/O pin 2.
Since the keypad is using Uno’s digital I/O pin 2 through 9, the buzzer and lights can’t use digital I/O pin
2 through 9.
Connect the buzzer to the Uno’s digital I/O pin 10.
Install a circle of 8 LED lights on the bread board. The following light numbers can be used to identify
the location and wiring of each light:
3
4
2
1
5
6
8
7
Connect 3 LEDs to the Uno’s digital I/O pin 11, 12, and 13 to represent the LED light #1, #2, and #3.
The Arduino IDE Serial data connections, Serial.begin() and Serial.println() functions, use digital I/O pin
0 and 1. Therefore, if we want to use the 9600 baud rate window to print debug statements, the use of
digital I/O pin 0 and 1 should be avoided.
The 6 Analog pins (A0 – A5) on the Uno board can also be used to send digital output as digital pins
14-19.
The analog pins are mapped to be extra digital pins as follows:
Analog Pin Number
A0
A1
A2
A3
A4
A5
Digital Pin Number
14
15
16
17
18
19
Connect the fourth (4th) LED to the Uno’s analog pin A2 (digital I/O pin 16) to represent the light #4.
Connect the fifth (5th) LED to the Uno’s analog pin A3 (digital I/O pin 17) to represent the light #5.
Connect the fifth (6th) LED to the Uno’s analog pin A3 (digital I/O pin 18) to represent the light #6.
Connect the fifth (7th) LED to the Uno’s analog pin A3 (digital I/O pin 19) to represent the light #7.
Connect the fifth (8th) LED to the Uno’s analog pin A3 (digital I/O pin 15) to represent the light #8.
Write a c program, using the Arduino’s integrated development environment (IDE), to make a Pink
Panther and Detective Game that utilizes a keypad to obtain the player inputs.
Keypad #
1
2
4
3
A
6
7
8
*
0
9
D
The following table contains the keypad key functions:
Keypad
Key
A
D
*
0
7
4
1
2
3
6
9
8
Function
Start the game.
End the game and report score. Blink light 1 and buzz frequency 262 for 50 ms for each score
point.
Turn on all 8 lights when not playing the game.
Turn off all 8 lights when not playing the game.
During the game, if light 1 is on, turn off light 1,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 2 is on, turn off light 2,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 3 is on, turn off light 3,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 4 is on, turn off light 4,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 5 is on, turn off light 5,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 6 is on, turn off light 6,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 7 is on, turn off light 7,buzz frequency 262 for 25 ms., and score 1 pt.
During the game, if light 8 is on, turn off light 8,buzz frequency 262 for 25 ms., and score 1 pt.
Install a circle of 8 lights.
The following table suggests the mapping between the light numbers and the Keypad numbers.
Light #
3
4
2
1
8
Keypad #
5
1
6
4
7
7
3
2
6
8
9
The program should automatically turn on each light by looping through the circle clockwise one at a
time.
When the program starts, each light stays on for 1 second during the first circle. During the second
circle, each light stays on 90% of the previous duration, 900 milliseconds (1000 ms * 90 / 100 = 900
ms). During the third circle, each light stays on 810 milliseconds (900 ms * 90 / 100 = 810 ms). The
lights loop faster and faster after each circle by reducing the duration 10% each circle.
The millis() function in the Arduino Library (http://arduino.cc/en/reference/millis ) can be used to track
time in milliseconds after the game starts. The millis() function returns the number of milliseconds since
the Arduino board began running the current program. This number will go back to zero after
approximately 50 days. To calculate the actual game time in milliseconds, the value returned by the
millis() function call should be compared to a value returned by a previous call to the millis() function.
The millis() function call output is a unsigned long data type.
The player can turn off the light by pressing the keypad key when the light is on. A successful hit
scores 1 point. Pressing the keypad key when the light is off will not score any point.
Add sound effect from the buzzer when each light turns on.
An example Pink Panther sound effect can be as follows:
Situation
Light 1 turns on
Light 2 turns on
Light 3 turns on
Light 4 turns on
Light 5 turns on
Light 6 turns on
Light 7 turns on
Light 8 turns on
Frequency
1109 then 1175
1319 then 1397
1109 then 1175
1319 then 1397
1865 then 1760
1175 then 1397
1760 then 1661
1661
Duration in Milliseconds
25 then 75
25 then 75
25 then 75
25 then 75
25 then 75
25 then 75
25 then 75
100
Additional game functions are always welcome!
Zip the entire Sketch folder for Project Keypad Game.
Rename the folder to LastNameFirstName_Proj_KeyGame.zip and submit the zipped file on Moodle2
with your report.
Demo the Project to your Lab Instructor.