Professional Documents
Culture Documents
~ 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
(ttp455www.desi/n"oom.com5we"lo/5c#t5657iew589$%5d#niel2li"es:ind2#rduino2tower.(tml
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
-(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
No 7iscer#l rew#rd
,t@s Eust some pixels +risis of risin/ expect#tions
5/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
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
(ttp455www./ulli7erproducts.com5-rt51$L.(tml
13/50
+ommerci#l copies
Licensin/ fees
14/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
ATmega)*+
&K :. pro/r#m memory
&4 :. #7#il#"le for user code $ :. for "ootlo#der 5 self2pro/r#mmer
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
& :. EE0<?M
Non7ol#tile write?occasionally d#t# memory &%% : write cycles ;R$%% seconds #t full t(rottle=
19/50
?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
E7en in +
3(#t@s ?K ...
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
"rogramming (odel
*m#ll proEects
3(ere ,s No <?M
*in/le2t(re#ded loop;=
0lus ,<U (#ndlers...
"rogramming (odel
,t@s .-*,+#lly +
?r +PP for 1ummies
No pl#ce for
it
"rogramming (odel
void loop78 9 i#t *aw+e#se< i#t *esista#ce< float Dloat*es< float 2<
*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!< @ @
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
// 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
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
<#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
*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
ZowieT
1osimeter Charger
Uu#dr#ture Encoder
Volt#/e #dEustment
4.4 :.
39/50
*Su#re2w#7e dri7e
H#rdw#re timer
-n#lo/ input
H#rdw#re -1+
?ne2off proEect
*uccessT
41/50
1e"u//in/ sc#ffold
1#t# Y & "#ud ;T=
''V. p#rsin/
1#t# Y & "#ud ;T= No error detection "its
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
50/50