Intro to Arduino at Deezmaker by Qtechknow

Post on 19-May-2015

407 views 2 download

Tags:

description

This was my presentation for the Intro to Arduino class held at Deezmaker 3D Printer Store/Hackerspace 4/6/13. I, Quin/Qtechknow, taught this class along with my ArduSensor Fun Pack, which is available on my website, www.qtechknow.com. We went over some key concepts of Arduino, open source, and circuits. Enjoy!!!

transcript

Intro to Arduino Class

Deezmaker 3D Printer Store and Hackerspace

Taught by Quin

4/6/13

Saturday, April 6, 13

Thank you to SparkFun for sharing the original

presentation!

Saturday, April 6, 13

What is Open Source???

Open source is when you release your design files (a.k.a. the PCB files, schematic) to the public, so that

anyone that wants to learn more about the PCB, can learn for free. When you release files for a new project you have

made, but you remade/remixed the files that someone else made, you

have to credit them.

Saturday, April 6, 13

Schedule

• Getting started with Arduino and electronics• Project 1 & 2• Break• Project 3 & 4• Explaining More Code• Project 5 & 6• Q&A + Free Project Time

Saturday, April 6, 13

Arduino Board“Strong Friend” Created in Ivrea, Italy

in 2005 by Massimo Banzi & David CuartiellesOpen Source Hardware

Atmel ProcessorCoding is accessible/easy (C++, Processing)

Saturday, April 6, 13

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?

Saturday, April 6, 13

Saturday, April 6, 13

Arduino Shields PCB Built Shield Inserted Shield

Saturday, April 6, 13

Arduino Shields

Micro SD MP3 Trigger Joystick

Saturday, April 6, 13

ArduSensors - ‘Mini Shields’

Saturday, April 6, 13

ComponentsName Image Type Function Notes

Button Digital Input Closes or opens circuit

Polarized, needs resistor

Trimpot Analog Input Variable resistor

LDR Analog Input Variable resistor

Also known as photoresistor

Temp Sensor

Analog Input Variable resistor

Flex Sensor Analog Input Variable resistor

RGB LED Ooh... So pretty.

Dig. & Analog Output

16,777,216 different colors

Saturday, April 6, 13

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

Saturday, April 6, 13

Power (+5V) and Ground (GND)

Power is the current that goes through the circuit, and ground is the current return path (collector).

Always make sure that Power and Ground never touch directly, or the circuit will short, and become very hot.

Make sure to not use over 10V, just 5V, and 3.3V, so no shock will occur.

Saturday, April 6, 13

What’s a Breadboard?One of the most useful tools in an engineer or

Maker’s toolkit. The four most important things to remember:

• Breadboards are very easy to prototype with• A breadboard is easier than soldering• A lot of those little holes are connected, which

ones?• Breadboards can break, if you

force them too much.

Saturday, April 6, 13

What’s a Breadboard?

Saturday, April 6, 13

Analog and Digital• All Arduino signals are either Analog or

Digital • All computers including Arduino, only

understand Digital • We need a way to convert the analog

signals into digital signals, so that our Arduino can process them.

Saturday, April 6, 13

Analog to Digital Conversion

An ADC is a device that samples a continuous quantity of analog signals (sensor signals), compares it to the time, then outputs a digital signal to the Arduino. It then turns the digital signals into 1024 different values.

The ADC (analog) compatible pins on the Arduino are A0, A1, A2, A3, A4, and A5.

Saturday, April 6, 13

I/O, or Input/Output

Input is any signal entering an electrical system/Arduino.

Output is any signal exiting an electrical system.

Saturday, April 6, 13

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

Saturday, April 6, 13

Output

To output a signal that pretends to be analog(anywhere in between on and off), you will haveto use a PWM pin.

Use this code to output an ‘analog’ signal:analogWrite (pinNumber, value); Where value is a number 0 - 255.

PWM is available on Arduino Leonardo digital pins 3, 5, 6, 9, 10, 11, and 13, and marked with a ‘~’.

Saturday, April 6, 13

OutputUsing a Digital signal that pretends to be an Analog signal is called Pulse Width Modulation

Use Pulse Width Modulation, or PWM, for anything that requires a signal between HIGH and LOW (1-254, with 0 being off and 255 being on)

PWM turns the output on to off very fast, so fast that we can’t see it. By changing the 0 - 255 #, we can change the width of these signals.

Saturday, April 6, 13

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

Saturday, April 6, 13

Arduino IDE

The Arduino IDE (Integrated Development Environment) is where we develop our code, and deploy/upload the code to the Arduino Leonardo Board. You can download the latest software here:

Arduino 1.0.4: http://arduino.cc/en/main/software

Saturday, April 6, 13

Installing Drivers for Mac

The first time you plug a Leonardo into a Mac, the "Keyboard Setup Assistant" will launch. There's nothing to configure with the Leonardo, so you can close this dialogue by clicking the red button in the top left of the window.

Saturday, April 6, 13

Installing Drivers for Windows

This method has been tested on Windows XP and 7:

• Plug in your board and wait for Windows to begin its driver installation process. If the installer does not launch automatically, Navigate to the Windows Device Manager (Start>Control Panel>Hardware) and find the Arduino Leonardo listing. Right click and choose Update driver.

• If prompted to search for drivers online, choose "No, not this time". And click Next

Saturday, April 6, 13

Installing Drivers for Windows

Saturday, April 6, 13

Installing Drivers for Windows

• When asked to install automatically or from a specific location, select "Install from a list or specific location" and press Next

Saturday, April 6, 13

Installing Drivers for Windows

• Choose "Search for the best driver in these locations", and check the box "incude this location in the search". Click the Browse button and navigate to your Arduino 1.0.1 or later installation. Select the drivers folder an click OK

