You are on page 1of 50

Why Arduino?

~ An Introduction
Ed Nisley KE4ZNU softsolder.wordpress.com ~ MHV Linux Users roup !e"ru#ry $%&%
1/50

Upcoming Events
'(y )ou *(ould +#re '(ere ,t -ll .e/#n Microcontrollers 0ro/r#mmin/ Model 0ro/r#mmin/ 1,) #d/etry otc(#s
0roposed -rduino 3ower ;No <el#tion...= Mil#n ,t#ly
2/50

+ommerci#l *(ields *(ow2n23ell

(ttp455www.desi/n"oom.com5we"lo/5c#t5657iew589$%5d#niel2li"es:ind2#rduino2tower.(tml

Why You Should Care


3ypic#l pro/r#mmin/ excludes 3(e <e#l 'orld
Virtu#li>#tion is t(e ;?ld= New 3(in/ H#rdw#re is ;#lle/edly= fun/i"le

E7eryt(in/ depends on ?t(er 0eople@s +ode


Hidden complexity rem#ins complex 1e"u//in/ 5 isol#tion "ecomes difficult

3(e New"ie pro"lem


'(ere do t(ey st#rtA '(y s(ould t(ey c#reA
3/50

hello, world <!--

This is the source file for the "Hello World of AJAX" tutorial Please visit http://www !"#a$icAJAX co$ for $ore %reat AJAX source code a#d tutorials &op"ri%ht '(() *"a# +$ith / ,-. Tech#ical / ,-. /roup --0 <ht$l0 <head0

The Ne !ie "ro!lem

-(2(em...

</head0 <4od"0

<title0The Hello World of AJAX</title0 <script la#%ua%e1"Java+cript" t"pe1"te2t/3avascript"0 ///ets the 4rowser specific X$lHttp*e5uest 643ect fu#ctio# %etX$lHttp*e5uest643ect78 9 if 7wi#dow X:;Http*e5uest8 9 retur# #ew X:;Http*e5uest78< //=ot >? @ else if7wi#dow ActiveX643ect8 9 retur# #ew ActiveX643ect7":icrosoft X:;HTTP"8< //>? @ else 9 //!ispla" "our error $essa%e here //a#d i#for$ the user the" $i%ht wa#t to up%rade //their 4rowser alert7"Aour 4rowser does#Bt support the X$lHttp*e5uest o43ect Cetter up%rade to Direfo2 "8< @ @ ///et our 4rowser specific X$lHttp*e5uest o43ect var receive*e5 1 %etX$lHttp*e5uest643ect78< //>#itiate the as"#cro#ous re5uest fu#ctio# sa"Hello78 9 //>f our X$lHttp*e5uest o43ect is #ot i# the $iddle of a re5uest, start the #ew as"#cro#ous call if 7receive*e5 read"+tate 11 - EE receive*e5 read"+tate 11 (8 9 //+etup the co##ectio# as a /?T call to +a"Hello ht$l //True e2plicit" sets the re5uest to as"#cro#ous 7default8 receive*e5 ope#7"/?T", B+a"Hello ht$lB, true8< //+et the fu#ctio# that will 4e called whe# the X$lHttp*e5uest o43ects state cha#%es receive*e5 o#read"statecha#%e 1 ha#dle+a"Hello< //:aFe the actual re5uest receive*e5 se#d7#ull8< @ @ //&alled ever" ti$e our X$lHttp*e5uest o43ects state cha#%es fu#ctio# ha#dle+a"Hello78 9 //&hecF to see if the X$lHttp*e5uests state is fi#ished if 7receive*e5 read"+tate 11 -8 9 //+et the co#te#ts of our spa# ele$e#t to the result of the as"#cro#ous call docu$e#t %et?le$e#tC">d7Bspa#GresultB8 i##erHT:; 1 receive*e5 respo#seTe2t< @ @ </script0 <!-- &licFi#% this li#F i#itiates the as"#cro#ous re5uest --0 <a href1"3avascript:sa"Hello78<"0+a" Hello</a0<4r /0 <!-- used to displa" the results of the as"#cro#ous re5uest --0 <spa# id1"spa#Gresult"0</spa#0

</ht$l0

</4od"0

4/50

The Ne !ie "ro!lem


B-ll you need to do is ...C
Nested #"str#ctions M#ny simult#neous le#rnin/ cur7es

'(en it "re#:sD it@s really "ro:en


3oo m#ny mo7in/ p#rts

No 7iscer#l rew#rd
,t@s Eust some pixels +risis of risin/ expect#tions
5/50

Where It All #egan


M,3 -, L#" F G9%s
-d7#nced wid/etry

M,3 Medi# L#" F G8%s


Hum#n #ccessi"le 1irect m#nipul#tion 0ro/r#mm#"le stuff <#pid prototypin/ LE ?H MindstormsHD et #l
6/50

"rocessing
Processing was founded by Ben Fry and Casey Reas in 2001 while both were John Maeda's students at the MI Media !ab"
www"#rocessing"org$about

www.mic(#el2(#nsmeyer.com

7/50

"rocessing
Processing is
a si%#le #rogra%%ing en&iron%ent that was created to %a'e it easier to de&elo# &isually oriented a##lications with an e%#hasis on ani%ation and #ro&iding users with instant feedbac' through interaction"
(ttp455processin/.or/5le#rnin/5/ettin/st#rted
8/50

Wiring
(ernando )Barrag*n+ started ,iring in -u%%er 200. and he has been de&elo#ing it since" ,iring builds on Processing /
www.wirin/.or/.co5#"out.(tml www.p#"lo/indel.com5$%%65%95s#ms#2el2(ex#podo

9/50

Wiring
,iring is
both a #rogra%%ing en&iron%ent and an electronics #rototy#ing in#ut$out#ut board

for e0#loring the electronic arts and tangible %edia"


www.wirin/.or/.co5#"out.(tml www.sp#r:fun.com5commerce5productIinfo.p(pAproductsIidJ944
10/50

Arduino
In winter 20012 )Massi%o+ Ban3i was discussing the #roble% with 4a&id Cuartielles / )(+is students """ couldn't find an ine0#ensi&e2 #owerful %icrocontroller to dri&e their arty robotic #ro5ects
(ttp455#rduino.cc5en5M#in5-rduino.o#rd*eri#l www.wired.com5tec("i>5st#rtups5m#/#>ine5&K2&&5ffIopenm#nuf#cturin/

11/50

Arduino
he %icrocontroller """ is #rogra%%ed using
the 6rduino #rogra%%ing language 7based on ,iring8 and the 6rduino de&elo#%ent en&iron%ent 7based on Processing8
www"arduino"cc

(ttp455st#tic.sp#r:fun.com5im#/es5products5%%KKK2%L2L.Ep/
12/50

#e Care$ul Where You Sit

(ttp455www./ulli7erproducts.com5-rt51$L.(tml
13/50

%pen&Source 'ard are


6rduino is # M
9duino is not

+ommerci#l copies
Licensin/ fees

Except in sl#c: ,0 re/imes

1eri7#ti7es #re fine


Use # different n#me

14/50

%pen&Source 'ard are


Fino.2: ;top=
N&.O% P N$8 s(ip F 3(#il#nd

6R4;I<= 200> 4ue%ilano&e ;"ottom=


Bm#nuf#ctured "#sed on #uduino duemil#no7e reference desi/nC B'ill Not *(ip to ,t#lyC N$9 P N% F Hon/ Kon/

*p#r:fun /enuine licensed


NL% P N9 s5( F .oulder +?
15/50

'ello World
int ledPin = 13;

Q "lin: ...

void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, H !H); dela"(1###); digitalWrite(ledPin, $OW); dela"(1###); }
16/50

(icrocontrollers

3(is. ,s. Not. -. 0+.


17/50

ATmega)*+
&K :. pro/r#m memory
&4 :. #7#il#"le for user code $ :. for "ootlo#der 5 self2pro/r#mmer

& :. <-M ;82"it d#t# p#t(=


Vol#tile d#t# memory V#ri#"les P *t#c: P He#p...

O&$ . EE0<?M
Non7ol#tile write?occasionally d#t# memory &%% : write cycles ;R$%% seconds #t full t(rottle=
18/50

ATmega,-+
L$ :. pro/r#m memory
L% :. #7#il#"le for user code $ :. for "ootlo#der 5 self2pro/r#mmer

$ :. <-M ;still 82"it d#t# p#t(=


Vol#tile d#t# memory V#ri#"les P *t#c: P He#p...

& :. EE0<?M
Non7ol#tile write?occasionally d#t# memory &%% : write cycles ;R$%% seconds #t full t(rottle=
19/50

'ard are I.%


&L 1i/it#l ,5? "its
$ J seri#l 3x15<x1 1irect LE1 dri7e

?ne LE1...

K B-n#lo/C outputs
0ulse2widt( modul#ted +(oose di/it#l or 0'M 82"it resolution

K -n#lo/ inputs
&%2"it resolution #t "est
Q "lin: ...
20/50

"rogramming
.#re *ilicon 3ec(niSues
1irect ,5? "it m#nipul#tion ,nterrupt (#ndlers ;experts onlyT= Very limited code port#"ility

Esc(ew ?"fusc#tion
H#rd memory limits +ount t(e cyclesT

,t@s surprisin/ly f#st


&K MH> cloc: R &K M,0*
21/50

'o /ast Is It?


*witc( .ounce
K$.8 ms R& million instructions 3(#t@s # lot ...

E7en in +

Users #re surprised


3(ey@re not en/ineers

3(#t@s ?K ...

,t@s still em"edded pro/r#mmin/


22/50

%ther "eople0s Code


M#ny li"r#riesT
Most wor: well
Bounce is a library for 6rduino / It debounces digital in#uts and %ore"
htt#@$$www"arduino"cc$#layground$Code$Bounce

M#ny functionsT
Most #re useful
.lin:4 86K "ytes

M#ny "ytesT
Most #re necess#ry

M#ny #ut(orsT
Most write /ood code...
P .ounce4 &444 "ytes
23/50

ATmega)*+
&K :. pro/r#m memory &4 :. #7#il#"le for user code $ :. for "ootlo#der 5 pro/r#mmer & :. <-M ;82"it d#t# p#t(= Vol#tile d#t# memory V#ri#"les P *t#c: P He#p... O&$ . EE0<?M Non7ol#tile write?occasionally d#t# memory &%% : write cycles ;R$%% seconds #t full t(rottle=
24/50

(icrocontrollers

3(is. ,s. Not. -. 0+.


25/50

"rogramming (odel
*m#ll proEects
3(ere ,s No <?M

*in/le2t(re#ded loop;=
0lus ,<U (#ndlers...

Not muc( ,5?


3(ere ,s No .us *0, V ,$+ /#d/ets

Not muc( d#t#


3(ere ,s No <-M
26/50

"rogramming (odel
,t@s .-*,+#lly +
?r +PP for 1ummies

,n t(e K,** style


1on@t "e too cle7er 1on@t "e too #"str#ct 1on@t "e too /ener#l

No pl#ce for

it

?ne source file


)ou c#n (#7e more...
27/50

"rogramming (odel
void loop78 9 i#t *aw+e#se< i#t *esista#ce< float Dloat*es< float 2<

-ll t(e usu#l suspects H#rdw#re ,5?

*aw+e#se 1 a#alo%*ead7P>=GH+?=+?8< // ( I(', cou#ts if 7*aw+e#se <1 I8 9 // ver" low values $ea# ope# circuit *esista#ce 1 *?+>+TA=&?GCA!< @ else 9 // so$e sort of resista#ce is co##ected *esista#ce 1 ;i#=u$erator / *aw+e#se J ;i#6ffset< // tr" li#ear fit if 7*esista#ce 0 *?+>+TA=&?GC*?AK8 9 // out of li#ear ra#%e, use 5uadratic 2 1 +caleA!& / *aw+e#se< // %et plotti#%-scale I/A!& values Dloat*es 1 2 L 7&oeffA L 2 J &oeffC8 J &oeff&< // floati#% poi#t value *esista#ce 1 +cale*esista#ce L Dloat*es J ( .< // 4acF to i#te%er @ if 77*esista#ce 0 *?+>+TA=&?GCA!8 EE 7*esista#ce 11 (8 8 9 // out-of-ra#%eM *esista#ce 1 *?+>+TA=&?GCA!< @ @

!#ncy comput#tions #re ?K "ut c#n "e #c(in/ly slow

28/50

"rogramming (odel
T&&*IC 1 (2((< // stop Ti$erI clocF for re%ister updates // &lear 6&IA o# $atch, P-D &orr PW: :ode: lower W/:I2 1 (( T&&*IA 1 (2N( E (2((< // >f push-pull drive, set 6&IC o# $atch Oif PP+HGPP;; T&&*IA E1 (2,(< Oe#dif >&*I 1 P?*>6!GT>&K+< 6&*IA 1 P?*>6!GT>&K+ / '< 6&*IC 1 P?*>6!GT>&K+ / '< T&=TI 1 6&*IA - I< // PW: period // 6= duratio# 1 drive pulse width 1 .(Q !& // ditto - use separate load due to te$p 4uffre% // force i$$ediate 6&*I2 co$pare o# #e2t ticF

0l#n on some Uu#lity 3ime wit( t(e -tme/#&K8 1#t# .oo:

// upper W/:I2 1 I(, &locF +el 1 prescaler, start Ti$er I ru##i#% T&&*IC 1 (2I( E T&&*ICG&+'(<

29/50

Arduino I1E
)et -not(er ,1E
Very few fe#tures

*imple pro/r#ms
Ex#ctly t(e use case

'ritten in W#7#
GNuff s#id

BUse Extern#l EditorC


+lic: to uplo#d
30/50

1evelopment Cycle
'rite some code +ompile V uplo#d it
U*.5seri#l lin:

!ind errors
'(ereA HowA

,ter#te
Hidden errors...
31/50

"rogramming 2otchas
1on@t "e too cle7er
+ompiler errors...
he error %essage lu%# resulting fro% co%#iling that loo's li'e@ n %un&tion 'void setup()() error) 'OUTPUT( *as not de&lared in t+is s&ope n %un&tion 'void loop()() n %un&tion 'int ,ain()() ReallyA

Use ?0+ wit( c#re


*ome4 way cle7er

<#pid prototypin/
H#rdw#reD too

K,**T
'it( # 7en/e#nce...

(ttp455softsolder.wordpress.com5$%%65&%5%K5#rduino2"e2c#reful2wit(2t(e2preprocessor5
32/50

"rogramming 2otchas
6lthough the 6rduino language loo's li'e C and #arses li'e C and runs li'e C2 itBs not really C" ItBs a s#eciali3ed language gnawed on by a &ast con&ersion %onster and e&entually shat out as e0ecutable 6 %ega?style instructions"
(ttp455softsolder.wordpress.com5$%%65&%5%K5#rduino2"e2c#reful2wit(2t(e2preprocessor5
33/50

With That In (ind333

*imple proEects wor: perfectly ~ "ec#use ~ t(#t@s w(#t -rduino is #ll #"out
34/50

Arduino Application (odel H#rdw#re eSui7#lent of Unix2oid filter pro/r#m ~ 1o one t(in/D do it well ~ V, Not Em#cs
35/50

'ard are Shields


?t(er 0eople@s H#rdw#re
+ommerci#l 1,) :its V pl#ns

ZowieT

L#r/e "uildin/ "loc:s


Elimin#tes most solderin/ EconomicsA

?ne s(ield per proEect


3(ere ,s No .us

?ne +0U per proEect


36/50

Solar "o er 1ata 4ogger


?ptimum 0ower 0oint
V#ry lo#d current Me#sure ,D VD ' 1ump results to 0+
-c(tun/T O.O :. code

0#nel 7olt#/e "ooster


1emo circuitry

Notice t(e "o#rd si>eA +ircuit +ell#r Wune %6


37/50

Solar "o er 1ata 4ogger


3(is one didn@t wor:...
,nductor s#tur#tion -n#lo/ noise

Notice t(e "o#rd si>eA -n#lo/ 7s 1i/it#lA


-n#lo/ winsT

E7ery d#mn time

+ircuit +ell#r -pril %6


38/50

1osimeter Charger
Uu#dr#ture Encoder
Volt#/e #dEustment
4.4 :.

0'M B#n#lo/C output


H#rdw#re 0'M &4$O step2up X $%% V

+ircuit +ell#r -u/ %6

39/50

Capacitor ES5 (eter


+#p#citors (#7e < ;T=
-+2only property
4.8 :.

*Su#re2w#7e dri7e
H#rdw#re timer

-n#lo/ input
H#rdw#re -1+

L+1 output +ircuit +ell#r ?ct %6


40/50

Te6 78- 5%( 1ump.#urn 9.9 :.


-ncient test eSuipment
<?M "it rot ;T= No commerci#l 7#lue

?ne2off proEect
*uccessT

!rom :nown2/ood <?M

+ircuit +ell#r 1ec %6

41/50

WW9# Transmitter Simulator


''V. 3ime +ode
<! only #t ni/(t Le#p ye#r 5 second 1*35E*3 c(#n/es
9.& :.

1e"u//in/ sc#ffold
1#t# Y & "#ud ;T=

3(is. ,s. Not. -. W#mmer.


<e#lly

+ircuit +ell#r !e" &%


42/50

Totally /eatureless Cloc6


-ll t(e time
?nly t(e time Ne7er wron/ No user inputs
&&.6 :. P O%% . d#t#

''V. p#rsin/
1#t# Y & "#ud ;T= No error detection "its

3r#ce5lo//in/ output +ircuit +ell#r -pr &%


43/50

Totally /eatureless Cloc6


?ne input "it
Noisy ''V. 3ime +ode P # few switc( "its

?ne output "it


*eri#l d#t# X LE1 di/its P # few de"u//in/ outputs

0lenty of code in "etween


1i/it#l *i/n#l 0rocessin/ 3ime:eepin/ ;tri7i#l=
44/50

Totally /eatureless Cloc6

45/50

Sho &n&Tell 0#ss #round some "o#rds -dmire t(e listin/s .e c#reful wit( t(e cloc:...
46/50

"laces To 2o
en.wi:ipedi#.or/5wi:i5-rduino www.medi#.mit.edu www.processin/.or/ www.wirin/.or/.co www.#rduino.cc www.sp#r:fun.com softsolder.wordpress.com
47/50

Copyright&ish Stu$$
0lenty of stuff lifted from 'i:ipedi# 0L !ree 1oc License &.$ ?t(er im#/es pro"#"ly copyri/(tedD "ut s(own V #ttri"uted (ere under Bf#ir useC Zw(#te7er t(#t is[ 3(e rest is my own wor: \ 3(is wor: is licensed under t(e +re#ti7e +ommons -ttri"ution2Noncommerci#l2*(#re -li:e L.% United *t#tes License. 3o 7iew # copy of t(is licenseD 7isit (ttp455cre#ti7ecommons.or/5licenses5"y2nc2s#5L.%5us5 or send # letter to +re#ti7e +ommonsD O4L How#rd *treetD Ot( !loor *#n !r#nciscoD +#liforni#D 64&%OD U*-.

48/50

Ed Nisley
*#y BN,**2leeCD #lt(ou/( we]re t(e (#lf2essed "r#nc( of t(e tree En/ineer ;ex 0E=D H#rdw#re H#c:erD 0ro/r#mmerD -ut(or 3(e Em"edded 0+]s ,*- .us4 !irmw#reD #d/etsD 0r#ctic#l 3ric:s

+ircuit +ell#r www.circuitcell#r.com !irmw#re !urn#ce ;&6882&66K= 2 N#styD /ru""y (#rdw#re "#s(in/ -"o7e t(e round 0l#ne ;$%%& ...= 2 -n#lo/ #nd <! electronics 1r. 1o""@s Wourn#l www.ddE.com Em"edded *p#ce ;$%%&2$%%K= 2 -ll t(in/s em"edded Nisley@s Note"oo: ;$%%K2$%%9= 2 H#rdw#re V softw#re collisions 1i/it#l M#c(inist www.(omes(opm#c(inist.net -lon/ t(e 2+ode '#y ;$%%8 ...= 2 2+ode #nd m#t(em#tics

49/50

I$ you can0t read this then ma6e a ne $riend : ay up $ront

50/50

You might also like