Intro to Arduino Revision #2
-
Upload
qtechknow -
Category
Technology
-
view
452 -
download
0
description
Transcript of Intro to Arduino Revision #2
Intro to Arduino Class !
Deezmaker 3D Printer Store and Hackerspace
Taught by Quin Etnyre
July 26, 2014
Thank you to SparkFun for sharing the original presentation!
What is Open Source?
• Release your design files to the public • Free access for anyone who wants to learn • Everyone gains knowledge, companies or
hobbyists • You are able to remake/remix the project to suit
your own needs • When you credit the original designer
What is the Arduino?Intended for anyone to create interactive projects
“Strong Friend” Created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles
Open Source Hardware Atmel 8-Bit Processor
Coding is easy for anyone to learn
Why do I want an Arduino?
Arduino is a 8-bit prototyping system that is easy for the modern developer, designer, hacker, kid, or someone that has no experience in this type of genre to use.
! But why is important to all of us?
Schedule• Introduction to Arduino and Installing Software • Project 1 • Electronics Concepts • Project 2 • Arduino IDE in Depth • Project 3 • Break • Project 4 • Explaining More Code • Project 5, 6, & 7 • Project Time with more ArduSensors
Kit Contents
Arduino IDE
The Arduino IDE (Integrated Development Environment) is where we develop our code, and upload the code to the Arduino Leonardo board. You can download the latest software here:
!Arduino 1.0.5:
bit.ly/arduinoide
Downloading Code
!
bit.ly/deezmakercode !
Put the downloaded folder on your desktop
Arduino Drivers
Mac: Click Red ‘X’ !!Windows XP / 7 / 8: !!!Windows XP / 7 Secondary Option: http://bit.ly/
arduino-windows
Board Type
Serial Port / COM Port
Which COM/Serial Port?Mac: /dev/tty.usbmodemfd131 !
Interchangeable #: !Windows: COM# Device Manager: !Start>Control Panel>System & Security>Device Manager>Ports
What’s a Breadboard?
Circuit 1: Basic Blink
19
Add more LEDs!
Arduino ShieldsLCD Touch RGB LED WiFi
ArduSensors - ‘Mini Shields’
Concepts of Electronics
• Polarity • Power / Voltage and Ground • Analog and Digital • Inputs and Outputs • PWM • Arduino IDE Review • Analog Inputs
Polarity
Polarity is when there are two or more different sides (or leads) of a component that have different qualities that can not be reversed.
! Examples: batteries, LEDs, buttons
Power / Voltage and Ground (GND)
Use only 5V or 3.3V in your projects
Power+
-Circuit
Analog and Digital• All Arduino signals are either Analog or Digital • All computers can only understand Digital • Digital Pins D0 - D13 on Arduino • Special pins that are ADC enabled (analog to
digital converter) we can connect sensors to • Analog Pins A0 - A5 on Arduino
I/O, or Input/Output
Input is any signal entering an electrical system/Arduino. !Output is any signal exiting an electrical system.
OutputOutput is always Digital
!To Output a Digital signal (On or Off) use this code: !digitalWrite (pinNumber, value);
!Where value is HIGH (on) or LOW (off), both in caps
Output
To ‘Fade’ an LED or to output a voltage in-between 0V and 5V, use PWM
!Use this code to output an ‘analog’ signal: analogWrite (pinNumber, value); Where value is a number 0 - 255. (0V to 5V) !PWM is available on Arduino Leonardo digital pins 3, 5, 6, 9, 10, 11, and 13, and marked with a ‘~’.
OutputOutput is always Digital, even when it’s P.W.M.
!For P.W.M. the Arduino pin turns on, then off very fast
!!P.W.M. Signal @ 25% P.W.M. Signal @ 75% P.W.M. Signal rising
Circuit 2:
31
Arduino IDE in Depth
• Parts of the Sketch • setup() • loop() • Comments • Analog Input
Parts of the Sketch
void setup() {}
34
!!
void loop ( ) { } !!
!
!!
!
!!
Example of Comment:
Comments
• Comments are ignored by the compiler/verifier
• Comments can be anywhere • Starts with a // for a one-line comment • Starts with a /* and ends with a */ for a
multiple-line comment • Great ways to remind you what you did, teach
other people what that code means
Analog Input• To connect an analog Input to your Arduino, use
Analog Pins #A0 - A5 !• To get an analog reading, use the code: analogRead(pinNumber); !• Analog Input varies from 0 to 1023 on an Arduino
Circuit 3: Analog Reading
Break
Digital Sensors/Digital Input• Digital Input could be a switch or a button • To connect digital input to your Arduino use Digital
Pins # D0 – D13 • Digital Input needs a pinMode command (in setup): pinMode(pinNumber, INPUT); Make sure to use caps for INPUT • To get a digital reading: digitalRead(pinNumber); • Digital Input values are only HIGH (On) or LOW
(Off)
Digital Sensors/Digital Input• Digital sensors are more straight forward than
Analog !• No matter what the sensor, there are only two
settings: On and Off !• Voltage signal for LOW (off) will be 0V, and HIGH
(on) will be 5V
Parts for Circuit 4:
Arduino Leonardo Breadboard Pushbutton (2) LED (2) Resistor - 10K Ohm (2) Resistor - 330 Ohm (2) Jumper Wires
Circuit 4: Buttons
`
OperatorsThe equals sign
!= is used to assign a value
!== is used to compare values
!&& is “and”
!|| is “or”
Variables
Basic variable types: !
Boolean (on or off) Integer (a number) Character (a letter)
String (a phrase)
Declaring Variables
Boolean: boolean variableName; !
Integer: int variableName; !
Character : char variableName; String: stringName [ ];
Assigning Variables
Boolean: variableName = true; or variableName = false;
Assigning Variables
Boolean: variableName = true; or variableName = false;
Integer: variableName = 32767; or variableName = -32768;
Assigning Variables
Boolean: variableName = true; or variableName = false;
Integer: variableName = 32767; or variableName = -32768;
Character : variableName = ‘A’; or stringName = “Deezmaker”;
Circuit 5: ArduSensor + LED
Setup void setup ( ) {
pinMode (13, OUTPUT); }!
!
!
Inputs & Outputs are declared in setup, this is done by using the
pinMode function This particular example declares digital pin # 13 as
an output, remember to use CAPS
!!
If Statements if ( this is true ) { do this; }
!
!
!!
!!
Basic Repetition !
for (int count = 0; count<10; count++) { //for action code goes here //this could be anything }
Circuit 6: LED Bounce
Circuit 7: Meter
Project Time with more ArduSensors