Saturday, April 6, 13

Installing Drivers for Windows

Saturday, April 6, 13

Installing Drivers for Windows

Click Next. You will receive a notification that the Leonardo has not passed Windows Logo testing. Click on the button Continue Anyway

Saturday, April 6, 13

Installing Drivers for Windows

• After a few moments, a window will tell you the wizard has finished installing software for Arduino Leonardo. Press the Finish button

(from arduino.cc)

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Board Type

Saturday, April 6, 13

Serial Port / COM Port

Saturday, April 6, 13

Which COM/Serial Port?Mac: /dev/tty.usbmodemfd131

Interchangeable #:

Windows: COM#Device Manager:

Start>ControlPanel>System &Security>Device Manager>Ports

Saturday, April 6, 13

Circuit 1: Basic Blink

Saturday, April 6, 13

How to get the sketch:

Go to File>Examples>01.Basics>Blink

Saturday, April 6, 13

39Saturday, April 6, 13

Parts of the Sketch

Saturday, April 6, 13

void setup() {}

41Saturday, April 6, 13

void loop ( ) { }

Saturday, April 6, 13

Why do I make a comment?

• Comments are great ways to remind you what you did, teach other people what that code means, or to make a long description for your whole piece of code for licenses, date, and author

Saturday, April 6, 13

Comments

• Comments are ignored by the compiler/verifier

• Comments can be anywhere• Comments can start with

a // for a one-line comment • Another type of comment is

multiple lines and starts with a /* and ends with a */

Saturday, April 6, 13

Example of Comment:

Saturday, April 6, 13

InputInput is any signal entering an electrical system

•Both digital and analog sensors are forms of input•Input can also take many other forms: Keyboards, a mouse, buttons, light sensors, or just plain voltage from a circuit

Saturday, April 6, 13

Analog Input• To connect an analog Input to your Arduino, use

Analog/ADC Pins # 0 - 5

• To get an analog reading, use the code: analogRead(pinNumber);

• Analog Input varies from 0 to 1023 on an Arduino

Saturday, April 6, 13

Circuit 2: Analog Reading

Saturday, April 6, 13

Saturday, April 6, 13

Break

Saturday, April 6, 13

Digital Sensors/Digital Input• Digital Input could be a switch or a button

• To connect digital input to your Arduino use Digital Pins # 0 – 13 (Although pins # 0 & 1 are also used for serial)

• 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)

Saturday, April 6, 13

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 (for buttons, pressed or not)

• Signal is always either HIGH (On) or LOW (Off)

• Voltage signal for HIGH will be a little less than 5V on your Arduino Leonardo

• Voltage signal for LOW will be 0V, and HIGH will be 5V

Saturday, April 6, 13

Parts for Circuit 3:

Arduino LeonardoBreadboardPushbutton (2)LED (2)Resistor - 10K Ohm (2)Resistor - 330 Ohm (2)Jumper Wires

Saturday, April 6, 13

Circuit 3: Buttons

Saturday, April 6, 13

`

Saturday, April 6, 13

Saturday, April 6, 13

Semicolons

Semicolons are needed after every line of code, except for void setup(), void loop(), and a few others

Saturday, April 6, 13

Operators

The equals sign

= is used to assign a value

== is used to compare values

Saturday, April 6, 13

Operators

&& is “and”

|| is “or”

Saturday, April 6, 13

Variables

Basic variable types:

Boolean (on or off)Integer (a number)Character (a letter)

String (a phrase/many letters)

Saturday, April 6, 13

Declaring Variables

Boolean: boolean variableName;

Integer: int variableName;

Character: char variableName;String: stringName [ ];

Saturday, April 6, 13

Assigning Variables

Boolean: variableName = true;or variableName = false;

Saturday, April 6, 13

Assigning Variables

Boolean: variableName = true;or variableName = false;Integer: variableName =

32767;or variableName = -32768;

Saturday, April 6, 13

Assigning Variables

Boolean: variableName = true;or variableName = false;Integer: variableName =

32767;or variableName = -32768;

Character: variableName = ‘A’;or stringName =

“Deezmaker”;Saturday, April 6, 13

Variable ScopeWhere you declare your variables

matters

Saturday, April 6, 13

Circuit 4: ArduSensor + LED

Saturday, April 6, 13

Circuit 4: ArduSensor+LED

Saturday, April 6, 13

Saturday, April 6, 13

Common Functions

pinMode(pin, kind); (declares pins)analogRead(pin); (reads an analog pin)digitalWrite(pin, state); (tells a pin to

turn on (5V), or turn off (0V)if() {} (tells something to do a function,

when something else happensfor() {} (tells something to do a function

over and over)

Saturday, April 6, 13

Setupvoid setup ( ) {

Inputs & Outputs are declared in setup, this is done by using the

pinMode functionThis particular example declares digital pin # 13

as an output, remember to use CAPS

Saturday, April 6, 13

If Statementsif ( this is true ) { do this; }

Saturday, April 6, 13

Ifif ( this is true ) { do this; }

Saturday, April 6, 13

Conditionalif ( this is true ) { do this; }

Saturday, April 6, 13

Actionif ( this is true ) { do this; }

Saturday, April 6, 13

Elseelse { do this; }

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here //this could be anything}

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here }

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here }

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here }

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here }

Saturday, April 6, 13

Basic Repetition

for (int count = 0; count<10; count++) {//for action code goes here }

Saturday, April 6, 13

Circuit 5: LED Bounce

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Circuit 6: Meter

Saturday, April 6, 13

Saturday, April 6, 13

Saturday, April 6, 13

Q&A and Project time

Saturday, April 6, 13