EGG 101LINTRODUCTION TO ENGINEERING EXPERIENCE

ukrainianlegalElectronics - Devices

Nov 2, 2013 (3 years and 7 months ago)

145 views

EGG
101
L

INTRODUCTION TO ENGINEERING EXPERIENCE


LABORATORY
2
:

Introduction to Arduino UNO and Danger Shield


Department of Electrical and Computer Engineering

University of Nevada, Las Vegas


Goal:


This section introduces the basic hardware involved in

the experiments and activities performed in
these laboratory exercises. Namely the Arduino UNO and Danger Shield.


Objectives:




Familiarize the user with the Arduino UNO



Familiarize the user with the Danger Shield


Overview and
Requirements:


Arduino De
velopment Platform


“Arduino is an open
-
source electronics prototyping platform based on flexible, easy
-
to
-
use
hardware and software. It's intended for artists, designers, hobbyists, and anyone
interested in creating interactive objects or environments.”

[
http://www.arduino.cc]


At its core, the Arduino development platform is
a microcontroller placed in a development shell
with all the necessary components to make it
easy to use. Arduino’s flagship platform is the
Arduino Uno, a microcontroller board bas
ed on
the Atmega328.
It ha
s 14 digital input/output
pins
, 6 analog inputs, a 16 MHz crystal oscillator,
a USB connection, a power jack, an ICSP header,
and a reset button.
It is all encompassing in
terms of supporting and using the
microcontroller. It ca
n be powered via an AC adapter or connected to a computer via USB,
which is also used for programming.


Microcontrollers


Microcontrollers are small integrated circuits that are
used in a wide variety of day to day household
products and applications. They consist of a
processor, memory, and programmable
inputs/output peripherals to control. You can think
of it as a small c
omputer on a single integrated
circuit, typically designed for embedded applications.
Microcontrollers are designed to execute specific tasks to control a system, such as
taking input from a remote control to change the channel on a television.


Microco
ntrollers have become quite common in many products such as appliances,
computer equipment, automobiles, and extending as far as industrial robotics. They
are designed to be self sufficient and cost effective, giving them a use in a large
variety of speci
fic tasks. If you can think of any digital interface used in many
household appliances or technological devices you can very safely assume that a
microcontroller is involved in the control of the interface.


Power


The Arduino Uno can be powered via the

USB connection or with an external power
supply. The power source is selected automatically.


External (non
-
USB) power can come either from an AC
-
to
-
DC adapter (wall
-
wart) or
battery. The adapter can be connected by plugging a 2.1mm center
-
positive plug
into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin
pin headers of the POWER connector.


The board can operate on an external supply of 6 to 20 volts. If supplied with less
than 7V, however, the 5V pin may supply less than

five volts and the board may be
unstable. If using more than 12V, the voltage regulator may overheat and damage
the board. The recommended range is 7 to 12 volts.


The power pins are as follows:


VIN: The input voltage to the Arduino board when it's usi
ng an external power
source (as opposed to 5 volts from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if supplying voltage via the
power jack, access it through this pin.


5V: This pin outputs a regulate
d 5V from the regulator on the board. The board can
be supplied with power either from the DC power jack (7
-

12V), the USB connector
(5V), or the VIN pin of the board (7
-
12V). Supplying voltage via the 5V or 3.3V pins
bypasses the regulator, and can damag
e your board. We don't advise it.


3V3: A 3.3 volt supply generated by the on
-
board regulator. Maximum current draw
is 50 mA (milliAmps).


GND: Ground pins.


Memory


The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM
library).


Input and Output


Each of the 14 digital pins on the Uno can be used as an input or output
. They
operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an
internal pull
-
up resistor (disconnected by default) of 20
-
50 kOhms.


Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These
pins are
connected to the corresponding pins of the ATmega8U2 USB
-
to
-
TTL Serial
chip.


External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on
a low value, a rising or falling edge, or a change in value. See the attachInterrupt()
func
tion for details.


PWM: 3, 5, 6, 9, 10, and 11. Provide 8
-
bit PWM output with the analogWrite()
function.


SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication
using the SPI library.


LED: 13. There is a built
-
in LED connec
ted to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.


The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits
of resolution (i.e. 1024 different values). By default they measure from gr
ound to 5
volts, though is it possible to change the upper end of their range using the AREF pin
and the analogReference() function. Additionally, some pins have specialized
functionality:


TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication u
sing the Wire
library.


AREF. Reference voltage for the analog inputs. Used with analogReference().


Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.


[http://www.arduino.cc]


Danger Shield


The Danger Shield is a top mounted Arduino UNO shield
that equips a large variety of inputs and outputs to the
Arduino without the use of any kind of breadboard. Each
input/output is connected to the Arduino’s digi
tal and
analog pins.




Analog pins 0 to 2 connects to 3 individual 10k ohm
linear slide potentiometers output an analog value
between 0 and 1024.



Analog pin 3 is connected to a photocell. This
device chances resistance depending on the
amount of light it

is exposed to.



Analog pin 4 is connected to a temperature sensor which sends out an analog value
representative of the current ambient temperature.



Digital pins 2 and 9 are connected to a capacitve touchpad, which is able to sense
touch when pressure is a
pplied to the area.



Digital pin 3 is connected to a small 12mm round buzzer that operates in the 2kHz
range. It can be used to generate various sounds and even create simple music.



Digital pins 5 and 6 are connected to LED’s in series with a 330 ohm resis
tor. For
these labs the LED’s will be red and green respectively.



Digital pins 4, 7, and 8 are connected to the 8
-
bit shift register, which is used to drive
the 7 segment display.



Digital pins 10 to 12 are connected to momentary push buttons that send the

signal
low when buttons are pressed (low active).


The following exercises will display the use and function of the potentiometers and the capactive
sensor.


Components:




Arduino Uno



USB A
-
B Cable



Danger Shield



Host PC



Installed Arduino Uno drivers and
IDE



Provided Capacative Sensor Library.





Procedure:


Slider Potentiometers


1.

Attach the Danger Shield to the Arduino, making sure to properly align the pins. If you are
using an R3 revision of the Arduino UNO, there will be 2 pins on each side that
will have no
corresponding pins on the shield.




2.

Attach the Arduino UNO to the host PC with the use of the USB cable. Verify that the
drivers have been properly installed.


3.

Open the Arduino IDE and create a new sketch titled “Sliders”. Verify that the
correct COM
port is in use.


4.

Using the previous lab as a guide, verify and upload the following sketch to your Arduino
UNO:


// Global variables

int val = 0;


// Pin definitions

#define SLIDER1 0

#define SLIDER2 1

#define SLIDER3 2


void setup()

{


Ser
ial.begin(9600); //Start Serial Communication


Serial.println("Danger Shield Potentiometer Test");

}


void loop()

{


Serial.print("Sliders: ");


val = analogRead(SLIDER1);


Serial.print(" ");


Serial.print(val);


val = analogRead(SLIDER2);


Seria
l.print(" ");


Serial.print(val);


val = analogRead(SLIDER3);


Serial.print(" ");


Serial.println(val);


delay(300);

}


5.

Verify your results by sliding all 3 potentiometers. The value range should be between 0
and 1023.


Capacitive Sensor


1.

Download
and extract the CapSense.zip file included in this lab.


2.

Copy the extracted CapSense folder into the arduino “libraries folder”




3.

Attach the Danger Shield to the Arduino, making sure to properly align the pins. If you are
using an R3 revision of the Ard
uino UNO, there will be 2 pins on each side that will have no
corresponding pins on the shield.


4.

Attach the Arduino UNO to the host PC with the use of the USB cable. Verify that the
drivers have been properly installed.


5.

Open the Arduino IDE and create a
new sketch titled “CapSense”. Verify that the correct
COM port is in use.


6.

Using the previous lab as a guide, verity and upload the following sketch to your Arduino
UNO:


#include <CapSense.h> //Include the Cap Sense Library into our program


// Global
variables

int val = 0;

CapSense cs_9_2 = CapSense(9,2); //Initializes CapSense pins


void setup()

{


Serial.begin(9600); //Start Serial Communication


cs_9_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // Calibrates CapSense pin timing


Serial.println("Dang
er Shield Cap Sense Test");

}


void loop()

{


long start = millis();


long total1 = cs_9_2.capSense(30);


Serial.println(total1);


delay(10);

}


7.

Verify your results by pressing your thumb against the capactive sensor. The value reading
should incr
ease based on the pressure placed on the surface.


Demo and screenshots:





Test Your Understanding:

1.

What optimal voltage range that should be supplied to the Arduino board?

2.

How many digital pins does the Arduino have? What voltage and current do they
supply?

3.

How many analog pins are there? Define the SDA and SCL pins.