Arduino Uno - Teach Electronics
Download
Report
Transcript Arduino Uno - Teach Electronics
Getting Started With the Arduino Uno
Richard T. Vannoy II
[email protected]
[email protected]
http://www.TeachElectronics.com
What’s On The Flash Drive???
Arduino Flavors
Obsolete
LilyPad $20
Nano $26
Uno $37
Mega 2560 $70
Arduino Flavors
14 + 6 + 6 = 20
Obsolete
54 + 14 + 16 = 70
LilyPad $20
Nano $26
Uno $37
Mega 2560 $70
Pin Assignments
14 Digital I/O Pins
(pins 0-13)
Pin Assignments
DC Current Limit =
40 mA
Means you can drive
an LED or the base of
a transistor, but not a
motor or a relay or
other high current
device.
Pin Assignments
6 Analog In Pins
[Converts 0-5 Volts
to digital 0-1023]
(pins 0-5)
Pin Assignments
6 pins can be reprogrammed as
Analog Out Pins
(pins 11, 10, 9, 6, 5, 3)
Pin Assignments
~
Squiggly Line looks a little like
a sine wave, so is often used
to designate an AC or analog
signal.
6 pins can be reprogrammed as
Analog Out Pins
(pins 11, 10, 9, 6, 5, 3)
USB Port and AC Adapter
The USB Port supplies power to the board
and allows serial communications between
the board and the PCs Integrated
Development Environment.
USB Port and AC Adapter
If the user connects a standard 9 Volt adapter
to the power connector, Arduino will shift to
the adapter power supply.
USB Port and AC Adapter
Recommended input voltage: 7-12V
Input voltage limits: 6-20V (Less than 7 volts,
board may be unstable. More that 12 volts
may overheat and damage the board!)
Pin Assignments
vin: This pin
comes from the
external power,
whatever that is.
You can tap off
that power here
for other uses.
5V: This pin
comes from
the internal
regulated 5
volt supply.
Pin Assignments
3V3:
A 3.3 volt
supply from the
FTDI chip. Max
current draw =
50 mA.
Pin Assignments
3.3 Volt Power Supply
Uno Pin Assignments
GND: Ground pins
Pin Assignments
Pin 1 = TX Used to
transmit serial data.
Pin 0 = RX Used to
receive serial data.
Pin Assignments
Pins 3, 5, 6, 9,
10, 11 can be
used for PWM.
Pulse Width Modulation (PWM): A way of sending
variable width digital pulses that are seen as a
discrete DC voltage by DC motors. Controls the
effective voltage, therefore the speed of the motor.
Uno Pin Assignments
Pin 13
connects to a
built-in LED,
labeled “L”.
This LED lights
when pin 13 is
HIGH.
Pin Assignments
When receiving an analog input (say temperature),
you sometimes want to compare that reading with
some reference (say desired temperature). The REF
pin can supply that reference voltage.
Pin Assignments
Sending a LOW to
the reset pin will
reset the board.
Shields
•
•
•
•
•
•
•
•
•
Ethernet
Wifi
GPS
Data Logging
Cell
Video
Audio
Acelerometer
XBee
MP3
RS232
Smoke
Detector
Voltage
regulator
Integrated Development Environment (IDE)
As with any IDE, the software allows
you to:
- Write source code
(called sketches by Arduino )
- Compile and test code
- Load a program into the board
Integrated Development Environment (IDE)
This is your work space or sketch pad.
This is where you write the
source code for your programs.
Integrated Development Environment (IDE)
This is where the program provides status messages
and error messages for you when the compiler is
active or a program is being loaded into your
Arduino.
“Fade” tells you
that a program
named “Fade” is
presently loaded
into the IDE.
Arduino 1.6.7
is the version
number of the
app.
The Menu Bar
The Menu Buttons
…and the
standard Windows
Minimize,
Maximize and
Close Buttons
This button
opens a window
where you can
view serial
communications
between your
Arduino and the
PC.
This is the “Verify”
button that converts
your source code into
Hex code for loading
on the Arduino.
Control-R
This is the
“Upload” button
than sends your
compiled Hex
Code to the
Arduino.
Control-U
This is the “New
Sketch” button;
Similar to the
Windows
File New
menu selection.
This is the
“File Open”
button; Similar
to the Windows
File Open
menu selection.
This is the
“File Save”
button.
Blink LED Sketch
#define is a global searchand-replace. This says
“replace every occurance of
“LED_PIN” in this sketch with
“13””.
Blink LED Sketch
The setup() function is
required in every sketch. Use
it for setting up initial
values and things you want
done before the main program
starts
Blink LED Sketch
This says “Set up Pin 13 as an
output pin”.
Blink LED Sketch
The function loop() is
required in every sketch. When
the program starts, all the
code in loop() is executed
over and over until the board
is reset or power is lost.
Blink LED Sketch
This says “Send a one (5
volts) to Pin 13.” to turn the
LED on.
Blink LED Sketch
…and then delay for 1,000
milliseconds (One second).
Blink LED Sketch
This says “Send a zero (0
volts) to Pin 13.” to turn the
LED off.
Blink LED Sketch
This says “Send a one (5
volts) to Pin 13.” to turn the
LED on.
This program turns
on
Blinkthe
LEDLED
Sketch
for 1 second, then off for 1
second, and repeats this as
long as the program has power.
Too small
for you
to read
right
now, but
this is a
slightly
longer
program I
will walk
through.
A little
better
because I
turned
all text
to black.
Next I
will show
the
parts.
Lines 1-14 are one long
comment. It starts with the
/* on line 1, and ends with
the */ on line 14.
The three variables led,
brightness and fadeAmount are
all declared outside of any
function, making them global
variables, accessible by any
part of the program.
Only one thing in setup().
We want to set Pin 9 as the
pin that powers the LED in
this program.
Here is what loop() does:
1. Start with the LED
completely off (brightness 0).
2. Increase the brightness in
steps of 5 until 255 is
reached (LED is brightly lit).
3. Walk the brightness back
down in steps of 5 until it is
completely off.
4. Repeat 1 thru 3 forever.
Turn the LED off. (Brightness
was set at zero in line 17.)
Add 5 to brightness. (We will
be going 5, 10, 15, etc. each
time we return here, until we
get to 255.)
When we get to the top or
bottom of the brightness scale
(0 and 255) reverse the sign
on the fade amount to go in
the other direction.
Raise or lower the brightness
33 times per minute.
IDE Installation
1. Download the IDE from:
http://www.arduino.cc/en/Main/Software
And follow the installation instructions.
2. Install the USB drivers (They allow your
computer to talk to the board through the
USB port). In the “Found New Hardware”
Wizard, direct the wizard to the folder where
the IDE was installed. Look for the folder:
Drivers\FTDI USB Drivers
3. Launch the IDE.
IDE Installation
1. Download the IDE from:
http://www.arduino.cc/en/Main/Software
And follow the installation instructions.
USB drivers
allowasyour
The2.
.ccInstall
domainthe
is preferred
by many(They
cycling clubs,
well as churches
andcomputer
Christian organizations,
couldthrough
be an abbreviation
for
to talk tosince
the"CC"
board
the
"Christian Church" or "Catholic Church". Some open-source/openUSB
port).
In
the
“Found
New
Hardware”
hardware projects, such as the Arduino project, use a .cc for their
Wizard,
direct
the
wizard
to theforfolder
where
home
pages, since
"CC"
is the
abbreviation
"Creative
Commons",
whose
are installed.
used in the projects.
Business
owners in Southern
thelicenses
IDE was
Look for
the folder:
Massachusetts are rapidly adopting Cape Cod CC domains for local
Drivers\FTDI USB Drivers
identity. Canadian Club whiskey has also used .cc domains for
3. Launch
the IDE.
marketing
purposes.
Port Identification
• In “My Computer Properties”, navigate to
the “Device Manager” dialog box.
• Under “Ports (COM & LPT), look for an entry
like: “USB Serial Port (COMx)”, where x is
some COM port.
• In the IDE, select that port from the “Tools
Serial Port” menu to identify to the IDE which
port you are using.
The
End
Any questions?
• Richard T. Vannoy II
• [email protected]
• [email protected]
• http://www.TeachElectronics.com
57