Вы находитесь на странице: 1из 334

004

32.973.26
71

71 Arduino: m :
. . - .: -r, 2015. - 336 .: .
ISBN 978-5-9775-3585-4

Arduino.
Arduino.
Arduino IDE. ,
, ,
.
, , , ,
.
, ,
. m m.

.

4
32.973.26
:

.
.




Authorized Russian translation of the English edition of Exploring Arduino : Tools and Techniques for Engineering
Wizardry, ISBN 978-1-118-54936- 2013 John Wiley & Sons, lnc. Rights Reserved.
This translation pulished under license BHV-St Petersburg, 2015.
Exploring Arduino Tools and Techniques
for Engineering Wizardry, ISBN 978-1-118-54936- 2013 John Wiley & Sons, Inc. .
r "-r", 2015

04.02 15.
70100 1 /,6. . 27,09.
2000 . 703.
"-'', 191036, -, ., 20.
""
199034, -, 9 , 12/28

ISBN 978-l-l 18-54936-0 (.) 2013 John Wiley & Sons, Inc
ISBN 978-5-9775-3585-4 (.) , , "-r", 201 S
......................................................................................................................... 15
............................................................................................ 16
................................................................................................................ 17
.......................................................................................................................... 19
m1 ......................................................................................................................... l9
.............................................................................................................................. 20
..................................................................................................................... 20
...................................................................................................... 20
..................................................................................... 21
Arduino?......................................................................................................................... 21
Open Source ............................................................................................................... 22
m ........................................................................................................ 22
"-"
m ................................................................................................ 23

1. ARDUIN0...... 25
1. , Arduino 27
l.l. Arduino ........................................................................................ 27
1.2. .................................................................................................................... 28
1.3. Atmel...................................................................................................... 28
1.4. ........................................................................................... 30
1.5. 1 - ................................................................ 31
1.6. ................................................................................................................. 31
1.7. Arduino ......................................................................................................................... 31
1.8. ............................................................................................... 36
l.8.l. Arduino IDE .................................................................................. 36
l.8.2. IDE m Arduino ............................................................................. 37
l.8.3. Blink ........................................................................................ 39
............................................................................................................................................ 41

2. -,
- .............................................................................. 42
2.1. ............................................................................................................... 43
2.2. m ..................................................................................... 43
2.2.l. ................................................................................................ 43

2.3. .................................................................................................. 44
2.3.1. ................................................................45
2.4. ...............................................................................47
2.5. .............................................................................................................48
2.6. - analogWriteO .............................................. 49
2.7. ......................................................................... 52
2.7.l. ....................................... 52
2.8. "" ..............................................................................................55
2.9. RG-......................................................... 58
............................................................................................................................................ 62

3. ....................................................................... 63
3.1. ..................................................................... 64
3.2. ...................................................................... 64
3.3. .............................................................. 65
3.4. Arduino. analogReadO ..............67
3.5. ........................................................................................... 67
3.6. ................................................................................... 71
3.7. ....................................................................... 73
3.8.
............................................................................................................... 75
3.9. ....................................................................................... 75
3.l . ......................... 77
............................................................................................................................................ 79

11. ...................................... 81
4. ................... 83
4.1. .................................................................................................. 84
4.2. .......................................................................................... 85
4.3. ...................................................... 86
4.4. ...............................................................................................86
4.5. ......................................................................... 87
4.6. ......................................................................................................... 87
4.7. ........................................88
4.8.
-................................................................................................................91
4.9. - ........................................................................................................... 92
4.1. - ..............................................................................................94
4.11. ..............................................................................................98
4.11.1. ............................................. 98
4.11.2. .................................................................................. 98
4.12. ...............................................................................................102
4.13. ...................................................................... 103
.......................................................................................................................................... 107

5. ..................................................................................... 108
5 .1. ...................................................................................................................... 109
5.2. ........................................................................................ 110
7

5.3. t .......................................................11
5.4. ................................................................................................111
5.5. ....................................................................................................... 112
5.6. .................................................................................................................114
5.6.1. ...............................................................................................114
5.6.2. ............................ 115
5.6.3. ...........................................................116
..........................................................................................................................................117

6. USB ....................................................... 118


6.1. Arduino ......................................................119
6.2. Arduino FTDI ..............................120
6.3. Arduino USB
.....................................................................................................122
6.4. Arduino , USB.... 123
6.5. Arduino USB-xoca .....................................................................124
6.6. Arduino ...............................................................................................124
6.6.1. ..................................................................................................124
6.6.2. ........................................................................126
6.6.3. ....................................................................... 127
6.6.4. Arduino .........................................................................................................128
6.6.5. ...... 129
Arduino ............................................................... 129
char int .................................................................................................130
......................................131
RG- .....................133
6.7. ..................................................................................136
6.7.1. Processing .....................................................................................................136
6.7.2. Processing ......................................................................................................136
6.7.3. Arduino Processing ................................................136
6.7.4. rssing- Arduino .............................................. 140
6.8. Arduino Leonardo (
32U4) ................................................................................................ l43
6.8.1. ....................................................................................................143
6.8.2. ......................................................... 147
6.8.3. .............................................................................................................148
..........................................................................................................................................151

7. .................................................................................. 153
7.1. ............................................................................................... 154
7.2. ......................................................... 155
7.3. 74595 ............................................................................................... 155
7.3.1. ................................................................ 155
7.3.2. r......................................................................156
7.3.3. Arduino r...................................................... 158
7.3.4. ................................... 160
7.4. r....................................... 161
7.4.1. " " ........................................................................................... 161
7.4.2. .................................................................. 162
.......................................................................................................................................... 165
8

111. II ........... 167


8. 12 ............................................................................. 169
2
8.1. 1 ......................................................................................... 170
2
8.2. 1 ...................................................................................... 170
8.2.1. .............................................................. 171
8.2.2. ........................................ 173
2
8.3. 1 ..................................................................................... 173
8.3.1. .............................................................................................. 173
8.3.2. ....................................................................... 174
8.3.3. ................................................................................................... 177
2
8.4. , , I c ................ 179
8.4.1. ............................................................ 179
8.4.2. ..................................................................................... 180
8.4.3. Processing ............................................................................ 182
.......................................................................................................................................... 185

9. SPI ............................................................................ 186


9.1. SPI ........................................................................................ 187
9.2. SPI ................................................................................................ 188
9.2.1. r SPI ...................................................................................... 189
9.2.2. SPI .................................................................................... 189
2
9.3. SPI I c .............................................................................................................. 190
9.4. I SPI .................................................................... 190
9.4.1. 4231 .................................................................................. 190
9.4.2. .......................................................................................... 193
9.4.3. ................................................................................................... 195
9.5.
I SPI ............................................................................................................. 197
9.5.1. .......................................................................................... 197
9.5.2. ............................................................................................. 198
.......................................................................................................................................... 201

10. 202
10.1. .................................................................... 203
10.2. LiquidCrystal ................................................................................................... 206
10.3. ................................................................................................... 206
10.4. ................................................................. 208
10.5. .................................................................................... 211
10.5.1. ........................................................................................... 212
10.5.2. -......................................................................... 213
10.5.3. .........................215
10.5.4. ......................................................... 216
10.5.5. : .................................................................................... 217
10.6. ......................................................................................... 221
.......................................................................................................................................... 221

11. ..... 222


11.1. : .................................................................. 223
11.1.1. : ....................................................................................................... 224
9

11.1.2. II ......................................................................................226
3,3 ............................................................................................................226
................................................................................... 226
............................................................................................... 226
I UART ............................................................... 227
UART............................................................ 227
11.2. ................................................................................................... 228
11.2.1. US-......................................................................... 228
( ) ............................................... 229
()..................................................... 229
11.2.2. I .....................................229
11.2.3. Windws- X-CTU .................................... 230
11.2.4. .................................... 234
11.3. ....................................................... 235
11.3.1. Arduino ........................................................................... 235
USB ................................................... 235
............................................................................................................236
.............................................................................................. 237
11.3.2. 1: ..........................237
11.3.3. 2: RG- .................................................................. 240
11.4. ...........................................................................................243
11.4.1. ......................................................................................................243
l l.4.2. ...................................................................................244
11.4.3. ..................................................................................... 245
11.4.4. ........................................................................................ 246
l l.4.5. .......................................................................................... 247
.......................................................................................................................................... 249

IV. JI I .................................. 251


12. ........................ 253
12.1. .......................................................................... 254
12.2. : ? ............................................... 255
12.2.1. ............................................................................................. 255
12.2.2. ................................................................................................255
12.2.3. .......................................................................................................... 255
12.2.4. ................................................................................................256
12.2.5. Arduino ........................................................256
12.3. ............257
12.3.1. ................................................... 257
12.3.2. ..............................................................................................................260
12.3.3. ....................................................... 262
12.4. .....................................................................................................264
12.4.1. .............................................................. 264
12.4.2. .................................................................................................264
12.4.3. .....................................................................265
12.5. m .....................................................................266
12.5.1. ..............................................................................266
12.5.2. ...............................................................266
..........................................................................................................................................269
10

13. SD ................................................. 270


13.1. .................................................................................... 271
13.1.1. SV- ................................................... 271
13.1.2. SD- ........................................................ 272
13.2. Arduino SD-............................................................................... 276
13.2.1. SD-.................................................................................. 276
13.2.2. SI- SD- ............................................................................................. 280
13.2.3. SD-....................................................................................................... 280
13.2.4. SD- ....................................................................................................... 285
13.3. ......................................................................... 288
13.3.1. ............................................................. 289
DS1307 .............................................................. 289
Arduino RTClib ............................................................................ 290
13.3.2. : .................................................................. 290
SD card shield RTC .................................................................. 291
RTC .................................................................. 291
13.4. ...................................................................................... 295
13.4.1. ...................................................................................................... 296
13.4.2. ....................................................................................... 296
13.4.3. .......................................................................... 300
.......................................................................................................................................... 301

14. Ji Arduino ....................................................... 302


14.1. , Arduino .................................................................................... 303
14.1.1. .......................................................................................................... 303
I- ............................................................................................................................... 303
- .......................................................................................................................... 304
HTML .................................................................................................................................. 304
................................................................................................................................... 304
GET/POST........................................................................................................................... 304
DHCP................................................................................................................................... 304
DNS ..................................................................................................................................... 305
............................................................................................................ 305
Arduino ................................................................................. 305
14.2. Arduino ........................................................................ 306
14.2.1. -.....................................306
14.2.2. -: .................................................................................306
14.2.3. Arduino-cepepa ..............................................................308
I- DHCP .............................................. 308
.............................................................................................. 309
- ..................................................................................... 309
14.3. Arduino .................................................................................. 313
14.3.1. Arduino ......................................................... 313
14.3.2. Arduino ............................................ 314
...................................................... 315
I- Arduino DHCP ..............................................................315
80 Arduino...................................................................316
DNS ..................................................................................... 316
11

14.4. ..................................... 317


14.4.1. Xively ............................................................................. 317
Xively....................................................................................... 317
...................................................................................................317
Xively HTTPClient..................................................................... .318
Arduino .......................................................................................... 319
Xively ................................................................... 320
- ............................................................................. 322
14.4.2. ............................................................................... 322
.............................................................. 323
........................................................................... 323
.......................................................................................................................................... 326

. ATmega
Arduino ............................................................................................... 327
................................................................................ 327
............................................................................................... 327
ATmega 328 ................................................................................... 329
Arduino ................................................................................................. 331

.............................................................................................. 333
,


m
,
.
"" ,
Comell University Sustainae Design,
(Green Building Councils).

,
, -
.
-, m
.
,
, .
D- MakerBot Replicator, ,
, NASA.
D- MakerBot Digitizer.
Machines Lab,
D-,
.
, .
ouTube
Arduino, .

,
. 2012
"
" (New Face ofEngineering).
Blum
Idea Labs LLC -.
-
.
http://www.jeremyum.com.
16


- , Arduino
2006 . 2005
Interactive Telecommunications Program () - ,
.
Arduino
Arduino. m
Making Things Talk 2011
, Arduino Starter Kit 2012 .
J

, Wiley ,
. ,

.
.
element 14
Arduino, .
- ,
.
,
. ,
.
, ,
, , .
. , .
, ,
,
.
. , , ,

.
Arduino , , Arduino
,
, .
Arduino,

. Arduino
, .
, ,
, ,

Arduino - .


Arduino,
.
, .
. - ,
, ,
. ,
.
,
.
20


.
,
. - ,
Arduino,
.
, ,
,
.
,
, .

.
Arduino .
, , ,
Arduino, ,

.



Arduino, ,
, . ,
, OS , Windows Linux
IDE Arduino.

:
+ ;
+ ;
+ ;
+ .


http://www.exploringarduino.com
.
,
. Wiley
wiley.com. -
21

Download code http://www.wiley.com/go/


exploringarduino. ISBN (
978-1-118-54936-).
. zi
, .


Arduino ,
, .
Arduino, .
Arduino:
Arduino -
http://www.arduino.cc/en/Reference/omePage;
Arduino -
http://www.jeremylum.com/category/arduino-tutorials;
Arduino Adafruit -
http://learn.adafruit.com/category/learn-arduino;
Arduino SparkFun -
http://learn.sparkfun.com/tutorials;
Arduino - http://www.arduino.cc/forum;
Arduino elementl4-
http://www.element14.com/community/groups/arduino.
,
Twitter (@sciguy14), , .

(http://www.jeremylum.com/contact), .

Arduino?
Arduino .
, -,
. , Arduino -
,
Arduino IDE. , , ,
( ) ,
Arduino "" .
, Arduino,
. ,
Arduino -
22

, ,
. Arduino
1. Arduino, -
,
Arduino.

Open Source
(Open Source),
.
, ,
Arduino .
- :
http://www.oshwa.org/definition.
, Arduino - ,
.
, Arduino,
,
Arduino.
Arduino,

. Arduino
Arduino ( Arduino)
. , Arduino
, . ,
MakerBot Replicator D-
Arduino Mega (http://www.thingiverse.com/thing:16058).
, ( )
GNU General Puic License (GPL),
, .


, ,
Arduino YouTube (http://www.
youtube.com/sciguy14)1
.
, ,
, ,

I Arduino .
http://www.youtube.com/AmperkaRU. - . .
23

(http://www.jeremylum.com/portfolio)
. Arduino,
,
.
, ,
.
. Arduino!


"-"

, ,
, Arduino Uno,
.
http://www.bhv.ru/books/193108.

"-" ""
. -
:
+ Arduino -
http://wiki.amperka.ru.
+ ,
, - http://www.youtube.com/AmperkaRU http://wiki.
mrk.ru/:-.


Arduino


1.
2.
3.


:
+ Arduino Uno;
+ US-.
1
http://www.exploringarduino.com/content/chl
, . ,
www.wiley.com/go/exploringarduino
Downloads.
EI \
Arduino,
"".
: http://amperka.ru/jeremy.
JEREMY n .
, ,
.

1.1. Arduino
Arduino
, Arduino.
, ,
. ,<,
, -
!

Arduino www.jeremyb
1
lum.com/2011/01/02/arduino-tutorial-series-it-begins/ Wiley.

I
: http://wiki.amperka.ru/eoypo:1-nepe-ar.
28 /. Arduino

Arduino
:
+ Arduino;
+ ;
+ Arduino - Arduino IDE.
Arduino.
Arduino - ,
, Arduino. , ,

. Arduino Uno.

Arduino, , .
Arduino .

1.2.
Arduino ,
(. 1.1):
+ Atmel;
+ US- ;
+ ;
+ -; (Debug, Power, Rx,
);
+ ;
+ (ICSP).

1.3. Atmel
Arduino - Atmel.
Arduino, Arduino Uno, ATmega.
Arduino Uno, . 1.1, ATmega 328.
Due, R
Cortex.
.
Arduino :
- (ADCs), -,
( I2 c SPI) .
.
Tmega
16 .
.
.....

-

,


(D


S
1
ICSP (D
::::

----- 2


USB


s
ATmega 328
s



7-12 -

. 1.1. Arduino Uno

1\)
(
30 /. Arduino

Arduino (Debug),
13, (
) .

1.4.
Tmega,
ICSP
(. 1.2). , Arduino -
US-, .
Arduino, Tmega
-,
Arduino USART.
Arduino Uno Mega 2560 USB
USART
(ATmega 16U2 8U2 ). Arduino Leonardo
ATmega 32U4,
USB. Arduino
ATmega USB
.
- ,
Arduino. VR
ICSP,
(SPI).
, , STK500 ISP II (. . 1.2).

. 1.2. AVR ISP MKII

Arduino ,
.
IDE UART,
.
, , Arduino.
1. , Arduino 31

IDE Arduino
(Tmega 16U2 8U2 Arduino Uno)
, .
, UART.
,
USB .
:
+ ( 2 ),
;
+
,
.
( Arduino,
), Tmega
.

1.5.
-
Arduino -
.
. Arduino
.
: ,
, - .

1.6.
5- ,
USB. , ,
6 20 (
7-12 ). DC V;n.
Arduino 5 3,3 :
+ 5 ,
- 0-5 ;
+ 3,3
.

1.7. Arduino
Arduino, . .
.
Arduino.
32 /. Arduino

Arduino Uno (. 1.3) - Arduino,


.
Tmega 328 l 6U2 USB.
Tmega 328 DIP SMD.

. 1.3. Arduino Uno

Leonardo (. 1.4) 32U4


USB.
US-, .
, , 6.
Arduino Mega 2560 (. 1.5) ATmega 2560,
54 -,
. Arduino Mega 2560
( Arduino Uno).
Arduino, 8-
VR, Due (. 1.6) 32- Atmel
SAM3X8E R Cortex-M3 84 .
: - ,
, ,
.
Arduino Nano (. 1. 7) ,
.
Mega ADK (. 1.8) Arduino Mega 2560, Mega ADK
USB,
Android.
1. , Arduino 33

. 1.4. Arduino Leonardo

. 1.5. Arduino Mega 2560


34 /. Arduino

. 1.6. Arduino Due

. 1.7 Arduino Nano

. 1.8. Arduino Mega ADK


1. , Arduino 35

Arduino LilyPad (. 1.9) ,


. , . .
FTDI.

. 1.9. Arduino LilyPad

, Arduino - .
rduin- ,
IDE Arduino , .
Seeeduino, Adafruit 32U4, SparkFun Pro
Arduino.
, . ,
ArduPilot - (. 1.1).
rduin- MakerBot
D-.

. 1.10. n ArduPilot Mega


/. Arduino

1.8.
, Arduino,
.
.

1.8.1. Arduino IDE


Arduino http://www.arduino.cc
Arduino IDE Download (. 1.11).

Download the Arduino Software


hi,1, :onrcf>Ardiflo ei.-;,Ir-(lc't(,:.:,t it. a..5.tt) \1.'riteeodtr.1r..d U?loo.d it tltf i/Ct 00,rd, l! ru.or; \\iDdrr.._.
)f OS "{, and !:inu'< 1"11"1 1"1,"iro'101,t is r.rittt:::. in./,...,,a 3nd i> PJ'OCE'S."'!t:.g. 1\\'1'1!1-. and Qti,.t .,-11 :rouri:e
wftv.,;1,r,

00'/\.l}(sd{f

.-\rdu.Jl'lo 1..0. {re1ease-notes. l,ostt1'd }' Googl@Code G<ttin3Swted


Refe
+ \\"indO"'i E,-iron:mf,nt
+ Macosi l!>ompl"
+ lit,;\ 321rit. 6-4 it
fouod,.tions
+ S:OU.."'t.O
fAQ

. 1.11. Arduino.cc

.
Arduino IDE. IDE Windows ,
Arduino .
1. , Arduino 37

1.8.2. IDE Arduino


Arduino USB,
. 1.12. Linux
.

. 1.12. Arduino Uno US-

OS ,
,
. Network Preferences ( ->
). Apply ().
Not Configured, .
System Preferences ( ).
Arduino Windows,
, . Arduino IDE
Windows .
IDE zi-,
:
+ ;
+ ;
38 /. Arduino

+ (System and Security).


. ,
(Device Manager);
+ ( LPT). ,
Arduino;
+ (Update
Driver Software );
+ Browse my computer for Driver software;
+ ,
Drivers Arduino (
FTDI USB Drivers );
+ Windows .
Arduino IDE.
Arduino. , Blink,
. Arduino ,
13. File->
Examples-> Basic Blink.
. Arduino ,
, , .
Arduino,
. Tools-> Board (->
) Arduino. Arduino Uno,
, .
, .
Tools-> Serial Port (-> )
. Windows *, * -
, . Linux
dev/tty.usbmodem* /dev/tty.usbserial*, * -
- .

MRi=iiM
,
, Arduino, , ,
, Arduino.

. Upload (
), Arduino IDE. ,
, .
, 13 Arduino,
. !
.
1. , Arduino 39

1.8.3. Blink
Blink (. 1.13),
, Arduino.

Blink I Ardulno 1.6.1

----1+1
lil\l!
Urnz on arJ LED on tor one :econd, then of! fot 011 econd, repee.t.edly.

11 ..l code 1 1rt th.e pul1c Uom.a1n.


>/

2 ----1+11 P1n 13 h LEI> r.onneci:ed JII03t Atd>.ti1Jo boatd3.


// g1ve 1t ne.m.(":
3 1nt led = 13;

/ J tl"v:: setup toutlne runs once hen you pi:3S J:eet:


4 ----1-1-vo1d setup () (
11 1n1 t1a1tze the d1,;r1 tal p1n as sn outpui:.
5 p!lode (led, OtrrPtrr);

11 t.tie loc,p tc11,.tt.in.e t\m ove.t and ove.r: aqa1n foteve:c:


6 ----t+voi loop (
7 d1g1taltJri1:e (led, HIG); / I tu the LED on (lt:H i 1:h<- voltaqe level)
8 ,jeJay(lOOO); "! W<t fot second
9 diqitalWrite(led, LO!i); // ttttn the LED off aaking the voli:age LOI
10 rJelay(lOOO); 11 wa1t fot secc,i

. 1.13. r Blink

. 1.13 :
+ 1 - r .
. , ,
. r /*
*/. r , ,
.
+ 2 - . // ,
.
.
40 /. Arduino

+ 3 - . - ,
. .
int, .
led 13 - ,
Arduino.
led, 13.
,
- ,
.
+ 4 - setup (), ,
Arduino. - ,
. setup ()
. ,
-,
. .
+ 5 - Arduino
. pinode (),
, . pinode
. led
, 13.
: INPUT () uu ().
. ,
uu.
, 13 .
, .
+ 6 - Arduino - loop ().
.
+ 7 - digitalWrite () : 5
. ,
"1" (
). digitalWrite () -
, . - ,
: IGH (5 ) LOW ( ). ,
digitalWrite ().
+ 8 - delay () -
. delay () Arduino
.
1 ( 1 ).
.
+ 9- digitalWrite (), ,
LOW.
+ 1 - , m
.
1. , Arduino 41

. ,
. ,
, .

:
+ Arduino.
+ Arduino Arduino -
USB.
+ Arduino.
+ Arduino IDE Arduino .
+ .


:
+ Arduino Uno;
+ ;
+ ;
+ 1 1 ;
+ 3 220 ;
+ USB;
+ ;
+ 05 ;
+ RG- 05 .


http://www.exploringarduino.com/content/c
, . ,
www.wiley.com/go/exploringarduino
Downloads.


, ,
, .
Arduino -.
m, , , -
, .
:
Arduino, (pull-up)
(pull-down) .
2. -, - 43

Arduino ,
- (). ,
-. , RG
.

-
http://www.jeremyum.com/2011/01/10/arduino-tutorial-2-now-with-more
inky-things/ 1 .
,
, , -
http://www.jeremyum.com/2011/01/17/electrical-engineering-basics-in-arduino
tutorial-3/2 .

2.1. 1
1 , , m
. Arduino
:
+ ;
+ ;
+ ;
+ ;
+ - ().

2.2.
Arduino.
9
. ,
, . , 9 Arduino
- ,
.

2.2.1.
,
. - ,

.

I
: htt://wiki.mrk.ru/:2--wm-.
2
: htt://wiki.mrk.ru/:3--.
44 /. Arduino

. , ,
. +5 .

. , ,
.
.
. 2.1 .
( )

( )
. 2.1.

2.3.

. ,
. ,
- .
: , .
: .
,
( +5 ), -
.
. .
2. -, - 45

9 Arduino ,
.
, .
220 . . 2.2.

. 2.2. Arduino Uno

2.3.1.
- - ,
( ), (
) ( ) .
(,
9 ) (-, , ).
, :
+
;
+ ,
. , -
46 /. Arduino

, - . ( )
( )
( ). , ,
;
+ .
() ,
, .
, .
, ()
.
:
U = lR,
- ; 1 - ; R - .
,
. ,
.

. ( ),
.
20 .
2 .
, . 2.3,
Rl.

g1+
--,:
i'
:
R1.

i _ . ____ ___ ___ ___


l.[01
Jl;t
1
__ . ____ G 1 0
:
!'
:

. 2.3.

, LED 1 - 20
2 . 5
. 2 ,
3 .
(20 ), :
R = /!= 3/0,02 = 150 .
, 150
20 . .
220 ,
.
- ,
, . -
2. -, - 47

. ,
, .
0,125 .
:
= !,
- , ; - , ; 1 - , .
. 2.3 3 20

= 30,02 = 0,06 .
60 < 0,125 = 125 , ,
.

2.4.
Arduino .
Arduino ,
, .
Arduino :
setup() loop() .
1 , setup()
, loop() .
, setup() .
,
9 . : pinode() -
digitalWrite() - IGH (5 )
( 2.1 ).

tJrr '2.1. f) i(r;


const int LED=9; // -

void setup()
{
pinode (LED, OUTPUT); //
digitalWrite(LED, HIGH); // HIGH

void loop() {
// m

, . 2.2, 2.1
Arduino. , -
48 /. Arduino

Arduino.
, ,
. const ,
, " "
. LED
9.
, .
: ,
.
.
( ).
1, ctigitalWrite
loop() . ,
.

2.5.

. ,
, .
,
. 2.2.

const int LED=9; //

void setup()
{
pinode (LED, OUTPUT); //

void loop()

for (int i=lOO; i<=lOOO; i=i+lOO)

digitalWrite(LED, HIGH);
delay(i);
digitalWrite(LED, LOW);
delay(i);

2.2, Arduino
, . , .
2. -, - 49

for , :
+ - .
i 100;
+ , .
, . <=
. , ,
i 1;
+ , i
. ,
100.
for, ,
:
1. i 100, 100 1,
.
2. 9 IGH, 100 (
i).
3. 9 LOW, 100 ( -
i).
4. i 100, i 200.
5. 200 1000, .
6. 9 IGH, 200 (
i).
7. 9 Low, 200 (
i).
8. i 100, i 300.
9. , i 1000 i -
100 .
, Arduino.
,
Arduino.

2.6. -
analogWrite()
Arduino.
, .
, , 5 .
Arduino Uno .
Arduino Due
.
50 /. Arduino

, m
- ().
Arduino - analogWrite().
, -
, - Arduino. Arduino Uno 3, 5,
6, 9, 10, 11 -. Arduino Uno
analogWrite() , . 2.1.
9 Arduino,
, , .
analogWrite().
analogWrite() : 8-
255, .
2.3 - 9
.

const int LED=9; //

void setup()
{
pinode (LED, OUTPUT); //

void loop()

for (int i=O; i<256; i++)

analogWrite(LED, i);
delay(10);

for (int i=255; i>=O; i--)

analogWrite(LED, i);
delay(lO);

2.3?
,
for, for.
loop( J .
for. i++
i=i+l. , i-- i=i-1.
, - .
2. -, - 51

,
, . ,
llllllv1
( ),
( ).
, , .
, . 2.4.
(
) .
,
HIGH, . 50% ,
, - .

25% nn 50% 75%


6 6 6
5 5
,
s 4 4
s s
4
l i
i i i
3 i 3
2 2 2
:i: ::i: ::i:
1 1 1

- -
1 1 1
3 4 5 6 7 8 0 2 4 5 6 7 8 0 2 4 5 6 8
. . .

0% 100%
6

s 4 4
s
:,:

i
:i:
2 !!- 2
::i:
1 1

- -
1 1
0 2 4 5 6 7 8 0 2 4 5 6 7 8
, ,

. 2.4. -

analogWrite ()
, :
+ analogWrite (), , 0% (
1ow);
+ 255 - 100% ( IG);
+ 127 50% ( IGH,
1ow).
. 2.4 , 25% IGH
, 75%
1ow.
52 /. Arduino

Arduino 490 . ,
(5 ) ( ) 490 .
, , , ,

? .
1 ( 50%), ,
50% ,
, .
,
.

2. 7.
.
, -.
- Arduino .
, ,
.
, ,
.

2. 7.1.

, . 2.1.
, ,
. 2.5.

MiX=ilM
, .
.

,
.
(pull-down) (pull-up)
" " . ,
. 2.5 1 .
IGH. , ?
, , " ".
, 5 ,
.
, IGH
1ow. , ,
. 2.5.
2. -, - 53

. 2.5. Arduino

, , ,
1 .
LOW. 1 -
.
5 .
:
+ 5 ;
+ .

.
IGH.

,
, 5 ,
. HIGH
LOW, .
54 /. Arduino

, ,
5
"" .
. ,
, , 01 ( 2.4).

const int LED=9; // 9


const int BUTTON=2; // 2

void setup()
{
pinode (LED, OUTPUT); //
//
pinode (BUTTON, INPUT); //
//

void loop()

if (digitalRead(BUTTON) LOW)

digitalWrite(LED, LOW);

else

digitalWrite(LED, HIGH);

2.4 :
digitalRead() if/else. uN int
. , setup() uN .
, . . Arduino .
digitalRead() . ,
digitalRead() IGH (. 1). ,
1ow (. ).
if () . if ()
( , digitalRead() ==Low),
digitalWrite(LED, LOW) ( ). ( )
else (
digitalWrite(LED, HIGH)).
! Arduino , ,
.
2. -, - 55

2.8. ""
?
, ,
, . ,
. , ,
. ,
, .

. ,
,
LOW.
, . 2.6.

r
6 6

4
:,
t 3

! 2


-1--5 0 5 025 30-35 -40 -4550 1 30 35 40 45 50
1 1 2 -0 5 10 15 20 25
, ,

. 2.6.

m 25 . ,
, ( )
. -,
( ). , , ,
, ,
.
:
1. ( Low).
2. .
3. , 5 ,
, , .
4. 5 ,
.
5. m Low, - IGH,
.
56 /. Arduino

6. .
7. 2.
- . -
, ,
, , . ,
. , digitalWrite() - ,
(rG 1ow),
. ,
,
.

. ,
.
,
.
. 2.5
Arduino , .

const int LED=9; // 9


const int BUTTON=2; // 2
boolean lastButton = LOW; //
//
boolean currentButton = LOW; //
//
boolean ledOn = false; //
//(/)

void setup()
{
pinode (LED, OUTPUT); //
//
pinode (BUTTON, INPUT); //
//

/*
*
*
* .
*/
boolean debounce(boolean last)

boolean current = digitalRead(BUTTON); //


if (last != current) // ...
2. -, - 57

delay(S}; // 5
current = digitalRead(BUTTON}; //
return current; //

void loop(}

currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH) //
{
ledOn = !ledOn; //
//

lastButton = currentButton;
digitalWrite(LED, ledOn); //
//

2.5 .
.
, (
).
(Low, LOW false).
=.
boolean debounce().
( :
true/false, IGH/LOW, ./., 1/0)
.
!= ( ).
, , , . 5 ( ,
),
. .
, .
,
debounce (}. debounce (} ,
currentButton,
.
debounce() currentButton

&& ( "", ,
, ,
&&).
Low, IGH, ,
lecton. -
58 /. Arduino

lecton. ,
.
.
.

2.9.
RG-
, ,
, -.
Arduino RG-
, . RG-
, -
.
RG- ,
, , -
. RG- -
Arduino , . 2.7.

.
. ,
2.6, , .
analogWrite () .
loop () -
( 7).
.
RG-, analogWri te ()
.

const int BLED=9; // 9 BLUE RG-


const int GLED=lO; // 10 GREEN RG-
const int RLED=ll; // 11 RED RG-
const int BUTTON=2; !/ 2

boolean lastButton = LOW; //


boolean currentButton = LOW; //
int ledode = ; // RG-

void setup ()
{
pinode (BLED, OUTPUT); //
// BLUE
2. -, -n 59

pinode (GLED, OUTPUT); // GREEN


//
pinode (RLED, OUTPUT); // RED
//
pinode (BUTTON, INPUT); //
//

/*
*
*
* .
*/
boolean debounce(boolean last)

boolean current = digitalRead(BUTTON); //


if (last != current) // ...
{
delay(S); // 5
current = digitalRead(BUTTON); //
return current; //
//

/*
* .
* .
*/
void setMode(int mode)

//
if (mode == 1)

digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);

//
else if (mode == 2)

digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);

//
else if (mode == 3)

digitalWrite(RLED, LOW);
60 /. Arduino

digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);

// (+ )
else if (mode == 4)

analogWrite(RLED, 127);
analogWrite(GLED, );
analogWrite(BLED, 127);

// (+ )
else if (mode == 5)

analogWrite(RLED, );
analogWrite(GLED, 127);
analogWrite(BLED, 127);

// (+ )
else if (mode == 6)

analogWrite(RLED, 127);
analogWrite(GLED, 127);
analogWrite(BLED, );

// (+ + )
else if (mode == 7)

analogWrite(RLED, 85);
analogWrite(GLED, 85);
analogWrite(BLED, 85);

// (mode = 0)
else

digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);

void loop()

currentButton = debounce(lastButton); //
//
if (lastButton == LOW && currentButton HIGH) //
2. -, - 61

ledode++; //
//
//

lastButton currentButton;
// n
//
// =
if (ledode == 8)
ledode = ;
setMode(ledode); //

RG-

. 2.7.
62 /. Arduino

, , .
, .
. ,
RG-.
, 1.
.

:
+ .
+ .
+ Arduino.
+ III, .
+ .
+ .
+ .
R 1


:
+ Arduino Uno;
+ ;
+ ;
+ 1 ;
+ 2 1 ;
+ 3 220 ;
+ USB;
+ ;
+ 36 ( 5 );
+ RG- .


http://www.exploringarduino.com/content/ch3
, . ,
www.wiley.com/go/exploringarduino
Downloads.


.
" ",
. ,
, ,
.
,
Arduino.
64 /. Arduino


, ,
Arduino.
,
. ,
Arduino ,
,
.

- 1
http://www.jeremyum.com/2011/01/24/arduino-tutorial-4-analog- inputs/ .

, , -
http://www.jeremyum.com/ 2010/06/20/lets-get-digital-or-analog/.

3.1.


. . :
. - ,
: , IGH LOW, 1 , . .
() .
.
.
. ? , , ,
, , , ,
. .
, .
,
.

3.2.
. 3.1 ,
. ,
: 5 . ,
: HIGH LOW. .
, ( 5 ),
.

I
: http://wiki.amperka.ru/eoypo:4-aaoroe-xo.
3. 65

,
.
, - , .
, ,
( - ).
( )
130 .
, -
.


6,.. 6

5'" - 5

4'" 4
a:i :,
qj qj
3'" 3
;
g. 2 .... 2
:I:
'"
1 1 1 1 1
-1
2 4 6 8 10
, ,
. 3.1.


,
.
Arduino ? -
(),
.

3.3.

, .
,
. ,
, - 5 .
. Arduino,
, ?
, , -
Arduino.
/. Arduino

. Arduino Uno
1 - . ,
i 0 . , Arduino i 0 = 1024
, 1023.
,
1023.
, 2,5 512 (
1023), 5 1023.
, . ,
. 3.2. , ,
5 .


5 7(111)
4, 5
6(110)
4
3, 5 t:[ 5(101)
!;!
a:i
3
'2 4(100)
i 2, 5 8.
:r t::r 3(011)
!
.
2
1, 5 2(010)
1
1(001)
0, 5
0(000)
2 3 0 2 3 4
. ,
. 3.2. -

. 3 , 23 = 8, ,
8 , 7. ,
, 7. . 3.2 ,

, . ,
, .
, Arduino Uno 1024 , 8, . 3.2.


( )
, Arduino
http://www.arduino.cc/en/Reference/AnalogReference.
3. 67

3.4.
Arduino. analogRead()
, ,
, .
Arduino .
analogRead().
.
,
,
- .

3.5.
,
, - . , ,
.
-.
, .
, 5 .
, ,
, .
Arduino. Arduino,
. 3.3.
5 .
. ,
, . 3.4, ,
. () rr
, () -
.


, . 3.4.

,
,
Arduino
.
analogRead(), Arduino IDE -
serial.pritln(). Arduino
3.1.
68 /. Arduino

. 3.3.

. 3.4.


. 69

//
const int =; //
int val = ; //

void setup(}
{
Serial.begin(9600};

void loop(}
{
val = analogRead(POT};
Serial.println(val};
delay(500};


. ,
, Serial .begin(},
.
, .
,
.
9600 .
val ,
analogRead(} ,
( ). serial.println(}
, .
( ,
).
Arduino , ,
, 500 ( , ).
, Arduino US
.
, Arduino IDE ,
, . 3.5.

.
, , .
, , - 1023.
. 3.6.
70 /. Arduino

const :i.nt POl'=O; / /Pot ;, Anlog !i'.!n


u,t val = ; //var il!ll:>le to hold the ana.wg read.ng fr.otn the ;,,:,

,,o.td ,.,tup II
(
Sexi"1.begin(9600);

vo1.d .1.
{
val = anolc,gRead () ;
Sexial.println(val);
del&y (5001 ;

. 3.5.

524
524
527
530
531
534
535
539
541
545
547
549
550

. 3.6.
. 71


, ,
. 9600 ,
.

,
, , ? .
,
. ,
.

3.6.

, .
" " , .
, ,
"" . :
+ (
);
+ ( -
);
+ ;
+ .
:
(VCC GND) Arduino.
:
+ Sharp. (
http://www.exploringarduino.com/parts/lR-Distance-Sensor,
- http://www.exploringarduino.com/parts/JST-Wire.)
Sharp .
.
5 Sharp (
http:// exploringarduino.com/wp-content/uploads/2013/06/GP2YOA-datasheet.pdt)
.
+ 36. ( http://www.
exploringarduino.com/parts/P36.)
36
. 1
1 .
( ) ( 0) : = ( - 500)/10.
500 0.
. 3. 7.
72 /. Arduino

2,0
. 5
1,8 . 6
. 7
1,6 +V, = V

a:i 1,4
:i::
1,2

1,0
:i::
0,8

0,6
a:i
0,4

0,2


-50 -25 25 50 75 100 125
0
,
. 3.7.

+ . (
http://www.exploringarduino.com/parts/riAxis-Analog-Accelerometer.)

. ,
: , Z ( ).

.
3,3 ,

analogReference (),
3,3 Arduino.
+ . (
http://www.exploringarduino.com/parts/DualAxis-Analog-Gyroscope.)
, , .

. .
Arduino
SudoGlove (http://www.jeremyum.com/portfolio/sudoglove-hardware-controller/).
-, ,

. 3,3 .
, .
3. 73

3.7.
36,
.
- .
, , .
Arduino Uno RG-, 2,
(. 3 .8).
,
. RG- ,
, , , ,
.

. 3.8.
74 /. Arduino

, .
3.1,
.
20 , 143.
.
.
. 3.7 , ( 0)
( ):
(0)10 = ()- 500.
700 20 . (
) 22
147, 18 - 139.
, .
analogRead() , digitalWrite () -
.

-=-
3.2,
, .
.

//
const int BLED=9; // 9 BLUE RG-
const int GLED=lO; // 9 GREEN RG-
const int RLED=ll; // 9 RED RG-
const int =; //
const int LOWER_BOUND=139; //
const int UPPER BOUND=147; //
int val = ; //

void setup{)
{
pinode {BLED, OUTPUT); /! BLUE
//
pinode {GLED, OUTPUT); // GREEN
//
pinode {RLED, OUTPUT); // RED
//

void loop()
{
val = analogRead{TEP);
3. 75
if (val < LOWER_BOUND)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);

else if (val > UPPER_BOUND)


{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);

else

digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);

3.2 ,
,
Arduino.

3.8.

, ,
. ,
,
(),
().
,
.
, ,
,
.

3.9.
,
. ,
, .
, ,
.
76 /. Arduino

(. 3.9)
. . 3.9- Arduino.
:
= (R2/(Rl + R2)).
5 , m
Arduino. Rl R2 (,
, 10 ), 5 , 2,5 .
, :
= 5 (10 /(10 + 10 ))= 2,5 .

GND
. 3.9. . 3.1 .

, ,
(. 3.1).
.
200 . 200 ,
. , (Rl R2)
,
.
, .
R1 , R2
1 (. 3.11).
RG- .

(. 3.1) .
1023,
.
.
, "" ,
, .
, . -
3. 77

200 () 900 ( ).
. , R2
.

. 3.11.

3.1 .

, analogWri te ( ) .
, 8-, . .
255, 1023. -
78 /. Arduino

Arduino
: map() constrain(). map ()
:
output = map(value, fromLow, fromigh, toLow, toHigh).

value - ( ). fromLow
fromigh - .
(200 900). toLow
toHigh - .
analogWrite() 255.
, . .

. , map() . map()
. , fromLow fromigh 200
900, , toLow toHigh 255 , 550 127,
550 200 900, 127 255
. , map() ,
. value 200 ( ),
output 255. , . . analogWrite()
, 255, .
constrain(), :

output = constrain(value, min, max).

map() constrain()
min max - 255, ,
, . ,
. ,
( 3.3).

//
const int RLED=9; // 9 - RED RG-
const int LIGHT=O; //
const int MIN_LIGHT=200; //
const int AX_LIGHT=900; //
int val = ; //
//

void setup()
{
pinode(RLED, OUTPUT); // RD-
//
3. 79

void loop()
{
val = analogRead(LIGHT); //
//
val = map(val, MIN_LIGHT, AX_LIGHT, 255, ); // map()
val = constrain(val, , 255); //
analogWrite(RLED, val); //

, val .
, . , map( J,
val
.
Arduino , ,
. ,

. ,
, .

.

:
+ .
+ .
+ .
+ , .
+ .
+ .
+ .


4.
1

5.
6. USB
7.

:
t Arduino Uno;
t US-;
t 9 ;
t 9 ;
t L4940V5;
t 22 ;
t ,1 ;
t 1 ;
t 4 ;
t 4 1 ;
t -- PN2222;
t 1N4004;
t ;
t ;
t - Sharp GP2YOA41SKOF ;
t ;
t ;
t ;
t ;
t SN754410.
84 //.


http://www.exploringarduino.com/content/ch4
, . ,
www.wiley.com/go/exploringarduino
Downloads.


.
?
, . ,
Arduino
. Arduino, ,
,
. , ,
. ,
,
. , ,
. ,
- .

, ,
-
1
http://www.jeremyum.com/2011/01/31/arduino-tutorial-5-motors-and-transistors/

!
9 , . .
, Arduino.
,
.
. ,
. , 5
9 .

4.1.

. ,
, , DVD-neepa.
. ,
, .
, .
, -, .

I
: htt://wiki.mrk.ru/:5---.
4. 85

()
(). "
", .
(, , ),
.
, .

4.2.
,
Arduino ,
.
Arduino
. ,
,
2. ,
. 4.1, :
+ Q1 - -- ,
9 .
: -- --.
--. , --
, , ;
+ Rl - 1 , Arduino
;

9V

-------------g
'<;!"
,..-z
1 0..-
lJ1
MOTOR 1t.1F

. 4.1.
86 //.

+ U 1 - ;
+ 1 - , ;
+ Dl - .

4.3.

:
.
.
(. 4.2): (), ()
().

(Q
1
. 4.2. --

,
. ,
. 5 ,
Arduino, . ,
.
,
.

4.4.
- -.
, .
.
,
.
.
, ,
.
4. 87

4.5.
, . 4.1,
9 , 5 USB.
5 .
:
+ Arduino
;
+ , Arduino
.
, ,
Arduino. ,
5 . 5- ,
9 12 (
).

!
,
Arduino.
.

4.6.
,
, . ,
. 4.1, . 4.3.

.
:
+ , 9 Arduino,
, . 4.3;
+ , +9 +5 ;
+ , ;
+ , ; ,
.
.
, .
. ,
Arduino US-,
+5 , Arduino.
.
88 //.

. ,
. , -
.

. 4.3.

4. 7.

( 4.1)
3.
Arduino -
,
.
4. 89

//
const int MOTOR=9; // 9 Arduino

void setup()
(
pinode (MOTOR, OUTPUT);

void loop()

for (int i=O; i<256; i++)

analogWrite(MOTOR, i);
delay(lO);

delay(2000);
for (int i=255; i>=O; i--)

analogWrite(MOTOR, i);
delay(10);

delay(2000);

,
, .
, , .

.
, . 4.4.
, Arduino 5
.
, ,
.
, -
. , Arduino
, !

. ,
4.2. Arduino
.
90 //.

-------

. 4.4

const int MOTOR=9; // 9 Arduino


const int =; // Arduino
int val = ;

void setup()
{
pinode (MOTOR, OUTPUT);

void loop()

val = analogRead(POT);
val = map(val, , 1023, , 255);
analogWrite(MOTOR, val)
4. 91

4.8.
-
.
, ,
.
. ri ,
-. - ,
. 4.5.

. 4.5. -

-? . ,

"". ,
, , m .
- ,
.
- : "", "
", "" "".
. "" ,
. ""
, .
- , ,
.
-.
, ?
+9 .
, . ,
- .
SN754410-
-, .
92 //.

4.9. -
-. SN754410-
-. -
-, . 4.5.
-.
, , ,
SN754410. . 4.6
SN754410.

1,2EN 1 16 Vcc,

1 2 15 4
1 3 14 4

{ }
4 13
5 12
2 6 11
2 7 10
Vcc2 8 9 3,4EN

. 4.6. SN754410


. 1 (,
- ).
SN754410
. 4.1 ( : - ; L-
; - ; Z- ).
4.1. SN754410


EN


L L
L z

SN754410:
+ GND ( 4, 5, 12, 13)-
;
+ Vcc2 ( 8)- ( 9 );
+ Vccl ( 16)- ( 5 );
4. 93

+ 1 2 ( 3 6)- ;
+ IA 2 ( 2 7)- ,
Arduino;
+ 1,2 EN ( 1)- .
- Arduino,
;
+ 4 ( 11 14)- ;

. 4.7. -
94 //.

+ 4 ( 10 15)- ,
Arduino;
+ 3,4 EN ( 9)- .
- Arduino,
.
. 4.7. .
, .
(2 7) - 5 ,
. . 2
7, .
!
,
.

4.1 . -

-.
,
,

.
: - , -
-
.
. 4.5, :
1. ,
.
2. , . 1
, - .
3. .

,
-.

( 4.3).

nr 4.3 ScnQ:MQra
// ( 0-255)
void forward (int rate)

digitalWrite(EN, LOW);
4. 95

digitalWrite(MCl, HIGH);
digita1Write(MC2, LOW);
analogWrite(EN, rate);

//
//( 0-255)
void reverse (int rate)

digitalWrite(EN, LOW);
digitalWrite(MCl, LOW);
digita1Write(MC2, HIGH);
analogWrite(EN, rate);

//
void brake ()

digitalWrite(EN, LOW);
digitalWrite(MCl, LOW);
digita1Write(MC2, LOW);
digitalWrit(EN, HIGH)

, EN
,
MCI 2. MCl 2
. EN, .
rate 255.
( 4.4)
.

void loop()
{
val = analogRead(POT);
//
if (val > 562)
{
velocity = map(val, 563, 1023, , 255);
forward(velocity);

//
else if (val < 462)
{
velocity = map(val, 461, , , 255);
96 //.

reverse(velocity);

//
else

brake();


1023. , . 4.8.


( 462 512 562 023



. 4.8.

462 562 (100


) break() ,
562 1023 -
forward(), 462 -
reverse (). map() .
m 461
, m 255.
map() ,
. loop()
setup( J ,
( 4.5).

!! -
const int EN=9; // EN
const int l=; // 1
const int 2=2; // 2
const int =; !/
int val = ; /!
int velocity = ; // (0-255)

void setup()
{
pinode(EN, OUTPUT);
pinode(MCl, OUTPUT);
pinode(MC2, OUTPUT);
brake(); !!
4. 97

void loop()
{
val = analogRead(POT);
//
if (val > 562)
{
velocity = map(val, 563, 1023, , 255);
forward(velocity);

//
else if (val < 462)
{
velocity = map(val, 461, , , 255);
reverse(velocity);

//
else

brake();

//
// ( 0-255)
void forward (int rate)

digitalWrite(EN, LOW);
digitalWrite(MCl, HIGH);
digita1Write(MC2, LOW);
analogWrite(EN, rate);

//
// ( 0-255)
void reverse (int rate)

digitalWrite(EN, LOW);
digitalWrite(MCl, LOW);
digita1Write(MC2, HIGH);
analogWrite(EN, rate);

//
void brake ()
{
digitalWrite(EN, LOW);
digitalWrite(MCl, LOW);
digita1Write(MC2, LOW);
digitalWrite(EN, HIGH);
98 //.

r Arduino . ,
? , .
- SN754410
.

4.11.
,
, . . . ,
-
. ( ), , ,
,
r . r ,
.
Arduino.

4.11.1.

.
( 180 )
, .
.
( )
.
, ,
,
.
,
.
,
.

4.11.2.
,
:
+ ( );
+ ( );
+ ( ).
,
. 4.9. ,
4. 99


.
,
( ,
).

/ -
-
/ -

. 4.9.

, ,
Arduino.
- Arduino. ,
,
.
.

.
1 0,
2 180,
1,5 - 90. ,
.
,
, 20 .
Arduino Servo, ,
.
, , ,
. 4.10.
, . 4.1, 20 .
1 2 ,
( ) 180.
100 //.

11 ... ...
1D 6
1 2 3 4 5
. ,
6 7 8 9 1 011 12 13 14 1 5 16171819202122232425262728293031323334353637383940
.
1,2 5 (45 )'
180

45
0

90
! 4
/.?
1"' 2
180C:::JJ.S:::::\o
:i:: 01----...
i:::

n n
1 2 3 4 6 7 8 9 1 011 12 13 14 1 5 16171819202122232425262728293031323334353637383940
.
5

i :[
1 (90')

d
5

,
2
180C:::i<I{:c:::\o
' '
01 2 3 4 6 7 8 9Wnaffi171920212223252627282930M 32 33343536383940
1 ' ' ' ' ' ' ' ' ' 1 ' ' 1 ' 1 ' ' ' ' 1 1 1 1 1 1 1 1 1 1 1 1 1 1

.
5

180
1D 6 2 (180')
90
! 4

1"' 2
1800
:i::o---...
i:::

01 2 3 4 5 6 7 8 9Wnaffi171920212223252627282930M3233343536383940
.

. 4.1 .

, , ,
Arduino .
5 , 9 12 .
, .
, 9
5 .
- , :
+ ;
+ ;
.
,
. ,
,
.
,
(, ).
5- L4940V5,
1,5 . . 4.11.
4. 101

9V 5V1
IC1
l-4940V5
\!IN OUT 2

1 z 2
_ 1 uf7 22Llr:

G D
. 4.11.

58
. 4.12.
102 /1.

,
.
. ,
5 Arduino.
Arduino.
. ,
,
9 Arduino, ,
5 .
(. 4.12).
, , ,
.
, , ,
Arduino, 5 . Arduino USB
Arduino
500 . .
,
. ,
.
.

4.12.
Arduino IDE Servo
. ,
. Servo
Arduino . .
-
.
0 , 1023 - 180 . ,
4.6, Arduino, .

n1r,4.11_.. t100oetteunst
nt ncretJo -- eeo,o-.Jnc>
//
#include <Servo.h>
const int SERV0=9; // 9
//
const int =; //
Servo myServo;
int val = ; //

void setup ()
{
myServo.attach(SERVO);
4. 103

void loop()
{
val = analogRead(POT); //
val = map(val, , 1023, , 179); //
myServo.write(val); //
delay(15);

include, ,
Servo. Servo myServo myservo.
, ,
myServo. setup() ,
9 Arduino. Arduino
, Servo Arduino.
loop() ,

. 15 ,
, .

4.1 .

, ,
. () ,
, .
,
.
.
,
,
" ". - .
- ,
. ,

. ,
, ,
.
- .
,
, , .


http://www.exploringarduino.com/content/ch4.
104 11.

,
. 4.13. ,
. ,
, .

. 4.13. - ,

r 9 Arduino,
5 . -
. 3, 5, 6,
11 1 . Arduino Uno
, 9 1
, , ,
Servo. , r
Arduino Mega
.
. 4.13.
, . -
, . 4.13.
- .
:
1. .
2. .
3. , .
4. .
4. 105

58
. 4.14.

5. .
6. 1.
4.7. Arduino IDE ,
Arduino.

// -
#include <Servo.h>
const int SERV0=9; // 9
//
const int IR=O; // -
//
const int LEDl=; // l
const int LED2=5; // 2
const int LD=; // 3
const it LED4=ll; // 4

// Servo
Servo myServo;
106 //.

int distl ; // n
int dist2 ; //
int dist ; //
int dist4 ; //

void setup()

myServo.attach(SERVO);
pinode(LEDl, OUTPUT); //
pinode(LED2, OUTPUT); //
pinode(LED, OUTPUT); //
pinode(LED4, OUTPUT); //

void loop()

//
distl = readDistance(15);
analogWrite(LEDl, distl);
delay(OO);
dist2 = readDistance(65);
analogWrite(LED2, dist2);
delay(OO);
dist = readDistance(115);
analogWrite(LED, dist);
delay(OO);
dist4 = readDistance(165);
analogWrite(LED4, dist4);
delay(OO);

int readDistance (int pos)

myServo.write(pos);
delay(OO);
int dist = analogRead(IR); //
//
dist = map(dist, 50, 500, , 255); //
dist = constrain(dist, , 255); //
return dist; // ,
//

readDistance( J ,
, , ,
loop() . -
4. 107

, .
50, - 500.
,
, .

:
+ .
+ ,
,
Arduino.
+
-.
+ Arduino
Servo.
+ 5 9
.
+ - , ,
, .
+ .

Arduino Uno;

US-;

4 ;

5 1 ;

1 150 ;

1 ;
8 .


http://www.exploringarduino.com/content/ch5
, . ,
www.wiley.com/go/exploringarduino
Downloads.


, .
,
Arduino! , ,
. , .
, -
. .
Arduino, "".
5. 109

Arduino .
- tone ( ) ,
. ,
Arduino
Arduino.
. Arduino Due,
().

5.1.
Arduino,
, .
, , .
. ,
.
.
.
,
Arduino?
:
. ,
.
, . (
, ), - (, ).
. 5.1,
.
. 5.1 , :
, .
261,63 . , ,
, 261,63
. (1/261,63 =
= 3,822 ), . Arduino
,
. , Arduino
, .
- :
(. . 3.1). -
, ,
.
, , .

.
110 //.

,j:z:
100
0 1 2 4 5
.
6 7 8 9 10

j

100

i .. .

iJr
100
0
'7 .
1 2
. V.. \1
4 5
,
6 7 8 9 10

i 100

50
<1
-50
f
100
0 1 2 4 5 6 7 8 9 10
,
. 5.1.

5.2.
, , ,

.
. - ? ,
. , . 5.2,
.
.
( , Arduino),
,
. -
, .

5.3. tone()

Arduino
. tone ()
Arduino.
5. 111

. 5.2.

tone (} :

+ Arduino ;
+ ;
+ () ;
, ,
noTone (} .
tone (}
Tmega, Arduino,
.
,
. tone (}
( ,
, . .). ,
.

5.4.
,
, .
. ,
, , . Arduino IDE
, .
, www.exploringarduino.com/content/ch5
112 //.

. Arduino .
, , , Arduino
. ,
, .
pitches.h, , , Arduino ,
. Arduino IDE .
(. 5.3).

. 5.3. Arduino IDE

pitches.h, .
, ,
.
Arduino, ,
. .
* .ino:
#include "pitches.h"
, , ,
. ,
. ,

( ).

5.5.
, ,
, .
- Arduino.
.
5. 113

GND
. 5.4.

. 5.5.
114 //.

, ,
.
, Arduino 40 .
8 (
). ,
. , = lR.
Arduino 5 40 . ,
R = 5 /40 = 125 .
8 ,
125 - 8 = 117 . 150 .
, .
, (. 5.4).
Rl - 150 , R2- 10 .
, , ,
: ,
150 .
.
Arduino ,
. 5.4, . 5.5.
. ,
.

5.6.
.

.

5.6.1.

, . -
. .
,
. -
, .
Arduino .
, ,
. , ,
int, :
int numers[4];
.

5. 115

, ,
:
//
int numers[4] = {-7, , 6, 234};
int numers[J = {-7, , 6, 234};
, . r r
,
. ,
, 9 Arduino,
, :
analogWrite(9,numers[2]);
, 2 ,
.
:
ntuners(2] = 10;
, r,
, .

5.6.2.

, ,
. , -
. ,
, .
,
, ( 5.1).

//
int notes [] =
NOTE_A4, NOTE_E3, NOTE_A4, ,
NOTE_A4, NOTE_E3, NOTE_A4, ,
NOTE_E4, NOTE_D4, NOTE_C4, NOTE_B4, NOTE_A4, N_4, NOTE_C4, NOTE_D4,
NOTE_E4, NOTE_E3, NOTE_A4,
};
//
int times[] = {
250, 250, 250, 250,
250, 250, 250, 250,
125, 125, 125, 125, 125, 125, 125, 125,
250, 250, 250, 250
};
116 11.

, (20 ).
, - .
. ,
, , 250 ,
- 125 .
,
!


www.exploringarduino.com/content/ch5
Wiley.

5.6.3.
.

. , ,
, setup () .
, Reset. 5.2
Arduino.

//
#include "pitches.h" //
const int SPEAER=9; //

//
int notes [] =
NOTE_A4, N_, NOTE_A4, ,
NOTE_A4, N_, NOTE_A4, ,
NOTE_E4, NOTE_D4, NOTE_C4, NOTE_84, NOTE_A4, NOTE_B4, NOTE_C4, NOTE_D4,
NOTE_E4, N_, NOTE_A4,
};

//
int times [) = {
250, 250, 250, 250,
250, 250, 250, 250,
125, 125, 125, 125, 125, 125, 125, 125,
250, 250, 250, 250
};

void setup ()
5. 117

//
for (int i = ; i < 20; i++)
{
tone(SPEAER, notes[i], times[i]);
delay(times[i]);

void loop()

// , Reset
}

, ,
,
for() . tone()
, delay(), ,
.

:
+ ,
.
+ ,
.
+
tone().
+ Arduino ,
.
+ ,
.

USB


:
+ Arduino Uno;
Arduino Leonardo;
+ US- - ( Uno);
+ US- - ( Leonardo);
;
+ RG- ;
+ 150 ;
+ 3 220 ;
+ 2 1 ;
+ ;
+ ;
+ 36;
+ . (Spark.Fun, Parallax Adafruit);

;
.


http://www.exploringarduino.com/content/ch6
, . ,
www.wiley.com/go/exploringarduino
Downloads.
. USB 119



, VR ISP MII.
Arduino - US
. Arduino
. Arduino ,
/
ATmega (USART).
Arduino Arduino
, ( Arduino).
,
Arduino USB .
Arduino ,
, ,
. ,
Arduino.
, ,
.

6.1.
Arduino
, Arduino
-. ,
:
.
Arduino.

,
r http://www.jeremyum.com/2011/02/07/arduino-tutorial-6-serial-communication
and-processing/ 1 Wiley.

USB.
,
( RS-232), . . US-.
. 6.1.
Arduino
9- .
, ,
RS232 USB. ATmega328,

1
: http://wiki.amperka.ru/eoypo:6-serial--processing.
120 11.

Arduino Uno, .
() Rx (),
1. 1, Arduino
, .
, "" (. .
), - USB.
US- . Arduino
. -
( Arduino Uno). -
, US- (,
32U4 Arduino Leonardo).

. 6.1.

6.2. Arduino
FTDI
Arduino ( )
USB . FTDI-
, :
USB. FTDI,
"Virtual Serial Port", 9-
. Arduino Nano
FTDI . 6.2.

FTDI
. Windows, OS
Linux http://www.ftdichip.com/DriversNCP.htm.
Exploring Arduino.

FTDI (US-
FTDI . 6.3)
(. 6.4).
Arduino FTDI ,
USB.
.
. USB 121

FTDI

. 6.2. Arduino Nano n FTDI

. 6.3. FTDI . 6.4. FDI Sparkfun

Arduino FTDI.
, , :
+ Arduino Nano;
+ Arduino Extreme;
+ Arduino NG;
+ Arduino Diecimila;
+ Arduino Duemilanove;
+ Arduino Mega (original).
, FTDI:
+ Arduino Pro;
+ Arduino Pro Mini;
122 11.

LilyPad Arduino;

Arduino Fio;

Arduino Mini;
Arduino Ethemet.

6.3. Arduino

USB
Arduino Uno m , USB
.
, . . 6.5
8U2, Arduino Uno (
16U2).


Atmel 8U2 16U2

. 6.5. 8U2 Arduino Uno

:
+ Windows
.
Arduino IDE ( OS Linux );
+

. Arduino
. USB 123

. Arduino 8U2 16U2


Arduino;
+ (
LUF, USB), ,
, Arduino , ,
, IDI-.
Arduino , VR ISP
MII.
Arduino
USB :
+ Arduino Uno;
+ Arduino Mega 2560;
+ Arduino Mega ADK ( 2560);
+ Arduino Due ( ).

6.4. Arduino ,
USB
Arduino Leonardo , ,
,
USB. Arduino Leonardo ( )
32U4, USB.
.
-, ,
. -,
, (
, ). -, USART ATmega
USB,
,
( GPS).
Arduino,
USB:
+ Arduino Due ( -
);
+ LilyPad Arduino USB;
+ Arduino Esplora;
+ Arduino Leonardo;
+ Arduino Micro.
124 //.

6.5. Arduino USB-xoca


Arduino USB-xoca,
US- (, ,
Android). ,
. , - Arduino
Due . Arduino Due
USB Host, US- . Arduino
Mega ADK Android Open Accessory Protocol (),
Arduino Android.
, - Arduino ,
Android.
USB-xoca : Arduino Due Arduino Mega
ADK ( Mega 2560).

6.6. Arduino
, , -
Arduino .
.
, ,
, , .
Arduino.

6.6.1.
:
+ Serial.begin(baud_rate);
+ Serial.print("Message");
+ Serial.println("Message"),
baud_rate essage- , .
, Serial.begin()
setup(), .
Serial.print() serial.println()
. ,
serial.println() .
, ,
Arduino, . 6.6.
,
6.1,
.
6. USB 125

. 6.6.

//
!/
const int =; //

void setup()
{
Serial.begin(9600); //
// 9600
126 //.

void loop()

int val = analogRead(POT); //


int per = map(val, , 1023, , 100); //
Serial.print("Analog Reading: ");
Serial.print(val); //
Serial.print(" Percentage: ");
Serial.print(per); //
Serial.println("%");
delay(lOOO); // 1
//

6.6.2.
"" ( )
,
. (\),
. ,
: .
,
\ t. , \n.
,
, , serial.println() . ,
,
\n \ t , \\n \\t,
. 6.2 6.1,

.

//
const int =; //

void setup()
{
Serial.begin(9600); //
// 9600

void loop()

Serial.println("\nAnalog Pin\tRaw Value\tPercentage");


Serial.println("------------------------------------------");
. USB 127

for (int i = ; i < 10; i++)

int val = analogRead(POT); //


int per = rnap(val, , 1023, , 100);//
//
Serial.print("AO\t\t");
Serial.print(val); //
Serial.print("\t\t");
Serial.print(per); //
Serial.println("%");
delay(lOOO); // 1
//

,
, , . 6.7.

87 6\
Ot
\

----------------------------
Analoq P1n aaw Vali,e
------- ------
Percent.oqe

2 ,
43 4\
90 ,
141 t3t
163 1s,
2 23\
311 t
370 \
422 ,
470 45t

------------------------------------------
Analoq Pin Row Valua Percentaqe

514 50t
572 ss,
720 70\
1021 99\
1023 100,

!@

. 6. 7.

6.6.3.
Serial.print() Serial.println()
. ,
, . -
128 //.

ASCII. Serial.print () Serial.println()


, .
. 6.1 ( 23)
.

6.1.


Decimal Serial.println(23); 23
Hexadecimal Serial.println(23,HEX); 17
Octal Serial.println(23,0CT); 27
Binary Serial.println(23,BIN); 00010111

6.6.4. Arduino
Arduino,
? , , Arduino ,
. , , ,
Arduino IDE , -
(. 6.8).

iiJcoM4
1

Autoscrofl

. 6.8.

-, , Newline.
,
Arduino. ,
Newline, \n ,
.
6. USB 129

,
Arduino IDE <Enter>
m . ,
Putty (www.exploringarduino.com), m .

6.6.5.

Arduino IDE,
Arduino. ,
.
Arduino . ,
, Arduino
, .
,
.

Arduino
Arduino , .
Arduino , .
, :
+ Serial.availae () - ( ),
Arduino.
, ,
;
+ serial.read () - ,
.
, Serial. read ()
, ,
serial. availae () . ,
serial. read () , ,
. 6.3 Arduino.

/ /
char data; //

void setup ()
{
Serial.begin(9600); //
// 9600
130 //.

void loop()

//
if (Serial.availae() > )

data = Serial.read(); //
Serial.print(data); //

-
. , , ,
.
Newline,
(\n), , .
serial.println() 6.3
Serial.print()

char int
-
"5" "". ,
.
, ,
ASCJJ. ASCII (. 6.9) 7-
, 128 .
, ,
, char (. 6.3).
, , ,
. 6.3,
data int, , 5,
53 ( "5").
, . 6.9.
, Arduino .
? . -,
. 1,
:
if(Serial.read () == '1')
1 ,
.
' ' :
int val = Serial.read() - '0'
9,
. parseint(), Arduino IDE, -
. USB 131

Dec Char
NULL null
Dec Char
20 32 Space
Dec Char
40 64 @ 60 96 -
Dec Char

OxOl 1 SOH Start of headinq 21 33 ! 41 65 61 97


02 2 S'l'K Start of text 22 34 " 42 66 62 98
03 3 End of text 23 35 # 43 67 63 99
04 4 . End of transmission 24 36 $ 44 68 D 64 100 d
05 5 ENQ Enquiry 25 37 % 45 69 65 101
06 6 Acknowledqe 26 38 & 46 70 F 66 102 f
07 7 BELt. Bell 27 39 47 71 G 67 103 g
BS Backspace 28 40 ( 48 72 68 104 11
09 9 Horizontal tab 29 41 ) 49 73 ! 69 105 .i
10 LF New line 2 42 * 4 74 J 6 106 j
11 VT li'ertical tab 2 43 + 4 75 : 6 107 k
12 FF Form Feed 2 44 ' 4 76 L 6 108 1
OxOD 13 CR carriage return Ox2D 45 - Ox4D 77 Ox6D 109
14 so Shift out 2 46 . 4 78 N 6 110 !!
OxOF 15 SI Shift in Ox2F 47 / Ox4F 79 Ox6F 111
OxlO 16 DLE Data link escape 30 48 50 80 70 112
Oxll 17 DCl Device control 1 31 49 1 51 81 Q 71 113 q
12 18 2 Device control 2 32 50 2 52 82 R 72 114 r
13 19 D Pevice control 3 33 51 53 83 s 73 115 s
14 20 DC4 Device control 4 34 52 4 54 84 74 116 t
15 21 N Negative ack 35 53 5 55 85 u 75 117 u
16 22 SYN Synchronous idle 36 54 6 56 86 v 76 118 v
17 23 End transmission k 37 55 7 57 87 w 77 119 w
18 24 CAN Cancel 38 56 58 88 78 120
19 25 End of medium 39 57 9 59 89 79 121
OxlA 26 SUB Substitute 3 58 : OxSA 90 z 7 122 z
OxlB 27 FSC Escape 3 59 ; OxSB 91 1 7 123 {
OxlC 28 FS File separator 3 60 < 5 92 \ 7 124 i
D 61 "'
OxlD 29 GS
OxlE 30 RS
Group separator
Record separator 62 >
Ox5D 93 J
OxSE 94 '
Ox7D 125 }
7 126 -
OxlF 31 us Unit separator F 63 ? Ox5F 95 - Ox7F 127 OEL
. 6.9. ASCII

.
.



,
. "1",
, "", .
9 Arduino, . 6.10.
,
. , ,
1 . Arduino
6.4
.
132 //.

. 6.10. 9 Arduino

//
const int LED=9;
char data; //

void setup(}

Serial.begin(9600}; //
// 9600
pinode(LED, OUTPUT};
. USB 133

void loop()
{
//
if (Serial.availale() > )

data = Serial.read(); //

//
if (data == '1')

digitalWrite(LED, HIGH);
Serial.println("LED ON");

//
else if (data == '0')

digitalWrite(LED, LOW);
Serial.println("LED OFF");

, else
else if. ,
. ,
Serial.read() , 1 ,
. else,
1 . 1
,
\n!


RG-

, ,
? ,
, .
, RG- ,
. 6.11.
RG- m 8-
(0-255), . ,
, "255,255,255".
, :
134 //.

+ ;
+ , -
analogWrite () ;
+ , .
, Arduino IDE
- Serial. parseint () .
.
, ,
, .
, , 6.5
Arduino.

. 6.11. RG- Arduino


. USB 135

//
// RG-
const int RED =11;
const int GREEN =10;
const int BLUE =9;
// RGB
int rval ;
int gval ;
int bval ;

void setup()
{
Serial.begin(9600); //
// 9600
// OUT
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);

void loop()

//
while (Serial.availae() > )
(
rval Serial.parseint(); //
gval Serial.parseint(); //
bval Serial.parseint(); //
if (Serial. read() -- '\n') //
(
//
analogWrite(RED, rval);
analogWrite(GREEN, gval);
analogWrite(BLUE, bval);

,
(\n). ,
.
255, ,
"200,30, 180". ,
.
136 1/.

6.7.
, "" Arduino
Arduino IDE. ,
- ,
.
,
Arduino , Arduino .
Processing,
Arduino, . ,
Arduino Processing!
,
, - Python, , Visual Basic, . . ,
Processing, ,
(GUI)
Arduino.

6.7.1. Processing
Processing ,
Arduino.
Processing,
, Arduino .
,
Arduino , .

6.7.2. Processing
Processing . ,
1, Arduino IDE.
http://processing.org/download/ ( www.
exploringarduino.com)
. !
Processing, ,
. 6.12.

6.7.3. Arduino
Processing
Processing
Arduino , .
, . 6.6. Arduino
. ,
Processing, ,
.
. USB 137

. 6.12. Processing. ?

6.6 Arduino. Arduino



50 . , Processing

.

//
const int =; //
int val; //

void setup()
{
Serial.egin(9600); //
// 9600

void loop()
138 11.

val = rnap(analogRead(POT), , 1023, , 255); //


//
Serial.println(val); //
delay(50); // 50

. 6.7

.
6.7 . Processing
.
"" . , Linux
/dev/ttyUSBO. ,
Arduino IDE.

// Processing JI
// Serial
import processing.serial.*;
Serial port;
float brightness = ; // JI

void setup()
{
size(500,500); //
port = new Serial(this, "", 9600); //
//
port.bufferUntil('\n'); //

void draw{)

background(O,O,brightness); //

void serialEvent (Serial port)

brightness = float(port.readStringUntil('\n')); //

Processing IDE
, Arduino IDE
.
. rssing- -
. USB 139

( ),
.
(. 6.13).


. 6.13. ssing-

, , ,
. Arduino, serial
. import processing . serial. * Serial port,
serial serial port.
Arduino, Processing setup (),
. setup ()
500500 size (500, 500).
port = new Serial (this, "", 9600) Processing
. ( port)
( ) 9600 .
Arduino
, .
port. bufferuntil ( \n ) rssing-
(' \n' ).
loop () Processing .
draw () serialEvent () . draw () loop ()
Arduino, . ackground ()
, ,
.
, .
,
. RGB 8-
255, map ()
.
serialEvent () ,
bufferuntil (), setup (). -
140 //.

serialEvent() .
port.readStringUntil( \n ).

, float().
brigthness, .
,
rssing- ( ,
).

SudoGlove - -
. Processing
, SudoGlove.
www.sudoglove.com.
www.jeremyum.com/2011/03/25/processing-based-sudoglove-visual
debugger/. Wiley.

6.7.4. rssing-
Arduino
- rssing- Arduino.
RG- Arduino, . -6.11,
,
, (. 6.5).
,
, .
6.8 rssing-,
, .
(data) .
hsv.jpg ( )
. data ,
. rssing-
. . 6.14.

import processing.serial.*; // serial


Pimage img;
Serial port;

void setup()
{
size(640,256);
img = loadimage("hsv.jpg"); //
6. USB 141

port = new Serial(this, "9", 9600); //


//

void draw()

background(O); //
irnage(img,0,0); //

void mousePressed()

color = get(mouseX, mouseY); // RG-


// 11

String colors int(red(c))+","+int(green(c))+","+int(ue(c))+"\n";


=

//
print(colors); //
port.write(colors); // Arduino

,, Favorites Documents library


8 Oesl<top p:s.s,J'\q"to-n.:.i1_KGB
Oownloacfs
ui Google Onve tl data U,t,, 0'<Y1if1ct! 5/10/20 11:35
1 Dropox
Recent Places :11 proce,sing_controt_RGB.pde ON! ncd.f 1d 1/22/20 2:26
, .. r;,,,e l'rocessing S <! $,1.: 709 bytes
;u,anes:

.1t Googl Orive


,t. usic
.., Pictufes
,IVideos

. 6.14.

, . 6.15.
, RGB Arduino
RG-. , Arduino,
,
.
142 11.

. 6.15. Processing

, .
, serial port.
Pimage img. .
setup () ,
, img
img=Load!mage ("hsv. jpg").
draw () irnage (irng, , )
: Irng - , , -
( ).
rnousePressed (). ,
, color . get ()
, (
). ,
, .
.
Arduino 6.5.
rssing- , Arduino,
.
. USB 143

6.8.
Arduino Leonardo (
32U4)
Leonardo, i,
USB,
, , , . .
. ,
, ,
, Arduino
IDE. ,
.

Mii=JIM
"" ,
, Reset,
Arduino IDE.

Leonardo
, Arduino Uno (. 1). Leonardo
http://arduino.cc/en/Guide/ArduinoLeonardoMicro#toc8
www.exploringarduino.com.

6.8.1.
Leonardo US-, i
Arduino .

, .
Leonardo US-,
. .
, ,
( CSV), Excel
Google SpreadSheeets .
,
csv.
,
data.csv.
, . 6.16.
,
, 3. ,
,
, .
/
(. 2). i Arduino -
144 //.


/

. 6.16.

, .
. Arduino
, 1
delay (), millis(),
Arduino. m ,
millis() , 1 ,
m, 1 . r
(%). , , 1000%1000,
, . . 1000/1000= 1 . 1500%1000 500,
1500/1000= 1 500. millis() 1000, -
6. USB 145

, millis() ,
1000, . . .
6.9 Arduino Leonardo. ,
Arduino Leonardo -> Board Arduino
IDE.

//
const int =; //
const int LIGHT=l; // 1
const int LED=; /! 13
const int BUTTON=2; // 2

boolean lastButton = LOW; //


boolean currentButton = LOW; //
boolean running = false; //
int counter = 1; //

void setup()
{
pinode (LED, OUTPUT); // OUPUT
Keyboard.begin(); //

void loop()

currentButton = debounce(lastButton); //
if (lastButton == LOW && currentButton HIGH) // ...
running = !running; //
lastButton = currentButton; //
if (running) //
{
digitalWrite(LED, HIGH); //
if (millis() % 1000 == ) // 1000
{
int temperature = analogRead(TEMP); //
//
int brightness = analogRead(LIGHT); //
//
Keyboard.print(counter); //
Keyboard.print(","); //
Keyboard.print(temperature); //
Keyboard.print(","); //
Keyboard.println(brightness); //
//
counter++; //
146 11.

else

digitalWrite(LED, LOW); // ,
//

/*
*
* .
*/
boolean debounce(boolean last)

boolean current = digitalRead(BUTTON); //


if (last != current) // ...

delay(5); // 5
current = digitalRead(BUTTON); //

return current; //
//

,
.
, Keyboard.begin() setup().
loop() Arduino
.
. ! running.
,
1 , .
. Keyboard.print()
.
.
Keyboard.println() Arduino <Enter> ( <Retum>)
.
.

. , .
,
. ,
.
, . ,
.
6. USB 147



http://www.exploringarduino.com/content/ch6.

6.8.2.

Leonardo .
Windows
<Windows>+<L> ( Linux
<Ctrl>+<Alt>+<L> ). , ,
, . OS
<Control>+<Shift>+<Eject> <Control>+<Shift>+
+<Power>, Leonardo , . .
<Eject> <Power>. ,
Windows. , . 6.16,
.

.
,
(
300, - 700, 500).
,
. ,
.
6.1 Arduino.
.
, , !

//
const int LIGHT =1; // 1
const int THRESHOLD =500; //
//

void setup()
{
Keyboard.begin();

void loop()

int brightness = analogRead(LIGHT); //


148 11.

if (brightness < TRESHOLD)

Keyboard.press(EY_LEE'I'_GUI);
Keyboard.press('l');
delay(100);
Keyboard.releaseAll();

.
.

,
http://www.exploringarduino.com/content/ch6.

:
Keyboard.press() Keyboard.releaseAll(). Keyboard.press()
.
<Windows> <L>, Keyboard.press() .
, Keyboard.releaseAll(),
. http://arduino.cc/
en/Reference/eyboardModifiers.

6.8.3.

Arduino Leonardo . ,
, .
, Arduino ,
.
, . 6.17.
, .
1.
, .
, -
.
. 6.17 SparkFun, (
Parallax). ,
, map()
.
, Leonardo.
6.1 1 ;
.
. USB 149



. 6.17. Leonardo

// II !
const int LEF BUTTON=4; // 11
const int MIDDLE BUTTON=; /! 11
const int RIGHT BUTTON =2; // 11
const int AXIS=O; //
const int AXIS=l; //

void setup ()
150 //.

Mouse.begin();

void loop()

int xVal readJoystick(X_AXIS); //


//
int yVal = readJoystick(Y_AXIS); //
//
Mouse.move(xVal, yVal, ); // J

readButton(LEF_BUTTON, MOUSE_LEF); //
//

readButton(MIDDLE_BUTTON, MOUSE_MIDDLE);//
//
readutton(RIGHT_BUTTON, MOUSE_RIGHT); //
//
delay(5);

// ,
int readJoystick(int axis)
{
int val = analogRead(axis); //
val = map(val, , 1023, -10, 10); //
if (val <= 2 && val >= -2) // 1
return ;
else //
return val;

// 1

void readButton(int pin, char mouseCommand)

// , ,
if (digitalRead(pin) == HIGH)

if ( ! Mouse.isPressed(mouseCommand))

Mouse.press(mouseCommand);

// J

else

if (Mouse.isPressed(mouseCommand))
. S 151

Mouse.release(mouseCommand};

, , ,
. ,
.
,
setup (} . loop ()

.
.
readJoystick () .
1024, .

Mouse.move(} .

, - . ,
. , readJoystick (} 1023
-1 1 .
,
. ,

512. ,
.
ouse.move(), .
ouse.move () .
readutton() .
ouse. isPressed (}
Mouse. press(} Mouse.release().



http://www.exploringarduino.com/content/ch6.

:
+ Arduino US-
.
152 11.

+ US-
Arduino.
+ Arduino US-.
+ .
+ ,
.
+ -
.
+ Arduino Pro
cessing.
+ rssing-
, Arduino.
+ Arduino Leonardo .


:
+ Arduino Uno;
+ US- - ( Uno);
+ 8 ;
+ 3 ;
+ 5 ;
+ 8 220 ;
+ SN74HC595N DIP-opnyce;
+ GP2YOA41 SKOF ;
+ ;
+ .

r
http://www.exploringarduino.com/content/ch7
, . ,
www.wiley.com/go/exploringarduino
Downloads.

r
Arduino,
: " , Arduino?"
, Arduino
. ! !
! , , .
. , 50
( ), -
154 //.

? r ,
Arduino
-.
, ,
, ,
Arduino.

.
, ,
Arduino Uno. Arduino,

. , Arduino
, Mega 2560 Due? ,
, . ,
, .
Arduino Uno ,
, .
, .
, .

7.1.
- ,

.
, ,
. Arduino,
. 7.1, .
, .

. 7.1.

,
. -
Arduino.
7. 155

7 .2.

. ,
Arduino, , ,
. . "" "" "1 ". ,
8 .
digitalWrite () analogWrite ().
, , 8
, 8 .
. 6
,
1 .
.
- (SIPO),
.
, . ,
,
Arduino.

7 .3. 7 4595
74595,
. 7.2.

1 16 Vcc
2 15
14 SER
4 13
OF 5 12 RCLK
OG 6 11 SRCLK
7 10 SRCLR
GND 8 9
. 7.2. 74595

7.3.1.
:
+ QA - QH - ;
+ GND - Arduino;
156 //.

+ SER- (DA . 7.1). 8



;
+ SRCLK- (CLOCK . 7.1).
IGH
DA . 8
8 ;
+ RCLK- (LA . 7.1)
.
SRCLR ,
, , . -
. ,
- . ,
, - .
,
.
- Arduino,
. SRCLR - .
.
5 , .

7.3.2.
,
. , CLOCK
, ,
, .
, Q' (
74595). DATA
. ,
. LA ,
, .
. 7.3.
, ,
, QA, QC, QE,
QG.
10101010. , .
LA,
. ,
CLOCK, DA .
, LA
.
7. 157

LATCH !!!
LOW LATCH s
ID
----)18--..iG ff
LOW
DATA DATA ...
.

...s
LOW CLOCK _L

LOW LATCH LOW LATCH

LOW DATA -----.iG DATA

_L _L

LOW LATCH LOW LATCH

LOW DATA ------......


..iG DATA

_L _L

1
!!! 1 !!!
LOW LATCH s LOW LATCH s
ID O ID 1
ff ff
LOW DATA .
1

----)18-
..iG DATA .
1
t:;
s t:;
s
1
_L _L 1

LOW LATCH I LATCH

LOW DATA -----.. DATA

_L LOW CLOCK

. 7.3.
158 //.

7.3.3. Arduino

Arduino
. Arduino IDE shiftOut(}
Arduino.
:
+ DATA;
+ CLOCK;
+ ;
+ , .
, ,
shiftout(} :
shiftOut(DATA, CLOCK, MSBFIRST, 810101010);
1 1 ' 1 1 '
6 D 1 - Arduino . -
MSBFIRST , (
) . LSBFIRST,
. -
. Arduino IDE,
.
. Arduino
: DATA 8 , LATCH 9, CLOCK
1.
,
(220 ). . 7.4.
, Arduino
IDE shiftOut(},
( 7.1).

const int SER=8; // 11 DATA

const int LATCH =9; // 11 LATCH


const int CLK =10; // 11 J CLOCK

void setup(}
{
// (OUTPUT}
pinode(SER, OUTPUT};
pinode(LATCH, OUTPUT};
pinode(CLK, OUTPUT};
7. 159

digitalWrite(LATCH, LOW); // LATCH -


shiftOut(SER, CLK, MSBFIRST, 810101010); // -
digitalWrite(LATCH, HIGH); // LATCH -

void loop() { ; }

. 7.4. 8

,
setup() .
. , . 7.3.
160 //.

LATCH ,
shiftOut() , LATCH ,
.
,
. . , ? !
,
, Arduino.
. . 7.2,
Q'. ,
, Q'. Q'
DA , LATCH CLOCK
, 16- ,
16 . ,
,
Arduino.

shiftout() ( shiftOut()
8 ).

7.3.4.

7.1
.
. , ,
(base2) (base1) .
( , ) 2.
.
(. 7.5).

1128 + 4 + 132 + l + 18 + 4 + 12 + Oxl = 170


. 7.5.


2. 7, 5, 3, 1 [()'. ,
, 27, 25 , 23 i.
170. , ,
7.1.
shiftout() :
shiftOut(DATA, CLOCK, MSBFIRST, 170);
, , .
7. 161

7 .4.


.
.
" " "".

7.4.1. " "


" " - ,
, .
. shiftout ()
, .

, . (. 7.6) ,
,
.
shiftout ()
.
. 7.2.

t=l 0000000 1
t=2 000000 2
t=3 QQQQQ QQ 4
t=4 0000 s
t=S 0000 16
t=6 00' 00000 32
t=1 000000 64
t=S QQQQQQQ 128
t=9 000000 64
t=10 00 00000 32
t=11 0000 16
t=12 0000 s
t=13 00000 00 4
t=14 000000 2
. 7.6. " "
162 //.

// " "
const int SER=8; // DATA
const int LATCH =9; // LATCH
const int CLK =10; // CLOCK

//
int seq[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2};

void setup()
{
!/ (OUTPUT)
pinode(SER, OUTPUT);
pinode(LATCH, OUTPUT);
pinode(CLK, OUTPUT);

void loop()

for (int i = ; i < 14; i++)

digitalWrite(LATCH, LOW); // LATCH -


shiftOut(SER, L, MSBFIRST, seq[i]); // -
digitalWrite(LATCH, HIGH); // LATCH -
delay(lOO); //

, .
,
.

lightrider
http://www.exploringarduino.com/content/ch7.
Wiley.

7 .4.2.
- ,
, , .
.
-
. 7.7.
7. 163

. 7.7. , " "

,

(. 7.8).
3 , -
1 ( 500,
).
.
.
8. 7.3
.

//
const int SER=8; // DATA
const int LATCH =9; // LATCH
164 11.

const int CLK =10; // CLOCK


const it DIST =; !/

//
int vals[9] = {,1,,7,15,l,63,127,255};
!/
int maxVal = 500;
/!
int minVal = ;

void setup()

!/ (OUTPUT)
pinode(SER, OUTPUT);
pinode(LATCH, OUTPUT);
pinode(CLK, OUTPUT);

void loop()

int distance = analogRead(DIST);


distance = map(distance, minVal, maxVal, , 8);
distance = constrain(distance,0,8);
digitalWrite(LATCH, LOW); // LATCH - -
shiftOut(SER, CLK, MSBFIRST, vals[distance]); // -
digitalWrite(LATCH, HIGH); // LATCH -
delay(10); //

00000000
0000000 1

000000 3

00000 7

0000 15

0000 31

0000 63

127

255
. 7.8.

7. 165

Arduino,
- . ,
. ,
maxVal minVal,
. ,
,
setup() Serial.println(DIST)
analogRead(DIST).


,
, http://www.exploringarduino.com/content/ch7.
Wiley.

:
+ .
+ .
+ .
+ .

8. 12
9. SPI
10.
11.


:
+ Arduino Uno;
+ US- ( Uno);
+ l ;
+ 3 ;
+ 4 ;
+ 8 220 ;
+ 2 4,7 ;
+ SN74HC595N DIP-opnyce;
+ I2 c TC74A0-5.0VAT;
+ ;
+ .


http://www.exploringarduino.com/content/ch8
, . ,
www.wiley.com/go/exploringarduino
Downloads.


, -,
? Arduino
,
.
,
. I2 c.
170 111.

I2C
-. I2c
( )
, .
I2C ,
, ,
. , ,
.


,
, http://www.jeremyum.com/2011/02/13/
arduino-tutorial-7-i2c-and-processing/ 1.
Wiley.

8.1. 1 2
, ,
, . I2C
Philips 1980-
. 1990
,
. "",
:
. , ,
I2C (- ), , ,
I2 -. LEENEX
, . -
, "" ,
, , .

8.2. 1 2
I2C . 8.1.
, , I2 C
, :
(SCL) (SDA).
.
, I2 C .

I
: http://wiki.amperka.ru/eoypo:7-i2c--processing.
8. 12 171

::>
t()
+

,:..j
(
Q.i
,_,;::,
(..) >
f\)
(..)
::, SDA SDA 1'
:i::
u z SCL
,) SCL u
t!
N
.....
N
......

GNO GNO

Q.i
u
(...)
>
SOA :::> ......
(\)
U)
SCt. u
(.!)

GNO
2
. 8.1. 1

8.2.1.
2
1
. ()
Arduino. .
,
, m .
, ,
. ,
,
.
, ,
. 7-
( , ID ).
, .
, , , .
2
1 .
2
1 , - ,
2
. 1 -,
.
2
1 -,
2
1 . -
172 1/1.

74. . 8.2 ,
J). TC74A0-5.0VAT
( -220) I2 - 1001000.

f =f f f
Exemples;
PA8f N9
) 74..V: -220 Serial Digital Thermal Sensor
Device Address Supply Operating Package
) 741-3.V: -220 Serial Digltal hennal Sesor
Options Voltage Temperature
,--. ) 742...V: -220 Serial Digital Thermal Sensor
Devlce; 74; Seriat 0/gital Therma! Senor d) 7433.3V: -220 Serial Digital Thennal Sesor
eJ 7443.V: -220 Serial Digital Thermal Sensor

Address Options: = liJOl (}()\)


1 1001 (;(l
f) TC74AS-3.3VA:
746-3.V:
-220 Serial Digtlal Thermal Sensor
-220 Serial Digital Thermal Sensor
g)
= 1001 01() h) TC74A7-3.3VAT: -220 Serial Digital hermal Sensor
3 " 10, (111
= 10(>1 ,
5 =- lCOl 101 ) TC74AO.S.OVAT. -220 Serial DigaJ Thermal Sensor
6
7
= ioi
11:01 111
) TC74A15.0VAT: -220 Serial Digitl Thermal Sensor
) TC74A25.0VAT: -220 Serial Digitl Thermal Sensor
Default Address d) TC74A3-5.0VAT: -220 Serial Digltal hetmal Sensor
TC74A4-5.0VAT: -220 Serial Digital Thermal Sensor
Ou!put Volt8g: . =
Accuracy optimiad for 3.V
)
f) TC74A5-5.0VAT: -220 Serial Digital Thermal Sensor
5 0 = ACCUl8CY op\imizlld for 5.0V
g) TC74A6-5.0VAT: -220 Serial Digal hermal Sensor
h) 747-5.0VAT: -220 Serial Digitat hermal Sensor
Operang Temperature: v " -4 s :,; +12sc
Oefault Address

Peck&lge: -220-5

. 8.2. 74.
2
1


, I2 c
. ID,
.
, , AD7414 AD7415 (AS),
I2C. AD7414
(. 8.3).
AD7414 , AS
. , AS,
: , m .

Table 4. 11 Address Selection

PartNumber
AD7414-0
ASPin
Float
12CAddress
1001
AD7414-0 GND 1001 001
AD7414
TopVlew AD7414-0 Voo 1001 010

I
{Not to Scate)
AD74141 Float 1001100
4 SCL AD7414-1 GND 1001101
AD7414-1 Voo 1001110
Fige 3. AD7414 / Configuration (SOT-23) AD7414-2 N/A 1001 011
AD7414-3 N/A 1001111
2
. 8.3. AD7414. 1
2
8. / 173

8.2.2.

. 8.1 , 12
.
,
. 4, 7 , -
, .

8.3. 1 2
I2c
. , Arduino 12
.
12- .
I2c.
12- :
+ .
+ 7- .
+ "1" () "" ()
,
.
+ ( ).
+ , ,
. ,
.
+ , -.
8.3.1.
, , ,
.
, .
, ,
. !
Arduino, . 8.4.
, SDA SCL 4
AS . , SDA SCL -
, . Arduino 4 AS
- () 12.
Wire 12
Tmega, Wire I2-.
174 111.

. 8.4.

4 AS ,
12.

8.3.2.
, Arduino
I2- . Wire
. ,
,
. ,
, . 8.5 8.6.
. 8.6 , 74.
:
. /2 175

1
s WR
7

: : ,
,

s WR s RD NACK
7 7 8

: :
:
,


I S
I I RD NACK

S = START Condition - -
= STOP Condition - -
=
WR- ()
RD - ()
-

. 8.5. 74

, - r (
). . 4.1 . 8.6.
,
. . 4.3 4.4 . 8.6 ,
8- .
Write Byte fonnat . 8.5 ,
74:
+ , ,
;
+ (1 )
;
+ 8 .
, 12-.
, Arduino
176 111.

74
4.0 REGISTER S AND L4-3: TEMPERATURE REGISTER
PROGRAMMER'S MODEL ()
0(7) 0(6] D(5] 0(4] D[] Dl2] 0(1) D/01
TABLE 4-1: ND MSB LSB
DESCRIPTION ln temperature dala registers. each unit value repre
(SMBUSJl2c READ_BYTE AND scnts onc dcgocc (Gclsi11sJ h valuo ls in 2s
WRITE BYTEI- complemenl blnary format such lha! reading of - r-r,.,
Command Code Funclion ,..):,., corresp<,nds to '. Examples of this
temperature to binaoy val; relafiorn;l1ip are s110.v11 in
RR OOh Read Temperat\Jre () Table4-4
RWCR 01h ReadNVrile Configuration
(CONFIG) L 4-4: EPERAURE-TO-DIGITAL
VALUE CONVERSION
TABLE 4-2: CONFIGURATION REGISTER ()
(CONFIG); 8 BIS, READI
Actual Registered Binary
VVRITEJ Temperature Temperawr.
Bit POR FunclJon Operalion +1' +t27"C 1 11
7J () olANUl!Y Heacll = slandby +12700' +127" ,; __1 __
S..'lilch \Nrit.e -: normal
+12.50' +12" 1; __ 1 __ 1,:
DIJ Dala Ready' Read _ = ready +2525" +25' ;;_,1 ..,,.1

015]- Q ResetVed -
Only :: = o,ot ready
N/A N/A
+05 ; ... 1)"

D[OJ Alway,; +025' ,;":,( ":,(1,;

returns zero ' :1(1 :(11.11.:;

1vhenread -o.2sc ., 1._1 __ !!


Notc 1: 'UII\_HUY ilHl:.Sl:.I al po,ver-up and - 50' -1' 11
SHDN n
75' 1' 1 11
-1 -1' 1 __1 __
-25.' -25" 1 __(, __11
-2525'(; -26" 1 .,,.. 1,
Vr.n--- -54 75' .55i.; 1 ... 1)1

-5500' -55" ,1 _ ( -(!


1 1 -6500' __
r,---\I
-65" 1:_1
DAT_RDY\\\\\'. \ \ \\\\\\\
4.2 Register Set Summary

.-. .
1 1 h 74 register set is summarized in 4-5 AI
---.__ regitrs are 8 its. \ide
t..x.111 t1,11N
TABLE 4-5: 74 REGISTER SET
FIGURE 41: DATA_RDY. SHDN SUMMARY
Operation Logic Digram. POR
Name Description Read Write
State
4.1 Temperature Register (),
8 Bits, READ ONLY lnternal Sens0t ( ....
Ten,perature (2 s ::( (1) ..; N/A
The inary val,oe (2 s con1plemen1 formet) in this regis Complemenl)
ter represents temperature of the onboard sensor CONFIG CONFIG
followi11g .> oonversion cycle registers are
Register
(J
::,,, .. ..; .;
automatica/ly updated in an allernating manner
NOlle 1: The regoster will immediately
updatcd thc / convcotcr a"cr thc
DATA_RDY Bit goes high.

1i,)2001-2012 Micrcchip Tec;.,notogy lnc

. 8.6. 74
2
8. / 177

I2c. ,
, .

8.3.3.
, Arduino Wire
I2 c.
. 8.1,
, Wire.

// I 2 -
//
// Wire
#include <Wire.h>
int temp_address 72; // 1001000

void setup()

//
Serial.begin(9600);
// Wire
Wire.begin();

void loop()

//
//
Wire.beginTransmission(temp_address);
// asking
Wire.write(O);
// -
Wire.endTransmission();

//
// 1
Wire.requestFrom(temp_address, 1);
//
while(Wire.availale() == );
//
int = Wire.read();
//
int f = round(c*9.0/5.0 +32.0);
178 111.

//
//
Serial.print(c);
Serial.print("C ");
Serial.print(f);
Serial.println("F");
delay(SOO);

. Wire. beginTransrnission()
, ( )
. wire.write() "", ,
. -,
Wire.endTransmission(), .
12. Wire. requestFrom () -
12 -.
Wire.availae() ,
12. , 8-
Wire. read().
8.1
. .
.
8.1 Arduino
. ,
, . 8.7.

= []

_
9
',,
...............
27 81F
27 81F
27 81F
27 81F
27 81F
27 81F
27 81F
27 e1r
2 ?9F
27 81F
27 81F
27 BlF
27 SlF
Autoscrotl
2
. 8.7. 1 -
8. /2 179

8.4. , ,
1 2
, 12 -
,
. (. 7), rssing-,
.

8.4.1.
(. 8.8).
, . 8.4.

. 8.8. 1 2-
180 111.

8.4.2.
rssing-
, 8.1 .
-,
:
Serial.print(c);
Serial.print("C,");
Serial.print(f);
Serial.print("F.");
Processing
. ,
, .
-,
(. 7) map(),
. 7.3,
.

. , , (
).
, .
24 31 (75-88 F), .
8.2 .

11-rr 8.2. r t f-. n't ootspa)l(e1tJtM


.q r"r
\ ''
tn1
,,, ..
nQn
., . " . . '
nop:r
.,,
-temp,
. ..:...-.
.
,J. nit.ino
.,1
.

// I 2 - ,
//
// rssing-
// Wire
#include <Wire.h>
const int SER =8; // DATA
const int LATCH =9; // LATCH
const int CLK =10; // CLOCK
int temp_address = 72;

//
int vals[8] = {1,,7,15,31,63,127,255};

void setup()

//
Serial.begin(9600);
// Wire
Wire.begin();
2
8. 1 181

// (OUTPUT)
pinode(SER, OUTPUT);
pinode(LATCH, OUTPUT};
pinode(CLK, OUTPUT};

void loop()

//
//
Wire.beginTransmission(temp_address};
// asking
Wire.write(O};
!/ -
Wire.endTransmission(};

//
// 1
Wire.requestFrom(temp_address, 1};
//
while(Wire.availale() == );
//
int = Wire.read();

//
int graph = map(c, 24, 31, , 7};
graph = constrain(graph,0,7);
digitaJWrite(LATCH, LOW}; // LATCH - -
shiftOut(SER, CLK, MSBFIRST, vals[graph]); // ,
// -
digitalWrite(LATCH, HIGH); // LATCH - ,

//
int f = round(c*9.0/5.0 +32.0);

//
//
Serial.print(c);
Serial.print("C,"};
Serial.print(f);
Serial.print("F."};
delay(SOO};

8.2 Arduino ,
. ,
. .
182 111.

Processing,
.

8.4.3. Processing
Arduino
. ,
.
,
, Processing. Processing
npoee . ,
. Tools -> Create Font ,
. 8.9.

. 8.9. Processing-npoee

(
200). .
data .
Processing :
+
.
2
8. / 183

+ ,
.
+ -
.
8.3,
. Arduino
. !

// , I 2-
import processig.serial.*;
Serial port;

String temp_f - .. .
String temp_c = "";
,
String data "" ,
int index = ;
PFont font;

void setup()
{
size(400,400);
// "9"
port = new Serial(this, "9", 9600);
port.bufferUntil('.');
// ,
font = loadFont("AgencyF-Bold-200.vlw");
textFont(font, 200);

void draw()

background(0,0,0);
fill(46, 209, 2);
text(temp_c, 70, 175);
fill(O, 102, 153);
text(temp_f, 70, 370);

void serialEvent (Serial port)

data = port.readStringUntil('.');
data = data.sustring(O, data.length() - l);
// -
index = data.indexOf(",");
184 111.

//
temp_c = data.substring(O, index);
//
temp_f = data.sustring(index+l, data.length());

Processing,
serial . setup()
,
.
draw()
. fill()
Processing ( RGB) ,
. seria!Event()
bufferuntil(), ,
, .
, .
. 8.1 .

. 8.10. Processing

rssing-,
.



http:/lwww.exploringarduino.com/content/ch8.
Wiley.
8. /2 185

:
+ Arduino I2 c 2
( ) I c.
+ Wire I2 -,
4 5 .
+ I2 c
.
+
Processing.
+ , I2 -, Arduino,
Processing.

Arduino Uno;

US- ( Uno);

1 ;

1 ;

1 ;

1 ;

4 100 ;
2 4,7 ;
+ ;
+ SPI 4231;
+ ;
+ .

http://www.exploringarduino.com/content/ch9
, . ,
www.wiley.com/go/exploringarduino
Downloads.

, Arduino:
I2 c UART.
, Arduino, -
( SPI).
I2 c, SPI
, .
9. SPI 187

,
. SI-, I c,
2
. Arduino IDE
SPI Arduino r1
.
, ,
.


,
http://www.Jeremyum.com/2011/02/2011/02/20/ardulno-tutorialB
spl-lnterfaces1. Wiley.

9.1. SPI
SPI, "",
,
()
. SPI
, SPI
(,
).
SPI, Arduino IDE.

!
SPI ,
, .


SPI. SI-
,
(SCLK).
, (
), SCLK
( ).
, SPI
(. 9.1).

9.1. SP/ Arduino IDE

SI
1 ModeO LOW
2 Mode 1 LOW

I
: http://wiki.amperka.ru/eoypo:8-epec-spi.
188 111.

9.1 ()

N11 SPI

3 Mode2 HIGH
4 d HIGH

9.2. SPI
SPI .
:
+ (SCLK);
+ , (MOSI);
+ , (MISO).

( SS). , -,
-, +, - .
SI- . 9.1.

------1
...----..... 1
...

__
__.
1
.__

r---- ____ __J

. 9.1. Sl-
9. SPI 189

9.2.1. SPI
SPI , , .
SS.
SPI, ,
- (. 9.2).
9.2. - SPI

SPI
MOSI

MISO

SCLK
ss , -

12 , ,
. , SPI
Arduino, MOSI, MISO, SCLK SS.
Arduino SPI.
SPI ,
SPI - SPI.
CS, - CLK; MOSI MISO
(SDI)
(SDO) .

9.2.2. SPI
SPI
SS. , ,
MOSI, MISO, SCLK . SS
, .
, SS
.
SPI
:
1. SS ,
.
2. ,
,
.
3. 1 MOSI 1
MISO.
190 11/.

4. , ( ) , -
.
5. SS .
, (
). ,
Arduino , .

9.3. SPI 1 2
, , ,
. ., SPI- 12-. ? . 9.3
1 2 SPI. ,
.
, SPI , 12 .
2
9.3. SPI /

SPI 1 2


Arduino

Arduino

9.4. SPI
.
(
digipot). SPI
4231 1.
. ,
,
. 4231
. 7 , 128
10 .
, digipot
. ,
.

9.4.1. 4231
, 4231,
Google. -
9. SPI 191

4231 www.exploringarduino.com/
content/ch9.
:
+ ;
+ ;
+ ;
+ SPI , .
, . 9.2-9.4
. ,
4231, . 9.2.

CS Voo
SCK SDO
SDI SHDN
Vss WP
1
P1W POW
1
PDIP, SOIC, TSSOP
. 9.2. 4231


. 4231:
+ , POW - ;
+ PIA, PIW I- ;
+ VDD- 5 ;
+ VSS- ;
+ CS- SS SPI, ,
( - , 5 - );
+ SDI SDO- (
MOSI MISO);
+ SCK- SPI;
+ SDN WP- , .
4231 WP .
SDN , CS.
.
, SDN 5 .

. ,
.
192 111.

, .
(. 9.3).
, , R,
,
( 5 100 ). 103,
1 . , ,
, ( . 9.3 ,
20% ). ,
75 160 .
,
.

AC/DC CHARACTERISTICS (CONTINUED)


Standard Operating Conditions (unless otherwise specified)
Operating Temperature "
-4 :. +125" (extended)
DC Characteristics AII parameters apply across the speclfied operating ranges unless noted.
V00 = +2.7V to 5.5V. 5 kQ, 10 kQ, 50 kQ, 100 kQ devices.
Typical specifications represent values for V00 = 5.5V. = +25.
Parameters Sym Min Units Conditions
Resistance R 4.0 5 6.0 kQ -502 devices (Note 1)
( 20%} 8.0 10 12.0 kQ -103 devices (Note 1)
40.0 50 60.0 k(} -503 devices (Note 1)
. 100 120.0 kQ -104 devices (Note 1)
Resolution N 257 Taps 8-blt No Missing Codes

Step Resistance Rs - 129


R/ -
Taps
Q
7-blt
8it
No Missing Codes
Note6

-
(256}
- R/ Q 7-it Note6

Nominal IReo-RA1I
/R
- (128)
0.2 1.25 / 421 devices onty

-
Resistance Match
!Rwo Rw 11 0.25 1.5 % 422 devices only,
/Rw Code = FullSca!e
Wiper Resistance - 75 160 V00 = 5.5 V, lw = 2.0 mA. code = OOh
(Note 3, Note 4)
Rw
- 75 300 V00::: 2.7 V, lw = 2.0 mA. code = OOh

. 9.3. 4231

.
4231 .
,
. . 9.4.
. 9.4 , : 8- 16-.
, -
. 16-
, .
, (, , )
.
9. SPI 193

8- 16-

I


' r.----.-



D D D D D D D D D D D D
D D D D 1 9 8 D D D D 1 9 8 7 6 5 4 2 1

1

t t
2 1 2 1
=
'---....,------.---..,J 1= INCR ()
1 = DECR ()
1 1= Read Data
( )

. 9.4. 4231

,
.
, - 1. ,
.
, , -
(0-128). ,
10000, - .
. 9.4, 4 - ,
2 - (00- ), 2 -
( ,
128).
,
Arduino. , .

9.4.2.
SPI,
MCP423 l, .
(, ,
) . .
5 ,
( )- .
. 9.5.
.
, 5 100
( - 75 ) .
,
100 , (- 10 ), .
175 ,
.
,
, .
, .
194 111.

. 9.5.

. 9.6.
9. SPI 195

, , SPI.
Arduino Uno 13 - SCK, 12 - MISO, 11 -
MOSI. 1 SS , 9 -
SS . . 9.6. ,
SCK, MISO MOSI.
, ,
.

9.4.3.
, ,
SPI
.
SPI Arduino IDE,
SPI. , , - SPI
SPI
. , SS .

, :
+ SS ;
+ ;
+ - ;
+ SS .
, 9.1, :
SS, m
SPI. SPI. begin () SPI
Arduino SPI
SPI. transfer ().
SS 1 ,
- 9. settled () SS,

. loop ()
, . Arduino
.


, SPI
, http:/1 www.exploringarduino.com/
content/ch9. Wiley.

, ,
.
196 111.

// ,
//
// SPI
#iclude <SPI.h>
// SPI
//
// 11 = MOSI, 12 = MISO, 13 = CLK

const int SSl=lO; // SS 1


const int SS2=9; // SS 2
const byte REGO=BOOOOOOOO; //
// ( )
const byte REGl=BOOOlOOOO; // 1
// ( )
void setup()

// SS
pinode(SSl, OUTPUT);
pinode(SS2, OUTPUT);
// SPI
SPI.begin();

//
// Chip 1 (SS 10) -
// Chip 1 (SS 10) 1 -
// Chip 2 (SS 9) -
// Chip 2 (SS 9) 1 -

void setLed(int SS, int reg, int level)

digitalWrite(SS, LOW); // SS ()
SPI.transfer(reg); //
SPI.transfer(level); // (0-128)
digitalWrite(SS, HIGH); // SS

void loop()

for (int i=O; i<=128; i++)

setLed(SSl, REGO, i);


setLed(SSl, REGl, i);
9. SPI 197

setLed(SS2, REGO, i);


setLed(SS2, REGl, i);
delay(lO);

delay(300);
for (int i=128; i>=O; i--)

setLed(SSl, REGO, i);


setLed(SSl, REGl, i);
setLed(SS2, REGO, i);
setLed(SS2, REGl, i);
delay(lO);

delay(OO);

9.5.
SPI
-
SPI, .
,
. 5, Arduino IDE ,
Arduino
.
. ,
. SPI
.



.
,
Arduino.

9.5.1.
(. . 9.6).
, .
, ,
Arduino, .
,
, , . ,
. 9. 7.
198 1/1.

. 9.7.

,
, .

9.5.2.

(. 9.1). ,
, ,
. loop ()
, .
setLed (),
, ,
. 9.2 setReg ().
200 111.

for (int i=O; i<=128; i++)

setReg(SSl, REGO, i);


setReg(SSl, REGl, i);
setReg(SS2, REGO, i);
setReg(SS2, REGl, i);
delay(lO);

delay(OO);
for (int i=128; i>=O; i--)

setReg(SSl, REGO, i);


setReg(SSl, REGl, i);
setReg(SS2, REGO, i);
setReg(SS2, REGl, i);
delay(lO);

delay(OO);
freq = freq+lOO;
if (freq > 2000) freq = 100;

Arduino ,
, .
l 00 , 2000 .
, .
. ,
. :
+ (
,
);
+ ,
;
+ , ;
+ .


, Sl-
, http:// www.exploringarduino.com/
content/ch9. Wiley.
9. SPI 201

:
+ SPI
( )
.
+ Arduino SPI
Arduino .
+ SPI,
SS
.
+ SPI
Arduino SPI.
+ .
+ ,
Tone SPI.
9. SPI 199

// ,
//
// Arduino SPI
#include <SPI.h>
const int SPEAER=8; //
int freq = 100;
// SPI
//
// 11 = MOSI, 12 = MISO, 13 = CLK

const int SSl=lO; // SS 1


const int SS2=9; // SS 2
const byte REGO=BOOOOOOOO; //
//( )
const byte REGl=BOOOlOOOO; // 1
//( )

void setup()

// SS
pinode(SSl, OUTPUT);
pinode(SS2, OUTPUT);
// SPI
SPI.begin();

//
// Chip 1 (SS 10) -
// Chip 1 (SS 10) 1 -
// Chip 2 (SS 9) -
// Chip 2 (SS 9) 1 -

void setReg(int SS, int reg, int level)

digitalWrite(SS, LOW); // SS ()
SPI.transfer(reg); //
SPI.transfer(level); // (0-128)
digitalWrite(SS, IGH); // SS

void loop()

tone(SPEAER, freq); //

Arduino Uno;

US- ( Uno);

SI- 4231;

162- -;

2 4,7 ;

2 1 ;

1 150 ;

1 1 ;

r 74-5.0 VAT 12;

;
.


http://www.exploringarduino.com/content/chlO
, . ,
www.wiley.com/go/exploringarduino
Downloads.
10. 203


,
. ,
, , .
(LCD) Arduino,
( , ,
. .)
.
, LCD Arduino,
Arduino LiquidCrystal
. , ,
, ,
, .
- ,
,
.



http:l/www.jeremyum.com/2011/07/31/tutorial-13-for-arduino-liquid-crystal-displays
Wiley.

10.1.

, ,
. .
, 162 , 16 (
14, ) .
16- -,
32 (16 2 ).
,
, .
( . 10.1), .
, , Arduino.
-
: 4- 8-.
, ,
,
. . 1 .1.

I
: http://wiki.amperka.ru/eoypo:13--cne-lcd.
204 111.

. 10.1. -

10.1. -


1 Vss
2 Vdd +5
3 Vo ()
4 Rs ( )
5 RW /
6
7 00 ( )
8 01 1 ( )
9 02 2 ( )
10 03 3 ( )
11 04 4
12 05 5
13 06 6
14 07 7
15
16

:
+ Vo
, .
+ Rs
, , , ,
.
1Q. 205

+ RW , ,
, .
+ EN , .
+ D4-D7 , DO-D -
.
-
,
+5 , , ,
.
.
. 10.2 -
Arduino. -.

. 10.2. - Arduino
206 111.

10.2.

- Arduino
RS 02
EN 03
04 04
05 05
06 06
07 07

- Arduino , . 10.2.
- .
Arduino, .
.

10.2. LiquidCrystal
Arduino IDE LiquidCrystal,
-.
, , ,
, .
,
, .
, , Arduino:
http://arduino.cc/en/Reference/LiquidCrystal.

10.3.
,
. , ,
.
LiquidCrystal:
#include <LiquidCrystal.h>
LiquidCrystal:
LiquidCrystal lcd (2,,4,5,6,7);
Arduino,
- : RS, EN, D4, DS, D,
D7. -, setup ()
begin (), -
-:
lcd.begin (16, 2);
10. 207

print() setcursor()
. ,
, :
lcd.setCursor (0,1);
lcd.print ("Jeremy Blum");
, (0,0),
. setcursor() , -
. (0,0).
print() ,
.
!
print ()
, ,
. ,
.
,
, ,
. 10. 1
. Arduino , .
,
.

//
// :
*include <LiquidCrystal.h>
// time=O
int time = ;
// LiquidCrystal
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup()
{
// - :
lcd.begin(l, 2);
//
lcd.print("Jeremy's Display");

void loop()

//
lcd.setCursor(O,l);
208 111.

/!
lcd.print(time);
// 1
delay(lOOO);
//
time++;

.
LiquidCrystal. time
. LiquidCrystal
lcd , .
lcd.begin (16, 2) : 16 2 .
, setup()
lcd.print (). ,
, ,
(0,0). (, 1),
time .
.

10.4.

, ,
? , ,
. , LiquidCrystal
,
. ,
, .
.
.
-, , 58 .
,
.
,
-.
5 , 5 :
, . .
,
, - .
( 20% )
:
byte 20[8] = {
810000,
1 . 209

BlOOOO,
BlOOOO,
BlOOOO,
l,
BlOOOO,
l,
l,
};

2, , 20%
. setup() createChar(),
ID .
ID 7,
. 20
ID=O:
lcd.createChar (0, 20);


lcd.write ((byte) );

loop() -.
10.2.

// - -
// LiquidCrystal
#include <LiquidCrystal.h>
// LiquidCrystal
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

// -
byte 20[8] = {
BlOOOO,
BlOOOO,
BlOOOO,
BlOOOO,
BlOOOO,
BlOOOO,
l,
BlOOOO,
};
byte 40[8]
BllOOO,
BllOOO,
210 /11.

BllOOO,
BllOOO,
BllOOO,
BllOOO,
BllOOO,
BllOOO,
);
byte 60[8]
BlllOO,
BlllOO,
BlllOO,
BlllOO,
BlllOO,
BlllOO,
BlllOO,
BlllOO,
};
byte 80[8]
llllO,
BllllO,
BllllO,
BllllO,
BllllO,
BllllO,
BllllO,
BllllO,
);
byte 100[8]
Blllll,
Blllll,
811111,
811111,
Blllll,
811111,
811111,
811111,
);

void setup ()

// - :
lcd.begin(l, 2);
// -
lcd.print("Jeremy's Display");

//
lcd.createChar(O, 20);
1. 211
lcd.createChar(l, 40);
lcd.createChar(2, );
lcd.createChar(, 80);
lcd.createChar(4, plOO);

void loop()

//
lcd.setCursor(0,1);
//
// 16
lcd.print(" ");
//
for (int i = ; i<l; i++)

// (20 - plOO)
for (int j=O; j<5; j++)
{
lcd.setCursor(i, 1); //
lcd.write(j); //
delay(lOO); //

16
( ). for() 16 .
for()
-.


, - -
, http://www.exploringarduino.com/content/ch10.
Wiley.

10.5.
. I2
, 8, 5.
.
, .
, .
2.5
.
212 111.

10.5.1.

.
Arduino.
,
(. 4). , . 4.1. -
, (. . 10.2).
, -
Arduino 1 .
Arduino, -
150 . .
1 2 - , 8.
. 10.3.
, .

. 10.3. -
10. 213

10.5.2. -
-
. , .
"Current:" "Set:" ,
. ,
"0 " .
(8,0) loop (),
(8,1)
.
(15,1) , .
- ,
.10.4.

. 10.4. -

,
. ,
, 10.3.

//
byte degree[B] = {
00110,
01001,
01001,
00110,
,
,
,
,
};

// " "
byte fan_on[B] = {
00100,
810101,
01110,
Blllll,
01110,
214 111.

810101,
800100,
800000,
};

// " l"
byte fan_off[8] = {
800100,
800100,
800100,
811111,
800100,
800100,
800100,
800000,
};

- setup().
print()
write() ( 10.4).

//
lcd.createChar(O, degree);
lcd.createChar(l, fan_off);
lcd.createChar(2, fan_on);

// -
lcd.setCursor(O,O);
lcd.print("Current:");
lcd.setCursor(lO,O);
lcd.write((byte) );
lcd.setCursor(ll,O);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Set:");
lcd.setCursor(l0,1);
lcd.write((byte) );
lcd.setCursor(ll,1);
lcd.print("C");
lcd.setCursor(15,1);
lcd.write(l);

loop()
. .
10. 215

10.5.3.

2 debounce().
, .
, .
:
// ,
boolean lastDownTernpButton = LOW;
boolean currentDownTernpButton = LOW;
boolean lastUpTernpButton = LOW;
boolean currentUpTernpButton = LOW;

debounce()
. , ,
( 10.5).

//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)

delay(5);
current = digitalRead(pin);

return current;

loop() ,
,
set_ternp - ( 10.6).

//
currentDownTernpButton = debounce(lastDownTernpButton, DOWN_BUTTON);
currentUpTernpButton = debounce(lastUpTernpButton, UP_BUTTON);
// set ternp
if (lastDownTernpButton == LOW && currentDownTernpButton == HIGH)
{
set_ternp--;
216 111.

// set temp
else if (lastUpTempButton == LOW && currentUpTempButton == HIGH)
{
set_temp++;

// set temp -
lcd.setCursor(B,l);
lcd.print(set_temp);
//
lastDownTempButton = currentDownTempButton;
lastUpTempButton = currentUpTempButton;

10.6 debounce()
, set_temp
.
-.

10.5.4.

.
- ,
. ,
. tone( J
delay() notone( J. ,
tone( J ,

.
, 10.7,
, -.

// !
if (>= set_temp)

//
if ( !one_time)

tone(SPEAER, 400);
delay(SOO);
one time = true;
10. 217

//
else

noTone(SPEAER);

// -
digitalWrite(FAN, HIGH);
lcd.setCursor(l5,l);
lcd.write(2);

//
else

!/
// one time false
!/ -n
noTone(SPEAER);
one time = false;
digitalWrite(FAN, LOW);
lcd.setCursor(15,1);
lcd.write(l);

one_time ,
. 500 400 ,
true false ,
.

10.5.5. :
.
, .
10.8. Arduino
, .

//
// n 2
// Wire
#include <Wire.h>
#define ADDR 72
// LiquidCrystal:
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
218 111.

//
byte degree[8] = {
00110,
01001,
01001,
00110,
,
,
,
,
};
// " "
byte fan_on[8] = {
800100,
810101,
BOlllO,
Blllll,
01110,
810101,
800100,
,
};
// " "
byte fan_off[8] = {
00100,
BOOlOO,
BOOlOO,
Blllll,
800100,
800100,
800100,
,
};
// , ,
const int SPEAER =8;
const int DOWN_BUTTON =9;
const int UP BUTTON =10;
const int FAN =11;
//
boolean lastDowTempButton = LOW;
boolean currentDownTempButton = LOW;
boolean lastUpTempButton = LOW;
boolean currentUpTempButton = LOW;
int set temp = 23; //
boolean one time = false; //
1 . 219

void setup()
{
pinode(FAN, OUTPUT);
// Wire (I 2 - )
Wire.begin();
// ( )
lcd.begin(l, 2);
//
lcd.createChar(O, degree);
lcd.createChar(l, fan_off);
lcd.createChar(2, fan_on);
//
lcd.setCursor(0,0);
lcd.print("Current:");
lcd.setCursor(lO,O);
lcd.write((byte)0);
lcd.setCursor(ll,O);
lcd.print("C");
lcd.setCursor(O,l);
lcd.print("Set:");
lcd.setCursor(lO,l);
lcd.write((byte) );
lcd.setCursor(ll,l);
lcd.print("C");
lcd.setCursor(lS,l);
lcd.writeH);

//
boolean debounce(boolean last, int pin)

boolean current = digitalRead(pin);


if (last != current)
{
delay(S);
current = digitalRead(pin);

return current;

void loop()

//
Wire.beginTransmission(TEMP_ADDR);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(TEMP_ADDR, 1);
220 111.

//
// 1
while(Wire.availale() );
int = Wire.read();
//
//
lcd.setCursor(B,0);
lcd.print(c);
//
currentDownTempButton = debounce(lastDownTempButton, DOWN_BUTTON);
currentUpTempButton = debounce(lastUpTempButton, UP_BUTTON);
//
if (lastDownTempButton== LOW && currentDownTempButton == HIGH)
{
set_temp--;

//
else if (lastUpTempButton== LOW && currentUpTempButton HIGH)
{
set_temp++;

//
lcd.setCursor(B,1);
lcd.print(set_temp);
lastDownTempButton currentDownTempButton;
lastUpTempButton = currentUpTempButton;
// !
if ( >= set_temp)
(
//
if (! one_time)

tone(SPEAER, 400);
delay(500);
one time = true;

//
else

noTone(SPEAER);

//
digitalWrite(FAN, HIGH);
lcd.setCursor(15,1);
lcd.write(2);
10. 221
// !
else

//
// one time false
// -
noTone(SPEAER);
one time = false;
digitalWrite(FAN, LOW);
lcd.setCursor(lS,l);
lcd.write(l);

, , Arduino
.
.

, ,
http://www.exploringarduino.com/content/ch10.
Wiley.

10.6.
.
:
+ .
+ -
- .
+ .
+ .
+
, SPI 9.

:
+ - Arduino .
+ -
.
+ .
+ , , -
.


,

:
+ 2 Arduino ( Uno Leonardo);
+ US- Arduino;
+ Arduino;
+ SparkFun USB Explorer;
+ 2 Series 1;
+ 2 shield;
+ ;
+ ;
+ RG- ;
+ 1 1 ;
+ 1 ;
+ 1 150 ;
+ 3 220 ;
+ ;
+ 2 .

http://www.exploringarduino.com/content/chll
, . ,
www.wiley.com/go/exploringarduino
Downloads.


!
.
11. 223

, Arduino
, Digi.
,
, .
,
, .
Arduino
Arduino. .

http://www.
jeremyum.com/2011/02/27/arduino-tutorial-9-wireless-communication/1.
Wiley.

11.1.
.
.
,
.
, . ,
(FCC) , ,
.
2,4 , , WiFi
. ISM ( ,
),
. IEEE 802.15.4,

(PAN).
, , AN "-"
"-" (. 11.1). "-" ,

. "-"
.

- -
. 11.1. N-

I
: htt://wiki.mrk.ru/:9--.
224 111.

11.1.1.

API.
.
. ,
, , .
Arduino (
Arduino) .
20 .
1, 802.15.4.
N- "-" "-",
Zigee. ,
S1 (. 11.2).

. 11.2. Series 1


, 1 2 .
1, . . .

.
Pro non-Pro, , , ,
( 1 Pro
300 non-Pro 1 ).
Pro, .
, 2,4 900 .
900 ,
, . ,
2,4 900 , .

I
l ()"' 1,6 ; l "' 30 . - .
11. 225

, -
: , ,
. ,
, .
1, non-Pro,
2,4 ,
.
. 11.3.

11;=-.
I-R RF Module Pin
Numbers
(tt)p sides shown shields on ottom} Pi-o 1- hn 20
:
Pin 1 - -' Pin 20
:
: : /''!'
:
: :
:
:

P.i.n 10-
i
- Pin 11
Pi.n 10 - - Pin 11

Pin Assignments for the and XBee-PRO Modules


(Low-iserted signals . distinguished wilh horizontal line v signal name.)

-
--------1----- Output _____J _______ -------------- UAR Data Out________---------------
1 VCC 1 , Power supply

___ 2 -- ! _ -- -------D
--- t------- -- --- ------ -------------------- ----------------- --------------------------
3 DIN I CONFIG ! lnpu i t UART Data ln
- -- 4-- - ------------
-- Ri
008* -. - ! u tput I
---- --1 - --. -i;;put ----1--o<1u1R
O Digital Output 8

-=-
. "5 eset (reset pu1se must.ai1eis12oons --
; =: = = 1=-= ==f-=-oy==-1-
PW l
=

. -- -- r -------- -------------- _ __. . ______.___ ------ --- - -------------------------------------------------------


-------- --...--..--. ,---.-- ----
9
10 1
'. -- --- ----------
DTR I SLEEP_RQ 1 018

--GND
----- . -- -- ----+-----------------
------------ t
:

----
,
- -----
lnput

----- i-----------------------------------------
--+----------
-
Pin Sleep Control Line or Digital lnput 8
Ground
-. -------- --------------------------------
11
- -- ---- -- ------
12 ,
AD4 / DI04
------------t------------- ---------------------"'------------
--------- --- -------!----
S / DI07 1
Either
Eilher
, Analog lnput 4 or Digital 110 4
Clear-tend Flow Controlor Digital IIO 7
13 !
----- - ____,__ ... ------- --- --------------1-----------------+------------- --------- --------------------------
ON / SLEEP
- - ----1------ -- --------------..---...j' ----............ Output... -----------
I odule Status lndicator
14 , VREF i lnput
............./ .......... --- "'' - -- - ... t--- ---"' 1-- ______ ,,_______ ! -------- -------------- -------------------------
Voltage Reference for AJD-lnputs
------ - -- "'--- ..
15
.
.... .......
16
'
- Associate / AD5 / DI05
j - ..... _____
........ _,,
RTS / AD6 / DIO
.
i .
Either
-- ---- -
, ,_, ............ .. --- .....
I Either
,
---.....\
Associated !ndicator, Analog lnput 5 or Digilal IIO 5
_,,_ -
.. ---- -- ___ .. ________ - ...... ..
I Request-to..Send Flow Control. Analog lnput 6 or DigitaJ 1/0 6

-- "
18
! '" . , ---- -- ----- D
. - -- --17- --- j- ---------
AD /DI
I DIO -+----_,,_____________
-------. "' .... I
-- 2 02----- 1-- ith ---------
E
ERher
er
J________ -- -- --
\
------
Anatog lnpul 3 or Digital
--- ------ -- ----
i
Anatoglnput2orDig tall/02
IIO 3__,,_____ -- --. --
...... ----"--
....... "' ... - - - - . .. ........ ................... - - ...... "'. - ---- -1- . ---- -. ----- - --- - -- -- ---- -- - .. _,,__ , .
.... ..
2
19 !
0
!" --- - AD1 / DI01
ADO / 01 0 0
t-
-- ---
1 --Either----- I-- -----
il
E erh 1
Analog lnput 1 or DigitalllO 1
Analoglnput orDigitall/0 0
---------------

. 11.3. Series 1.

!
3,3 , 5
.
226 111.

11.1.2.
- (. 11.4),
Arduino.
-,
.
.

Arduino Wireless Shield Sparkfun Shield Cooking Hacks Shield


. 11.4.

3,3
Arduino 5 ,
( ) 5 ( ).
3,3 , .
Arduino 3,3 ,
-. -
.


UART Rx Arduino
,
Arduino . (
).
.


:
+ Associate -,
;
+ RSSI-aropaec .
11. 227

1 UART
Arduino
(UART) Rx .
Arduino ( Mega Due) UART,
US- .
Leonardo UART ( Rx ), ,
. . USB .
Arduino Uno :
UART. Rx (
) . 11.5.


RX

RX

Arduino
RX


. 11.5. UART

"" . 11.5. ,
,
Arduino. Arduino , ?
, ,
. , Arduino
.
:
+ Arduino;
+ -
Arduino.
Arduino
,
().

UART
Arduino UR
( 1 Arduino).
228 111.

USB.
Arduino
.
Arduino, SoftwareSerial.
Arduino
Rx -.
Arduino
Rx . Sparkfun ,
1 2 3 Arduino Rx .
,
SoftwareSerial.

11.2.
,
. -
.
.
,
.

11.2.1. US-
, Arduino,
USB. : Arduino
USB (. 6) USB.
USB,
, SparkFun USB Explorer (. 11.6).

. 11.6. SparkFun USB Explorer


11. 229

( )
Arduino Uno,
. . .
Arduino,
, .
, Tmega,
Arduino US
. .

, .
Uno SMD ATmega .

()
SparkFun USB Explorer : -
, SparkFun USB Explorer
US-, . m SparkFun USB
Explorer US- FTDI,
Arduino. m
Arduino .

11.2.2.


. (. 11. 7):
+ ID ( N-)- ,
, .
+ ( )-
.
+ DL ( )- ,
.

)
'IJ
''
- -
D
I =l 234

D=(9600) ,
''
= 1000 = 1001
DL = 1001 DL = 1000
. 11.7. "-"
230 111.

+ BD ( )- .
(9600 ).
, DL
, . .
, . PAN
1234, .
BD 3.
BD :
+ 0-1200 ;
+ 1-2400 ;
+ 2-4800 ;
+ 3-9600 ( );
+ 4-19 200 ;
+ 5-38 400 ;
+ 6-57 600 ;
+ 7-115 200 .
,
. ,
. m 1. ,
.

11.2.3.
Windws- X-CTU
,
. 11.7. Windows,
X-CTU,
. Windows,
,
Linux OS .
X-CTU Digi
Google. X-CTU
http://www.exploringarduino.com/content/chll.
:
1. , X-CTU .
, . 11.8.
-.
2. -, Explorer
Test/Query (. . 11.8).
, 9600 ,
,
(. 11.9).
11. 231

Parj1y jNONE i}
Stop 8its J1 .
T8$t/0Ueo/_l

..-Moqern Flast, Upde!e---- ----1


j /,lo t>aud che,nge
L-------""--_J

. 11.8. X-CTU

test / Query 'odem


Communi-on with moclem"O,
Modem \JIPe 2
[\!Qdem /itrowore yersiQn 10ED

. 11.9. X-CTU -
232 111.

3. Read,
-.
, . 11.1.

11 (\
Cil ()2) ID PAN
11 ( QH-[1eatmati,:.1nddre;;s Higl1
1; { DL 0r:."t$tinatri Addr1Nti L"\
11 (,, \' 16 1::t Source Ad(!,s
1 (1 200) SH - Sene! Number High
f,J (40689198) SL-Sene! Numberlow
f,J (O)MM-.t.CMode
11 () R,1-,, Re11ie
11 (): RN - Rar1dom Oeia\, S!ots:
li ( 19) NT Notie Cl1$GOver , i,,
11 {} NO - Node Oiico1 rr OpHts
1 (n) - Coo1din6to1 ,
lil (1 f"FE) SC Sc,,,, :::l1a1.n<1l1,
lil (4) SD" Sc"'r1 Ouro.tior
1 /J,1-Et1dDeviceAttooat!cm
11 () .2 - Coordir1e,1or Asociatn
11 () 1 -Associe.tion lndice.tion
11 (\ AES E11crypN"1
II AES Enc:iyplion

. 11.10. X-CTU-

4. PAN ID, ,
. ,
.
, .
: ID-1234; DL- 1001; - 1000.
5. Write ,
-.
(. 11.11).
!
Explorer .
, DL ,
. . 11.12
-.
11. 233

;;;.,,klng & Securlly


;, IJ tC} Ctlr,r1EI
j- 111 (1234JID-PANID
!".""" r/il tO) DH - Oet.tia.11tm Audre }::. r-!19!1
l--1:iJ (1001) Dl-OestJna!ionddress Low
[,.. 111 (1000) -16-il Source Add1ess
1' l:iJ (1 200) SH - Seriet Number High
; lil (4068919B)SL-Serie1Numberlow
i
k.,, 11 lt) fl tM - tv!JC Mode
f."'-- 1 () ;:.,1Ft <B1-..'t Re1rie,;
> lil ((1) RN Rodom Del Slot,
),-, 11 (i :1) N -Norte 0 1 s-co.,,er Ti1r:

- - lil (!)} NO, t,Jr.ie { 1:...-r Optiont


t""- 11 (G} Caord\11atoi En:!I\
}--- 11 \1FFE')SC-Br,-.11i'..:t1r'l::ni:\!
i- lil 14) :::D Scan Durabn
f..., lil (0)1 -Et1r! Dvir ",1soc3ti1Jr
; ,. li () .2 - Ci;'1or.liJ.8tat A,ociaUor1
! .. 11J ()!: A;'iolion lndicao
,-,..,, Ci (0) t:t. - , ':., 11cn/l')Ji01, Eriftt)le
[,. 11J -AES Encrypbon
,, h - .. , ,,, ' -

. 11.11.

. Networking & Security


i'- IJ {) ' (:hf.ml?I
\- lil (1234) 10-PAN 10
\. IIJ () -,., ;9h
[ ... l:iJ (1 ) DL-Oesbnation ddress LO\
11 (1001)Y-16i1Sourceddress
t,-11 (1 200) SH-Senat Numer High
-11 (4064E31D)SL-SerilOINumberlow
--- f(I) t"iAC MorJe
() RR :.,-: R!jlC'3
(f$) FtN R!:':fridom tietay Slo;
(19't NT - Nod-e Gicover Tire
?.,, () NO - Nt1dP Di1::..:vsr t'lptit1::
r,-. ([,; -Cou,dma>or Enahlc
,-.- (H'FE) SC !::ren Channels
}-, i 4) Sf.) - r;i1J1 r.1urt1.tion
f'"'
() 1 . j 01-;i1,..-e ;. :'UL1,"!;.tiQ!'
{)('' (:(101.ditHttOf Aa:socii,tinr'i
1 (U)AlAssociationlndon
(0) -.AJ:S Ei:,yptic: En.,le
KY-AESEncrypl!on

. 11.12.
234 111.

.
AN , ,
. 11.3.

11.2.4.

Windows,
.
Linux . screen. 1,
IDE Arduino Explorer.
-> .
:
1. ,
screen /dev/ttyUSB 9600
(/dev/ttyus ).
<Enter> .
.
, .
,
:
;
PAN ();
();
(ATDL);
(TWR).
( )
-, . ,
.
2. +++ , <Enter>,
, , .
3. ATID1234 <Enter>,
1234.
4. l <Enter>,
1000.
5. ATDLlOOl <Enter>,
1001.
6. ATWR <Enter>,
,
.
11. 235

7. , , ATID,
ATDL <Enter>,
.

-,
+++ , .
,
. 2-7, ADL ,
.
!
, ,
, .

11.3.

, . -
Arduino.
Arduino ,
US-.
Arduino US- Arduino
.

11.3.1. Arduino
Arduino USB,
.
.

USB
Arduino US- ,
. USB-nopy
, USB Explorer,
USB-nopy .
, .
,
USB Explorer
Processing.
5- US-.
.
iPhone, Android-ycpoc, .
. 11.13 US- .
236 111.

. 11.13. 5- US-


Arduino ,
V;0 ,
5 .
. 11.14 9-
.
9-
1,5 . ,
6 . Arduino
l . 5,5

. 11.14. 9
11. 237

4,5 . , 4,5 ,
ATMega,
oUSB.


Arduino -
.
Arduino.
:
( 2,1 (. 11.15));
( 7-12 );
( ,
Arduino). 1
Arduino
.

. 11.15.

11.3.2. 1:

, ,
.
, 6.
:
1. ,
, Arduino.
Arduino, UART,
.
/ UART,
Arduino .
. ,
,
11.1.

//
const int =; //
int val; //
238 111.

void setup()

Serial.begin(9600); //

void loop()

val = map(analogRead(POT), , 1023, , 255); //


//
Serial.println(val); //
delay(50); //

2. i Arduino
. ,
, . 11.16.
3 . . IUia Arduino ,
. US- .
4. USB Explorer
USB. ,
Rx USB Explorer
.
5. rssing-
Arduino IDE.
, USB Explorer, ,
(. 11.17).
6. , ,
Processing
. , .
Processing 11.2.

r 11.2. r Processlng n
- pot_to_processing/processlng_d,splay_color

// Processing
// serial
import processing.serial.*;
Serial port;
float brightness = ; //

void setup()
{
size(500,500); //
port = new Serial(this, "", 9600); //
//
11. 239

port.bufferUntil('\n'); //

void draw()
{
background(O,O,brightness); //

void serialEvent (Serial port)

brightness = float(port.readStringUntil('\n')); //

. 11.16. Arduino
240 111.

l !_=_J.: .. i

13
::: : ::: :: ]! Sen 1

75
76
76
11
77
77
77
77
76
76
16

Autoscroll

. 11.17. ,

,
Arduino .
( Arduino )
.

11.3.3. 2: RG-
,
Arduino . 6
RG-, ,
Arduino.
Arduino ,
( -
).
( 11.3) Arduino.
6. RGB
RG-.

//
// RG-
const int RED =11;
const int GREEN =10;
const int BLUE =9;

// RGB
int rval ;
int gval ;
int bval ;
11. 241

void setup()
{
Serial.begin(9600); //
// 9600
// OUT
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);

void loop()

//
while (Serial.availale() > )
{
rval Serial.parselnt(); //
gval Serial.parselnt(); //
bval Serial.parselnt(); //
if (Serial.read() -- '\n') //

// R,G,B
analogWrite(RED, rval);
analogWrite(GREEN, gval);
analogWrite(BLUE, bval);

, 6 (. 11.18). Arduino
.
, USB Explorer
Processing ( 11.4). , hsv.jpg
data .
.

<s;rt 11.4. r Prcessing " d&J,t 'J'f G- -


proce$sing..J.ol1tro1_r9bl p.roces,ing,,..contl_GB

import processing.serial.*; // serial


Pimage img;
Serial port;

void setup()
{
size(640,256);
img = loadlmage("hsv.jpg"); //
port = new Serial(this, "9", 9600); //
242 111.

void draw()

background(O); //
image(irng,0,0); //

void rnousePressed()

color = get(rnouseX, rnouseY); // RG- I


String colors = int(red(c))+","+int(green(c))+","+int(ue(c))+"\n";
//
print(colors); //
port.write(colors); // Arduino

. 11.18. Arduino RG-


11. 243

6. .
Arduino,
.
.
,
.
Arduino .

11.4.
Arduino
. Arduino ,

. Arduino,
, , .
Arduino, ,
. - , Arduino
, , .


, , ,
,
http://www.exploringarduino.com/content/ch11.

11.4.1.
Arduino.
. Arduino
, .
, , - .
-,
.
- , Arduino
, .
.
, ,
, ,
.
. 11.19. ,
.
244 111.

>''-IIIII

IJ
ID=1 234
- ((
BD=3(9600)

>))

=1000

DL=1001
=1001
DL=1000
. 11.19.

11.4.2.
.
Arduino
(. 11.20).
Arduino , ,
Leonardo -,
Uno. Uno Micro
, Leonardo Mega

. 11.20.
11. 245

. ,
Leonardo. .
.
,
.
Arduino 9- . ,
.

MRi=l#M
, ,
Arduino.

11.4.3.
,
. Arduino ,
RG-, .
. 11.21. ,
, () RG
.
.

. 11.21.
246 111.

Arduino .
Uno, US-.
US-, .
, rssing
.

11.4.4.
,
. ,
.
50 . ,
, 1, . .
, .
, Arduino .
, Arduino Uno Rx/Tx (0/1) UART,
USB. Uno Mega
().
Leonardo ( US
) .
11.5 Arduino Leonardo, Uno,
Seriall Serial.

// Arduino n
const int BUTTON =12; // 12

void setup()
{
// Leonardo Rx/Tx
// USB r
// n Leonardo (Seriall = RX/TX)
!/ UNO Seriall Serial
Seriall.begin(9600);

void loop()

Seriall.println(digitalRead(BUTTON)); //
delay(50); //

setup()
9600 . 50
11. 247

. digitalRead
println (),
.

11.4.5.
, .
, 11.6, Arduino Uno U.
Arduino Leonardo serial Seriall.

, ,
, ,
, . , . .
delay () . delay ()
, ,
:
, . . ,
.
RG
.
delay () , .
delay () millis (),
.
l 00 .
millis (), 100 .
, . , loop ()

.
setup () .
,
, , millis () .
11.6.
Arduino,
( ).

//
const int RED =11; // 11 - RG-
const int GREEN =10; // 10 - RG-
const int SPEAER =8; // 8
char data;
int onLED = GREEN;
248 111.

int offLED = RED;


int freq = 131;
unsigned long prev_time ; //
//
void setup()
{
Serial.begin(9600);

void loop()

//
// 100 ?
if (millis() >= prev_time + 100)

!/
if (onLED == GREEN)

onLED = RED;
offLED = GREEN;

else

onLED = GREEN;
offLED = RED;

//
if (freq == 261)
{
freq 131;

else

freq 261;

//
//
prev_time = millis();

//
if (Serial.availae() > )

//
data = Serial.read();
11. 249

/! -
if (data == '1')

digitalWrite(onLED, HIGH);
digitalWrite(offLED, LOW);
tone(SPEAER, freq);

// -
else if (data == '')

digitalWrite(onLED, LOW);
digitalWrite(offLED, LOW);
noTone(SPEAER);

if () loop() ,
prev_time.
100 ,
, .
if () loop()
. , , 1 -
onLed,
offLed, freq.


, ,
http://www.exploringarduino.com/content/ch11.
Wiley.

:
.
Arduino
5 3,3 .
X-CTU ( Windows)
( Linux ).
Arduino.
Arduino
.

Arduino.
millis().

jn1


12.
13. SD
14. Arduino

1,

,.,,


:
+ Arduino ( Uno);
+ US- Arduino;
+ ;
+ ;
+ RG- ;
+ 1 1 ;
+ 1 100 ;
+ 1 150 ;
+ 3 220 ;
+ 1 ;
+ 7414 ( );
+ ;
+ 2 .

http://www.exploringarduino.com/content/chl2
, . ,
www.wiley.com/go/exploringarduino
Downloads.


.
, , delay ()
Arduino .
1 , millis (),
254 IV.

Arduino delay ( J.
, .
,
( , . .).
, ,
Arduino, ,
. ,
.
, .


http://www.jeremyum.com/2011103/07/arduino-tutorial-10-interrupts-and
1
hardware-debouncing .
Wiley.

12.1.
( )
-. , ,
, .
.
, .
, ,
. ,

:{

!
1


2
1

+
3

!
4

!
5

. 12.1.

I
: htt://wiki.mrk.ru/:10----.
12. 255

for ()
delay () . ,
.
. Arduino
. ,

(. 12.1), .

12.2. :
?

loop () . , .
,
.
, ,
.

12.2.1.
Arduino
.
, , - digitalRead ().
, ,
. . .

12.2.2.

, . . .
, (. 2) :
. ,

, ctelay (). ,
,
.

12.2.3.
-
. Arduino
, . . ,
. ,
, ,
. , -
256 IV.

,
.
dig italRead ()
loop () ""
.

12.2.4.
, ,
. - ,
,
.
.
.
, Arduino
. (
), loop () .
, -
.
.

12.2.5. Arduino
Arduino
. ,
(. 12.1).
Due, ,
.

12.1. Arduino

INTO INT1 INT2 INT INT4 INTS


UNO, Pin2 i - - - -
Ethernet
Mega2560 Pin2 i Pin21 Pin20 Pin19 Pin18
Leonardo i Pin2 PinO Pin1 - -

attachinterrupt {).
- ( . 12.1)
Arduino ( Due). Arduino Uno
2,
attachinterrupt {) . Arduino Uno ( ATmega328)
, Mega Leonardo
(. . 12.1).
12. 257


. attach_interrupt () -
.
, :
void toggleLed ()
{
var = !var;

var ,
, .
attachinterrupt () - .
Low, CANGE, RISING FALLING ( Due IG).
CANGE, RISING FALLING ,
. IGH LOW
,
, .

12.3.

,
RG- .
RG-
. ,
delay ().

12.3.1.

2,
.
,
. ,
, .

. (pull-up) :
, Arduino
, .
. 12.2 .
, ,
.
.
, R-.
258 IV.

, (. 12.3).
, Rl R2.

. , ""
,
.

, .

Pos: o.ooos RtGGER

.. li
1

sowce

..
....
*


" , , ' , , , ,


. 12.2.

vcc

51
,
R2

100
2 10uF
Pin 2 (lnt )
+

GND
. 12.3. R-
12. 259

R2, ,
. .
100
. ,
. 12.4.

R-
. 12.4. R-,

R- , Arduino
.

. - , ,
.
.
,
.
Arduino.
7414.
, .
. 12.5.
R- ,
Arduino (.-12.6).
, .
Arduino .
.
. 12.7, , , .
.
260 IV.

1V

2 V

2V 5

sv

1..

GNO 7 4V

. 12.5. 7414

vcc

-"

S1
1
R2

100

2 2 10uF
Pin 2 (lnt )

GND
. 12.6.

12.3.2.
, .
RG- .
, . 12.8.
12. 261

Tek il Reidy Pof: 0,000$


---Wl'W+..,.-'f"T,r"'v-,rt
TRIOOER

f
i .;
-
S

f
1\
......._........_..._.................... Sfope

Mode
n9
eou.;
i
lSOms...... """ctfi7' 2JJov
8-Apf-1310: <10z
R-
. 12. 7.

. 12.8.
262 IV.

12.3.3.

Arduino.
-
, delay() .
, ,
, III- analogWrite().
RG- ,
255 . .
, . .
.
, volatile.
, volatile (
). .
volatile:
volatile int selectedLED = 9;
Arduino attachinterrupt(),
setup(). : (
Due),
(Low, CANGE, RISING FALLING).
( 2 Uno), RISING ( )
swap()
attach!nterrupt(O, swap, RISING);
swap()
.
.
,
,
, m .
,
delay().
RG- .
12.1.

// ,
//
//
const int BUTTON_INT =0; // ( 2 Uno)
const int RED=ll; // RG- 11
const int GREEN=lO; // RG- 10
const int BLUE=9; // RG- 9
12. 263

// volatile
volatile int selectedLED = RED;

void setup()
{
pinode (RED, OUTPUT);
pinode (GREEN, OUTPUT);
pinode (BLUE, OUTPUT);
// RISING ( LOW HIGH)
attach!nterrupt(BUTTON_INT, swap, RISING);

void swap()
{
//
analogWrite(selectedLED, );
// selectedLED
if (selectedLED == GREEN)
selectedLED = RED;
else if (selectedLED RED)
selectedLED = BLUE;
else if (selectedLED == BLUE)
selectedLED = GREEN;

void loop()

for (int i = ; i<256; i++)


{
analogWrite(selectedLED, i);
delay(lO);

for (int i = 255; i>= ; i--)

analogWrite(selectedLED, i);
delay(lO);

Arduino,
(R, G ) RG- .
,
.


, Arduino
, http://www.exploringarduino.com/
content/ch12. Wiley.
264 IV.

12.4.
- ,
Arduino. .
ATmega328 ( Arduino Uno) .
Arduino millis (},
delay () analogWrite ().
Arduino
, ,
- . ,
( imerOne) 16-
Timerl ATmega328.
Leonardo, Arduino Uno.

Timer1 - 9 10,
TimerOne analogWrite ()
.

12.4.1.
, , Arduino ,
. imer 1 -
16- , , i 6 - 1 (
65 535). ,
. ,
, . 16 ,
Timer 1
. TimerOne

.

12.4.2.
TimerOne Wiley
, https://code.google.com/p/arduino
timerone/downloads. imerOne
Arduino.
:
+ Windows - Documents/Arduino/libraries;
+ - Documents/Arduino/libraries;
+ Linux - /homeNOUR USER NAE/sketchbook/libraries.
TimerOne Arduino
IDE , , .
Timerl Arduino.
12. 265

12.4.3.
, Arduino ""
.
,
. TimerOne
, loop() .
, loop()
delay(),
. ,
, , 12.2,
Arduino Uno. , 13 Arduino,
. -
loop(), .

//
#include <TirnerOne.h>
const int LED=l;

void setup()
{
pinode(LED, OUTPUT);
Tirnerl.initialize(lOOOOOO); // I 1000000
// (1 )
Tirnerl.attachinterrupt(inky); // rn ink()

void loop()

//

//
void inky()
{
digitalWrite(LED, !digitalRead(LED)); //

Tirnerl.initialize()
. 1 (1000000 ).
Tirnerl.attachinterrupt () - ,
. ,
, .
266 IV.

12.5.
,
,
.
.
2, 3 6,
. loop ()

.
,
. , (). (2)
65 . (130 )
2 2. 4 (260 ),
2. , ,
2. ,
.
,
, - .
.

12.5.1.
. RG
, 12 Arduino
150 . , .
. 12.9.

12.5.2.

, tone ()
.
12.3 Arduino .
, ,
.

//
// TimerOne
#include <TimerOne.h>
//
const int BUTTON INT =; // ( 2 Uno)
const int SPEAER=l2; // 12
12. 267

. 12.9.

//
#define NOTE 65
#define NOTE D 73
#define NOTE 82
#define NOTE F 87
#define NOTE G 98
#define NOTE 110
#define NOTE 123

// volatile
volatile int key = NOTE_C;
volatile int octave_multiplier = 1;

void setup()

//
Serial.begin(9600);
pinode (SPEAER, OUTPUT);
// RISING
attachinterrupt(BUTTON_INT, changeKey, RISING);
//Set up timer interrupt
Timerl.initialize(500000); // 0,5
268 IV.

Timerl.attachinterrupt(changePitch); // m changePitch()
//

void changeKey()

octave_multiplier 1;
if (key == NOTE_C)
key = NOTE_D;
else if (key == NOTE_D)
key = NOTE_E;
else if (key == NOTE_E)
key = NOTE_F;
else if (key == NOE_F)
key = NOTE G;
else if (key == NOE_G)
key = NOTE_A;
else if (key == N_)
key = NOTE_B;
else if (key == N_)
key = NOTE_C;

//
void changePitch()
{
octave_multiplier = octave_multiplier * 2;
if (octave_multiplier > 16) octave_multiplier 1;
tone(SPEAER,key*octave_multiplier);

void loop()

Serial.print(": ");
Serial.print(key);
Serial.print(" Multiplier: ");
Serial.print(octave_multiplier);
Serial.print(" Frequency: ");
Serial.println(key*octave_multiplier);
delay(lOO);

.
. , key octave_
multiplier volatile,
. changeKey()
-
12. 269

key. changePitch () tone ()


. .
,
16- . .
loop () , l
key, octave_multiplier .

, ,
http:/lwww.exploringarduino.com/content/ch12.
Wiley.

:
+ : F
.
+ Arduino .
Due ,
.
+
R- .
+
Arduino.
+ imerOne
.
+ ,
, .

,.

1
" SDJ


:
+ Arduino ( Uno);
+ US- Arduino;
+ Arduino ( );
+ ;
+ ;
+ SD card shield;
+ SD;
+ ;
+ ;
+ .

http://www.exploringarduino.com/content/chl3
, . ,
www.wiley.com/go/exploringarduino
Downloads.


Arduino
, ,
. . ,
, Arduino
(
).

, SD-. , Arduino SD-.
13. SD 271

,
SD-.
. ,
.


http://www.jeremyum.com/2011/04/05/tutorial-11-for-arduino-sd-cards-and
datalogging/ 1 .


GS-
http://www.jeremyum.com/2012/07/16/tutorial-15-for-arduino
gps-tracking/. Wiley.

13.1.
, , ,
, , .
- .
SD-
Arduino. :
+ , -
;
+ GS- ;
+ ;
+ .

,
.

13.1.1.
SV-
SD- SV-.
, ,
. SV-
:
Date,Time,Valuel,Value2
2013-05-15,12:,125,255
2013-05-15,12:,100,200
2013-05-15,13:,110,215

I
: htt://wiki.mrk.ru/:11-sd----.
272 IV.

, .
,
. , , ,
. Excel
, , . 13.1.
13.1. SV- /

Date Time Value1 Value2


2013-05-15 12:00 125 255
2013-05-15 12:30 100 200
2013-05-15 13:00 110 215

SV- ,
print () println () .
Arduino CSV-,
.

13.1.2. SD-
Arduino, SD
. SD- SD-, .
SD- microSD. microSD-ap
,
SD-.
( ).
SD-
Arduino. m - ,
F16 FAT32. 2
F16, - FAT32.
microSD-apy, F16.
,
, ,
Arduino. ,
Arduino.
SD- Windows :
1. SD- . Computer ( )
(. 13.1).
2. SD- (
) Format (. 13.2).
(. 13.3).
3. (FAT 2 , FAT32
),
13. SD 273

II Dl!<ktop
1- Oownl$
f;.-. 01,0,pbot
'6 Googl Drivo
it1Rt.(;fPI.:t<:-t<S

-::,_ libtll'ril!S
; \ Document$
fi} Dt
\, Gc:iog;t.t Dtf'llc
J, Mu,i<
\-Pidurti.
IJ Vidtcs

'4Hcmogroup

.. 81el<Up0ri-,e(X:)

N<twork
;J.11 PHOENJX

. 13.1. SD- Computer

( LOG, ). . 13.3
2 .
4. Start, .
:
1. Finder, Disk Utility.
2. SDcard Erase.
MS-DOS (FAT) .
3. Erase. F16,
( FAT32).
Linux SD- .
Linux :
1. , , .
2. df,
. , . 13.4.
SD-.
/ctev /rmnckOpl, .
274 /V.

,).?' .u Oriv, (:)

Ntt1-.,I;
/IPotNIX

. 13.2. SD-

. 13.3.

13. SD 275

. 13.4.

3. SD-,
umount. SD- (. 13.5).

. 13.5. SD- Linux

4. SD- mkdosfs. ,
(
sudo). -F, FAT.
16 2, FAT\6 FAT32. -
276 IV.

, /dev/mmckOpl,
sudo mkdosfs -F 16 /dev/mmckOpl (. 13.6).
SD- !
SD- SD card shield.

. 13.6. SD- Linux

13.2. Arduino SD-


SD-, , 11,
3,3 . SD-
,
SD-. , SD- SPI,
9. Arduino IDE SD,

SD-.

13.2.1. SD-
() SD-
Arduino. , ,
.
SD-:
+ Arduino SPI, 6 ICSP
Arduino (11, 12 13 Uno 50, 51 52
g);
13. SD 277

+ (CS), (53
Mega, 1 Arduino);
+ 3,3 SD- .
SD-:
+ Cooking Hacks Micro SD shield (http://www.exploringarduino.com/parts/
cooking-hacks-SD-shield) (. 13. 7)
. ,
(8-13 Uno), 6-
ICSP Arduino. 8-13 CS
1 . ICSP CS
Arduino. , 1
Arduino . SD- 2 .

. 13. 7. Cooking Hacks Micro SD shield

+ Official Arduino Wireless SD shield (http://www.exploringarduino.com/parts/


arduino-wireless-shield) (. 13.8)- ""
Arduino SD-.
SD- ,
11.
SD- (CS) 4 Arduino.
1 , , 4
CS.
+ Official Arduino Ethernet SD shield (http://www.exploringarduino.com/parts/
arduino-ethernet-shield) (. 13.9) Arduino
. SD-,
, .
(Ethernet SD-) SI--
278 IV.

. 13.8. Arduino Wireless SD shield

. 13.9. Arduino Ethernet SD shield

; CS Ethemet 1 Arduino,
CS SD- - 4.
+ Official Arduino Wi-Fi SD shield (http://www.exploringarduino.com/parts/
arduino-wifi-shield) (. 13.10) ,
Wi-Fi. SD-, Ethemet SD shield, ,
. Ethemet SD shield, Wi-Fi- CS -
13. SD 279

1 , SD- - 4. ,
;
CS ( ).
+ Adafruit data logging shield (http://www.exploringarduino.com/parts/ adafruit
data-logging-shield) (. 13. l l) ,

. 13.10. Arduino Wi-Fi SD shield

. 13.11. Adafruit data logging shield


280 IV.

,
(RTC) SD-. CS SD-
(53 Mega, 10-
Arduino), 12 .
SparkFun MicroSD shield (http://www.exploringarduino.com/
parts/spark-fun-microSD-shield) (. 13.12) SD-.
,
. CS SD- 8,
SD .

. 13.12. SparkFun MicroSD shield

13.2.2. Sl- SD-


, Arduino SD-
SI-: MOSI, MISO, SCLK ( ) CS (
).
SD. , SI-
Arduino, CS
. SD
CS , CS .
Uno 10, Mega 53.
Arduino Uno CS, .

13.2.3. SD-
SD SD-.
. -
13. SD 281

log.csv, .
, F16
"8.3", . . ,
- .
, SD Arduino
SD-. Cooking Hacks Micro SD shield ,
. 13.13 ( 8-13 Arduino
).

. 13.13. Cooking Hacks Micro SD shield


SD. , SD-
( 13 .1 ):

.r 13.1. SD"
if (!SD.begin(CS_pin))
{
Serial.println("Card Failure");
return;

Serial.println("Card Ready");
282 IV.

,
so.begin(CS_pin), .

,
.
. ,
"hello" , , 13.2.

File dataFile = SD.open("log.csv", FILE_WRITE);


if (dataFile)
{
dataFile.println("hello");
dataFile.close(); // ,
//

else

Serial.println("Couldn't open log file");

( ,
) log.csv. / ,
dataFile true, .
.
dataFile. println() ;
, dataFile. print().

dataFile.close().
, SD- log.csv
5 -
( 13.3). CSV (
millis()) .
, ,
, .

r 13.3. SD-- write_to_sd.ino


// SD-
#include <SD.h>
//
// MOSI = pin 11
// MISO = pin 12
// SCLK = pin 13
13. SD 283

// CS
const int CS_PIN = 10;
// SD-
const int POW PIN =8;

void setup()
{
Serial.begin(9600);
Serial.println("Initializing Card");
// CS
pinode(CS_PIN, OUTPUT);
// 8, HIGH
pinode(POW_PIN, OUTPUT);
digitalWrite(POW_PIN, HIGH);
if (!SD.begin(CS_PIN))
{
Serial.println("Card Failure");
return;

Serial.println("Card Ready");

void loop()

long timeStamp = millis();


String dataString = "Hello There!";
//
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.print(timeStamp);
dataFile.print(",");
dataFile.println(dataString);
dataFile.close(); // ,
// !

//
Serial.print(timeStamp);
Serial.print(",");
Serial.println(dataString);

else

Serial.println("Couldn't open log file");

delay(5000);
284 IV.

,
, (Cooking Hacks Micro SD shield):
CS ;
(10), setup() pinode(lO, OUTPUT),
SD ;
8, w_PIN
setup()
IG;
loop( J
,
. long, millis()
, 16 .
, .
.
,
. 13.14.

9
5030 Hello There!
Inic1al1zinq Card
Caro Ready
10049 Hello There!
499,Hello here! 15067 Hello Therel
5520,Hello There! 20085 Hello There!
10545, Hello !here!
15563,liello There!
25104 Hello There!
20582, Hello here ! 30123 Hello Therel
25601, liello There ! 35141 Hello There!
30619,!!ello There!
40160 Hello There!
45178 Hello Therel
50197 Hello There!
55218 Hello Therel
60239 Hello Therel
65258 Hello Therel
70277 Hello Therel
75295 Hello Therel
80313 Hello There!
. 13.15.


. 13.14.

,
, SD- .
SD-
(. 13.15). ,
13. SD 285

13.2.4. SD-
SD-.
, .
, .
SD-
speed.txt. .
. 13 .16 , , 1 ( 1 ).
SD-
, Arduino. -

,r.( fl\lOfdf'S
III De,ttop @,OGCSV 1 ) .....:.r(,) 1,''\ f\.t,.:_1,:., ff t;!!'! : ,
J11 Downlood, ,..:,,,...i.1,ot 4t01, rX1'r,i. asi
,, Dropt>o,
ii!, G0<>9itO<iv
Rece.nt .PJace-:.

,.: Libro,in
: Oocmt.1its
.4'.\i..
J Gott O,Ne
J! Mu;i<
]Pictu,e,
II v,...,

;4Hom09roup

<\INotv.,,
!. !

D 1pd.ut Ool<l\di("d: 41'/201J 4$


1)(1<, s..;,41,yt"

. 13.16.
286 IV.

, ,
.
so.open(),
FILE _WRITE. File
( , serial), ,
parseint(). 13.4.

File commandFile = SD.open("speed.txt");


if (commandFile)
{
Serial.println("Reading Command File");
while(commandFile.availae() )
{
refresh_rate = commandFile.parseint();
}
Serial.print("Refresh Rate = ");
Serial.print(refresh_rate);
Serial.println("ms");

else

Serial.println("Could not read command file.");


return;

13.4
. ,
. .
13.3 13.4 ,
speed.txt, 13.5.

'r 13.5. 1.f SDapn.1--1.d_read_write.ino


// SD-
#include <SD.h>
//
//MOSI = pin 11
//MISO = pin 12
//SCLK = pin 13
// CS
const int cs PIN =10;
const int POW PIN =8;
//
int refresh rate = 5000;
13. SD 287

void setup()
{
Serial.begin(9600);
Serial.println("Initializing Card");
// CS
pinode(CS_PIN, OUTPUT);
// 8, HIGH
pinode(POW_PIN, OUTPUT);
digitalWrite(POW_PIN, HIGH);
if ( !SD.begin(CS_PIN))
{
Serial.println("Card Failure");
return;

Serial.println("Card Ready");
!! (speed.txt)
File comandFile = SD.open("speed.txt");
if (comrnandFile)
{
Serial.println("Reading Comrnand File");
while(comandFile.availae())
{
refresh_rate = comandFile.parseint();

Serial.print("Refresh Rate = ");


Serial.print(refresh_rate);
Serial.println("ms");
comandFile.close(); //

else

Serial.println("Could not read comand file.");


return;

void loop()

long timeStamp = millis();


String dataString = "Hello There!";
//
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.print(timeStamp);
dataFile.print(",");
dataFile.println(dataString);
dataFile.close(); //
288 IV.

//
Serial.print(timeStarnp);
Serial.print(",");
Serial.println(dataString);

else

Serial.println("Couldn't open log file");

delay(refresh_rate);


, .
(. 13 .17).

. 13.17. Refresh Rate,

13.3.

. (R)
, ,
. millis(),
, Arduino. -
13. SD 289

,
SD-.

13.3.1.
.
, ,
.
DS1307.

DS1307
DS1307 Arduino I2 c
,
. ,
. adafruit-DS1307-breakout
(http://www.exploringarduino.com/parts/adafruit-DS1307-breakout),
DS1307, , ,
1 2 .
Arduino (. 13.18).

. 13.18. adafruit-DS1307-breakout Arduino

, . ,

Arduino. 32,768 ,
2,2 3,0 .
,
, . 13.19.
290 IV.

. 13.19. ,

Arduino RTClib
,
Arduino.
(RTC). RTClib,
JeeLabs, Adafruit Indusrtries.
- http://www.exploringarduino.com/content/ch13.
libraries, 12.
.
RTC.adjust () .
RTC
RTC. now () .
.

13.3.2.
SD- ,
. ,
,
millis ().
13. SD 291

SD card shield RTC


Arduino SD card shield RTC.
Cooking Hacks Micro SD shield adafruit-DS1307-breakout,
, . 13.20.

. 13.20. Arduino
Cooking Hacks Micro SD shield adafruit-DS1307-breakout

, RTC Arduino; ,
RTC, .
2 LOW HIGH (+5 ),
RTC. RTC ,
-.

RTC
RTC .
:
+ RTC;
+ RTC (2-LOW, -rG);
292 IV.

RTC;
RTC ;
.
,
. , ,
CSV, .
!
,
, .
- , ,
Serial.print()
Serial.println() . ,
,
Arduino. F(),
Serial.println (F ("Hello")). 13.6.

( 13.6) RTC
. -,
.

// SD- RTC
#include <SD.h> // SD
#include <Wire.h> // RTC
#include "RTClib.h" // RTC
// SPI I2 C
// SD- SPI
// RTC - I2C
const int CS PIN =10;
const int SD POW PIN =8;
const int RTC POW PIN =;
const int RTC GND PIN =2.;
// 5
int refresh rate = 5000;
// RTC
RTC_DS1307 RTC;
//
String year, month, day, hour, minute, second, time, date;

void setup()
{
Serial.begin(9600);
Serial.println(F("Initializing Card"));
/! CS
pinode(CS_PIN, OUTPUT);
13. SD 293

pinode(SD_POW_PIN, OUTPUT);
pinode(RTC_POW_PIN, OUTPUT);
pinode(RTC_GND_PIN, OUTPUT);
// RTC
digitalWrite(SD_POW_PIN, HIGH);
digitalWrite(RTC_POW_PIN, HIGH);
digitalWrite(RTC_GND_PIN, LOW);
// Wire RTC
Wire.begin();
RTC.begin();
// RTC , /
if ( ! RTC.isrunning())
{
Serial.println(F("RTC is N running ! "));
RTC.adjust(DateTime( DATE, TIME ));
}
// SD-
if ( !SD.begin(CS_PIN))

Serial.println(F("Card Failure"));
return;

Serial.println(F("Card Ready"));
// ',' (speed.txt)
File conandFile = SD.open("speed.txt");
if (commandFile)
{
Serial.println(F("Reading Command File"));
while(conandFile.availae())
{
refresh_rate = conandFile.parseint();

Serial.print(F("Refresh Rate = "));


Serial.print(refresh_rate);
Serial.println(F("ms"));
conandFile.close();

else

Serial.println(F("Could not read command file."));


return;

//
F'ile dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.println(F("\nNew Log Started !"));
294 /V.

dataFile.println(F("Date,Time,Phrase"));
dataFile.close();
//
Serial.println(F("\nNew Log Started!"));
Serial.println(F("Date,Time,Phrase"));

else

Serial.println(F("Couldn't open log file"));

void loop()

//
DateTime datetime = RTC.now();
year = String(datetime.year(), DEC);
month = String(datetime.month(), DEC);
day = String(datetime.day(), DEC);
hour = String(datetime.hour(), DEC);
minute = String(datetime.minute(), DEC);
second = String(datetime.second(), DEC);
//
date = year + "/" + month + "/" + day;
time = hour + ":" + minute + ":" + second;
String dataString = "Hello There!";
//
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)
{
dataFile.print(date);
dataFile.print(F(","));
dataFile.print(time);
dataFile.print(F(","));
dataFile.println(dataString);
dataFile.close();
//
Serial.print(date);
Serial.print(F(","));
Serial.print(time);
Serial.print(F(","));
Serial.println(dataString);

else

Serial.println(F("Couldn't open log file"));

delay(refresh_rate);
13. SD 295

RTC #include "RTClib.h"


R_s17 RTC. RTC 12 -,
Wire, 8. setup ()
RTC. isrunning () , RTC. ,
,
. , RTC
. setup () - ,
.
loop () Dataime
RTC. DateTime , , ,
, , ,
. -
.
-
. ,
. 13.21.

Time Phrase
4/8/2013 23:24:05 Hello Therel
4/8/2013 23:24:07 Hello Tl1erel
4/8/2013 23:24:09 Hello There!
4/8/2013 23:24:11 Hello Therel
4/8/2013 23:24:14 Hello Therel
9 4/8/2013 23:24:16 Hello Therel . 13.21.
10 4/8/2013 23:24:18 Hello herel -
11 4/8/2013 23:24:20 Hello Therel
4/8/2013 23:24:22 Hello Therel
4/8/2013 23:24:24 Hello Therel
4/8/2013 23:24:26 Hello Therel
4/8/2013 23:24:28 Hello Therel
16 4/8/2013 23:24:30 Hello Therel
1:7 4/8/2013 23:24:32 Hello Therel

1
18 4/8/2013 23:24:34 Hello Therel
4/8/2013 23:24:36 Hello Therel
4/8/2013 23:24:38 Hello Therel

13.4.
.

. -
SD- .
296 IV.

13.4.1.
, , -
. , ,
. ,
. . 13.22.

. 13.22.

, -
, .
.
- Arduino
(. 13.23).

13.4.2.
,
.
13. SD 297

. 13.23.

-
. , , -
.
.
,
75 ( ,
, -). ,
.
SD-
, .

. Arduino 50
(
). ,
1 ( 50 ).
13.7 ,
.

!/
#include <SD.h> // SD
#include <Wire.h> // RTC
#include "RTClib.h" // RTC
298 IV.

// SPI I2 C
// SD- SPI
// RTC - I2 C
const int CS PIN =10; // SS n SD
const int SD POW PIN =8; // JI SD
const int RTC_POW_PIN =; // RTC
const int RTC GND PIN =2.; // n RTC
const int IR PIN =; // -
// RTC
RTC_DS1307 RTC;
// /
String year, month, day, hour, minute, second, time, date;

// n -
int raw = ;
int raw_prev = ;
boolean active = false;
int update_time = ;

void setup()
{
Serial.begin(9600);
Serial.println(F("Initializing Card"));
// CS
pinode(CS_PIN, OUTPUT);
pinode(SD_POW_PIN, OUTPUT);
pinode(RTC_POW_PIN, OUTPUT);
pinode(RTC_GND_PIN, OUTPUT);
// RTC
digitalWrite(SD_POW_PIN, HIGH);
digitalWrite(RTC_POW_PIN, HIGH);
digitalWrite(RTC_GND_PIN, LOW);
// Wire RTC
Wire.begin();
RTC.begin();
// RTC , /
if (! RTC.isrunning())
{
Serial.println(F("RTC is NOT running!"));
RTC.adjust(DateTime( DATE, TIME ));
}
// SD
if (!SD.begin(CS_PIN))

Serial.println(F("Card Failure"));
return;
13. SD 299

Serial.println(F("Card Ready"));
//
File dataFile = SD.open("log.csv", FILE_WRITE);
if (dataFile)

dataFile.println(F("\nNew Log Started!"));


dataFile.println(F("Date,Time,Raw,Active"));
dataFile.close();
//
Serial.println(F("\nNew Log Started!"));
Serial.println(F("Date,Tirne,Raw,Active"));

else

Serial.println(F("Couldn't open log file"));

void loop()

!/
DateTirne datetirne = RTC.now();
year = String(datetirne.year(), DEC);
rnonth = String(datetime.rnonth(), DEC);
day = String(datetirne.day(), DEC);
hour = String(datetirne.hour(), DEC);
rninute = String(datetime.rninute(), DEC);
second = String(datetime.second(), DEC);
//
date = year + "/" + rnonth + "/" + day;
time = hour + ":" + rninute + "" + second;
//
raw = analogRead(IR_PIN);
// 75
!/ .
if (abs(raw-raw_prev) > 75)
active true;
else
active false;
raw_prev raw;
// - .
if (active 11 update_tirne == 20)

File dataFile = SD.open("log.csv", FILE_WRITE);


if (dataFile)
{
dataFile.print(date);
300 IV.

dataFile.print(F(","));
dataFile.print(time);
dataFile.print(F(","));
dataFile.print(raw);
dataFile.print(F(","));
dataFile.println(active);
dataFile.close();
//
Serial.print(date);
Serial.print(F(","));
Serial.print(time);
Serial.print(F(","));
Serial.print(raw);
Serial.print(F(","));
Serial.println(active);

else

Serial.println(F("Couldn't open log file"));

update_time = ;

delay(50);
update_time++;

13.4.3.
Arduino
.
, SD- - CSV
. ,
, .
, . -
, ,
, .
. -,
. ,
Google. - http://www.exploringarduino.com/content/chl3
.
Google Drive.
, . 13.24.
13. SD 301

---------

g I
1

t

JI
J---.-----.---..-....-.-----....-.....__
0:1240 0'15:24 0.14'50

.1s 016.16 0:17 00 0'17.43

. 13.24. ,

:
+ SV-,
.
+ SD- Windows,
Linux.
+ SD- Arduino,
.
+ Arduino SD
SD-.
+ RTC .
+
-.
+ ,
- .
+ ,
.

14
Arduino

:
+ Arduino ( Uno);
+ US- Arduino;
+ Ethemet shield;
+ ;
+ 36;
+ RG-;
+ 1 1 ;
+ 1 150 ;
+ 3 220 ;
+ ;
+ Ethemet;
+ ;
+ ;
+ .

http://www.exploringarduino.com/content/chl4
, . ,
www.wiley.com/go/exploringarduino
Downloads.


, . Arduino ,
. - ,
Arduino .
14. Arduino 303

Arduino Ethemet
shield - .
, -,
Arduino .

14.1. , Arduino
, , -
, Arduino
, . 14.1.

. 14.1.

, Arduino
- , .
Arduino
(, , , ).

14.1.1.
Arduino , ,
.

I-
I- ,
, .
304 IV.

I-: I- I-.
(. . 14.1 ),
I-,
. /
I-, .
,
, (NAT).

-
-, I-, (
). -
. , ,
- Wi-Fi,
Ethernet. -
.

HTML
HTML, ,
. - Arduino
L-, .

, ,
World Wide Web ( ) .
, .
, -
.

GET/POST
GET POST
. URL, www.jeremylum.
com/?s=arduino, GET. GET ,
URL. s
arduino. URL,
s, . POST
, URL. ,
. POST ,
.

DHCP
DHCP, ,
. Wi-Fi
I-, -
14. Arduino 305

.
?
DHCP,
I-. ,
.
Arduino , , I-
.

DNS
DNS Domain Name System (
). -, ,
I-. www.google.com DNS-cepep
, I-, URL.
I- ,
Google. DNS
I- -. DNS
.


, Arduino Ethernet
shield . , ,
(
). ,
. -,
, . - ,
.
- .

Arduino
, ,
Arduino Ethernet-aanepo.
,
WIZnet Ethernet. ,
.
Arduino Ethernet, Ethernet.

MRiIM
Ethernet-aanep, . . ,
Arduino Ethernet .

Ethernet-aanep Arduino Ethernet


Ethernet
Ethernet. thmt- "crossover".
Arduino USB .
306 /V.

,
, ,
. , ,
, .
, -
I-,
. 10.

14.2. Arduino
Arduino -.
L- Ethernet Arduino
-,
Arduino.
- RG-
. ,
, Arduino.

14.2.1.
-
Arduino
. RG
.
. 14.2. , 4, 10, 11, 12 13
Arduino Ethernet. RG-
5, 6, 7, - 3 Arduino.

14.2.2. -
- Arduino. -
RG-
, . -
GET.
- Arduino,
, -
Arduino.
( Notepad++ Windows,
)
html. , test.html.
, , -,
<body> <header>.
. L- 14. l.
14. Arduino 307

. 14.2. Arduino-cepepy RG-

<fon action='' method='get'>


<input type='hidden' name='L' value='7' />
<input type='sumit' value='Toggle Red' />
</fon>
<fon action='' method='get'>
<input type='hidden' name='L' value='' />
<input type='sumit' value='Toggle Green' />
</fon>
<fon action='' method='get'>
<input type= 'hidden' name='L' value='S' />
<input type='sumit' value='Toggle Blue' />
</fon>
<fon action='' method='get'>
<input type='range' name='S' min='O' max='lOOO' step='lOO' value='O'/>
<input type='sumit' value='Set Frequency' />
</fon>

L- 14.1 . <fon>
, </fon>- .
308 IV.

<input> , .
L
RG-. action ,
. (input
hidden) sumit.
L- (input range).
. 100
, s.
( ) .
, , (
Google Chrome). Chrome <Ctrl>+<O>
( Windows) <Cmd>+<O> ( OS ), .
L- (. 14.3).

[,Jgggl fllc!

l:1'mleJ311.1e J

. 14.3. - Chrome


, GET.

14.2.3. Arduino-cepepa
L- -
Arduino-cepepa, ,
,
G.

I- DHCP
DHCP Arduino Ethemet-aanepo
. ,
. SPI Ethemet,
- Ethemet-aanepa ( )
EthernetServer. setup () Ethernet
-, , -.
I- Ethernet,
, Arduino I- D
I- . I-
Arduino -.
14. Arduino 309


loop () .
, , m
.
Arduino ,
. :
-, .
, , ,
. ,
"" : "404 Responce". 404 ,
. "200 Response"
, L- .
"200 Response" ,
L-, :
/1.1 200
Content-Type: text/htrnl
L-.
G-. G-,
? URL. ? , ,
. - L,
- s.
Arduino. break
,
, .

-
, ,
Arduino. ,
,
. , 14.2, RG
.
G-. ,
, .

// Arduino -
// MIT License
// http://bildr.org/2011/06/arduino-ethernet-pin-control/
#include <Ethernet.h>
#include <SPI.h>
const int BLUE =5;
const int GREEN =;
310 IV.

const int RED =7;


const int SPEAER =;

// r! RG-
// ,
//
int freq = ;
int pin;

// -
//
//
byte mac[] = { 90, 2, OxDA, , 4, };

// 80
EthernetServer server = EthernetServer(80); // 80
boolean receiving = false; // GET

void setup()
{
Serial.begin(9600);
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);
// DHCP
if (!Ethernet.begin(mac))
{
Serial.println("Could not Configure Ethernet with DHCP.");
return;

else

Serial.println("Ethernet Configured!");

//
server.begin();
Serial.print("Server Started.\nLocal IP: ");
Serial.println(Ethernet.localIP());

void loop()

EthernetClient client server.availae();


if (client)
{
//
boolean currentLineisBlank true;
boolean sentHeader = false;
14. Arduino 311

while (client.connected())

if (client.availae())
{
char = client.read(); //
if(receiving && == ' ') receiving = false; //
//
if(c == '?') receiving = true; // ?
// GET
if(receiving)

// ( L)
if ( == 'L')

Serial.print("Toggling Pin ");


pin = client.parseint();
Serial.println(pin);
digitalWrite(pin, !digitalRead(pin));
break;

// ( S)
else if ( == 'S')

Serial.print("Setting Frequency to ");


freq = client.parseint();
Serial.println(freq);
if (freq == )
noTone(SPEAER);
else
tone(SPEAER, freq);
break;

//
//

//
if( !sentHeader)
{
//
client.println("HTTP/1.l 200 ");
client.println( "Content-Type: text/html \n");
// RGB
client.println("<fon action='' method='get'>");
client.println("<input type='hidden' name='L' value='7' />");
client.println("<input type='sumit' value='Toggle Red' />");
client.println("</form>");
312 IV.

// RGB
client.println("<form action='' method='get'>");
client.println("<input type='hidden' name='L' value='' />");
client.println("<input type='sumit' value='Toggle Green' />");
client.println("</form>");
// RGB
client.println("<form action='' method='get'>");
client.println("<input type='hidden' name='L' value='5' />");
client.println("<input type='sumit' value='Toggle Blue' />");
client.println("</form>");
//
client.println("<form action='' method='get'>");
client.print("<input type='range' name='S' min='O' max='lOOO'"
"step='lOO' value='O'/>");
client.println("<input type='sumit' value='Set Freq.' />");
client.println("</form>");
//
//
sentHeader = true;

if ( '\n' && currentLineisBlank) break;


if ( '\n')

currentLineisBlank true;

else if ( ! = '\r')

currentLineisBlank false;

delay(5); // -
client.stop(); //

,
. - , Ethemet
aamepa. , 14.2.
Arduino .
, Arduino
DHCP.
I- (. 14.4).
, . 14.4, Arduino I-
192.168.0.9. . I-,
-.
14. Arduino 313

!tllernet Conf1gurea!
Server Started.
Lacal IP: 192.16S.0.9

. 14.4. DHCP I-

14.3. Arduino
, , Arduino
I-,
. ,
Arduino
.

14.3.1. Arduino

, - , ,
, Arduino ( Wi-Fi
Ethemet). I-
. L-, .
/ RG-.
.
Arduino .
Arduino IDE, .
, Arduino GET
(. 14.5).
Arduino ,
, Arduino
.
314 IV.

Toqgl"J Pin 7
To9glin9 Pin 7
TO\'l\'fl1ng F1n 6
:!'ogqll.ng 1n 5
Togg11n1J P.1n 5
Toggl1ng P1n S
Toggl111\'I Fl.n 6

. 14.5. Arduino -


, Arduino ,
http:l/www.exploringarduino.com/content/ch14.
Wiley.

14.3.2. Arduino

Arduino
, I- .
Arduino
, ,
.
14. Arduino 315

, :
1. DHCP, Arduino.
2.
Arduino.
3. DNS.
!
.
, . .
.
. ,
.
,
DNS.
, Arduino .


. URL
apeco I- .

I- Arduino, . ,
, I- Arduino 192.168.0.9, ,
( ), 192.168.0.1.
, .
(
). ,
, .
I- , . Windows
ipconfig.
.
, ,
TCP/IP .
Linux, , route -n
Gateway, .

I- Arduino DHCP
,
DHCP. ,
-
I-. I-
DHCP -,
,
. DHCP I- Arduino,
.
316 IV.

, I- Arduino,
-, .
.
, , Arduino
I- .

, Arduino IP (
DHCP) . , ,
http://arduino.cc/en/Reference/EthernetlPAddress.

80 Arduino
, I- Arduino,
- I-. Port
Forwarding-
I-. 80
-. Port Forwarding
80
80, I- Arduino.
, 80-80.
80 Arduino.

DNS
- .
, I-.
-, .
IP, I-
Arduino.
DNS I-.
, I-. ,
, I- .
, I-
Arduino I-, .
- IP.
,
I- -.
- (, myarduino.dyndns.org),
I- , .
DynDNS - ,
.
, DynDNS .
, .
,
.
Arduino ,
14. Arduino 317

I-.
DynDNS, , DynDNS
, ,
.
I- (
URL), Arduino
. , .

14.4.

, Arduino -,

.
Arduino - .
, , Arduino
( -
) I-,
I- . .
- Xively ( Cosm)
, Arduino.

14.4.1. Xively
- Xively
, Arduino .
Xively
, .

Xively
, http://www.xively.com
. , ,
.


, Develop
, . Add Device. (. 14.6)
.
.
Add Device.
. , . .

Arduino.
318 IV.

< > Add Device

. 14.6. Xively

Xively HTTPClient
Xively Arduino ,
. Xively HttpClient ,
GitHub. : https://
github.com/xively/xively-Arduino https://github.com/amcewen/ttpClient
Download ZIP .
- http://www.exploringarduino.com/content/chl4.
, :
1. ,
(GitHub ).
HttpClient-master HttpClient, Xively
Arduino-master xively.
2. Arduino, m 12.
3. Arduino IDE ( m
, ) -> -
14. Arduino 319

. HttpClient xively. ,
.
Xively
. Arduino IDE DatastreamUpload
xively. ,
, .
, 2:
// Analog pin which we're monitoring ( and 1 are used the
// Ethernet shield)
int sensorPin = 2;
Arduino
Ethemet.

Arduino
2 Arduino.
2 Xively.
1
2 (. 14.7), 3.
Arduino .

. 14.7. Arduino Ethernet


320 IV.

Xively
.
, Arduino.

Xively. : -
Ethemet, Xively API key Feed ID. - ,
. xively API key Feed ID Xively
API Keys (. 14.8).

Auto-generated Arduino device key for feed


1242622121
QkjXS1oUKQCGhqh3f>.v4\\lls.c!vOSAKx4ZXZYS\,VtJGUWdxczOg
permlulon& READ.UPOAiE,CREAT.DELE

+ Adcfiey
. 14.8. Xiveli API key Feed ID

Feed ID ( ) Xively API key (


) . ,
.
-:
// - Ethernet
byte mac[] = { OxDE, OxAD, , OxEF, OxFE, OxED };
Xively API :
// Xively API key
char xivelyKey[] = "YOUR_XIVELY_API_EY";
Feed ID (15552 ) :
// Feed ID
XivelyFeed feed(15552, datastreams, 1 /* */);
14.3 .

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
// - Ethernet-aaepa
byte mac[] = { 90, 2, OxDA, , 4, };
14. Arduino 321

// Xively ! key
char xivelyKey[] = "qkjXSloUKqbCG-hqh3fw4WisdvOSAx4ZXZYSWhGUWdxcz0g";
//
int sensorPin = 2;

//
char sensorid[J = "sensor_reading";
XivelyDatastrearn datastrearns[J = {
XivelyDatastrearn(sensorid, strlen(sesor!d), DATASTREA_FLOAT),
} ;
// Feed ID
XivelyFeed feed(l242622121, datastrearns, 1 /* nner of datastrearns */);
EthernetClient client;
XivelyClient xivelyclient(cliet);

void setup()

//
Serial.begin(9600);
Serial.printl("Starting single datastrearn upload to Xively...");
Serial.println();
while (Ethernet.begin(rnac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);

void loop()

int sensorValue = analogRead(sensorPin);


datastrearns[OJ.setFloat(sensorValue);
Serial.print("Read sensor value ");
Serial.println(datastrearns[O) .getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(15000);

Arduino, .
Arduino Xively
-, .
,
. datastrearns[J, -
322 IV.

( float). XivelyFeed
, ,
.

-
Arduino.
"200" , ,
, Xively API key Feed ID.
. ,
Xively, sensor_reading
15 . sensor_reading, ,
.
, . 14.9. , .
Arduino
Xively.

APIKeys

Auto-geated Ardulno device key fo1 feed

L ej, R ::
tl'P"1Qa\i.ing !"t,::-;--
to XJ,;,r-e)y -- -
s1lyc1ient ,p'l:t r-c1.irned lOti
.. -- . -
1242622121

"
41d. 17en.:Q:t v,1uo 619'.
O'f.l-04d.itlQ' 1t: t XiVt!:l;i
x:i..velycli.nt.put :.'e"tur.4 .100

. 14.9. Xively

14.4.2.
, Xively, ,
? , .
, Arduino .
, 12 SPI.
14. Arduino 323


36 (. 3),
3, . 14.10.

. 14.10. 36


,
Xively. ,
, .
datastream ,
light_reading temp_reading. 14.4 ,
. Xively API key, Feed ID -
, .

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
324 IV.

// - Ethernet
byte mac(] = { 90, 2, OxDA, , 4, };
// Your Xively key to let you upload data
char xivelyKey[] = "qkjXSloUKqbCG-hqh3fw4WisdvOSAx4ZXZYSWhGUWdxcz0g";

// ( 1
// Ethernet)
int lightPin = 2; //
int tempPin = ; //

//
char lightid[] = "light_reading";
char tempid[] = "temp_reading";
XivelyDatastream datastreams[] = {
XivelyDatastream(lightid, strlen(lightid), DATASTREA_FLOAT),
XivelyDatastream(tempid, strlen(tempid), DATASTREA_FLOAT),
};

// Feed ID
XivelyFeed feed(1242622121, datastreams, 2 /* numer of datastreams */);
EthernetClient client;
XivelyClient xivelyclient(client);

void setup()

//
Serial.begin(9600);
Serial.println("Starting doue datastream upload to Xively...");
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);

void loop()

int lightValue = analogRead(lightPin);


datastreams[O].setFloat(lightValue);
Serial.print("Read light value ");
Serial.println(datastreams[O].getFloat());
int tempValue = analogRead(tempPin);
datastreams[l].setFloat(tempValue);
Serial.print("Read temp value ");
Serial.println(datastreams[l].getFloat());
Serial.println("Uploading it to Xively");
14. Arduino 325

int ret = xivelyclient.put(feed, xivelyKey);


Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(l5000);

, , () m
. , ,
. tempid [ J datastreams [ J.
xivelyFeed , , ,
. loop()
. ,
datastreams ,
datastreams []. datastreams
, datastreams [1]. Arduino
- . ,
sensor_reading, . .
light reading. Arduino
, . 14.11.

-
00

1'(1(1
"'
r

our ted
fed

f,s,@d

ioo \,)1' !eed

; U'r le,ed

<'
AtUplt1:ad.111.g 1t to x.twly
[!xi\-elycl1ent..pu.t ;r:etu.i-ned 2Q!C:
12f[
liJRe:t.d: 1.t.,;:ht ?..tlue 69 GO
p,lt:4e&-tt teq, V&.lU !tl..-OD
f+l)plQa.<itno it t-c- Xi"--ely
1}avely.c11er..t,p--ut ret:.1Jtt1ec.t :2:0-0
;:

. 14.11. Xively

, Arduino -,
-.
, - .
326 IV.

:
+ IP, DHCP, DNS, .
+ .
+ L- Arduino .
+ - Arduino.
+ - Arduino .
+ Arduino Xively .
+ -, .
Arduino - Atmel.
Arduino,
Tmega, ,
. , Arduino Uno,
, .


-
.
, ,
.


, , ATmega 328.
, ATmega 328 Arduino Uno
. .
Google "ATmega 328 datasheet" DF-
Atmel. , Arduino,
http://www.arduino.cc
. (. .1).
,
.

. , 32
, 1 ,
1,8 5,5 ( Arduino 5 ).
-, (SPI, 12),
- ().
328

Features
Hlgh Perfonnance, Low Power AV8-Sit Mlcrocontroller
Advanced RISC Archltec:ture
- 131 Powerful lnstruc:tlons - Most Slngle Clodc Cycle Execution
- 32 8 General Purpose Working Reglsters
- Fully Statlc Operatlon
- Up to 20 MIPS Throughput at 20 MHz
- On-chlp 2,cycle Multipller
Hlgh Endurance Non-volatlle Memory Segments

s-t AVR
- 4/8/16/32 Bytes of lnSystem Self..Programmae Flash progam memory
(ATmega48PA/88PA/168PA/328P)
- 258/512/51211 Bytes EEPROM (Afmega48PA/88PA/168PA/328P)
- S1211/1/2 Bytes lntemal SRAM (ATmega48PA/88PA/168PA/328P)
- Wrlte/Erase Cycles: 10,000 Flash/100,000 EEPROM
Microcontroller
- Dsta retentlon: 20 years at asc1100 years at 25"'1)
- Optional Boot Code Sectlon wlth lndependent Lod< Blts with 4/8/16/32
Bytes ln-System
ln-System Programmlng On-ch\p Boot Program
1'rue ReadWhlleWrlte Operatlon
- Programming Lock for Software Securlty
Perlpheral Features Programmae
- Two 8-lt Tlmer/Counters with Separate Prescaler and Compare Mode
- One 16t Tlmer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Flash
- Real lme Coumer with Separate Osclllator
- Six PWM Channels
- 8-channel 10-lt ADC in TQFP and QFN/MLF package
Temperature Measurement
ATmega48PA
- khannel 10.it ADC in PDIP Package
Temperature Measurement
ATmega88PA
- Programmae Serlal USART
- Master/Stave SPI Serial lnterface ATmega168PA
- Syte-orlented 2wire Serial lnterface (Phlllps 12 compatlle)
- Programmae watchdog Tlmer with Separate On-chlp Osclllator ATmega328P
- On-cllip Analog Comparator
- lnterrupt and Wekllp on Pln Change
Speclal Mlcrocontroller Features
- Power-on Reset and Programmae Brown-out Delec:tion
- lntemal Calibrated Osclllator
- Extemal and lnternal lnterrupt Sources
- Slx Sleep Modes: ldle, ADC Nolse Reductlon, Powur-save, Power-down, Standby,
and Extended Standy
110 and Packages
- 23 Programmae 110 Lines
- 28-pln PDIP, 32-lead TQFP, 28-pad QFNJLF and 32-pad QFN/LF
Operaling Voltage:
- 1.8 5.5V for ATmega48PA/88PA/168PA/328P
Temperature Range:
- -40 to 85"
Speed Grade:
- 0-20 MHz@1.8 5.SV
Low Power Consumptlon at 1 MHz, 1.8V, 25 for ATmega48PA/88PA/168PA/328P:
- Al:live Mode: 0.2 mA
- Power-down Mode: 0.1 11
- Power-save Mode: 0.75 11 (lncludlng 32 kH:E R)

Rev. 8161!>-AVR-10/09

. .1. ATmega 328


ATmega Arduino 329

,
, .
, , DF-,
.
-, ,
. 13-1
1/0-Ports , . .2.
, ,
Arduino. ,
- ,
.
Cpin, .

P,nt------------------- Logic

See Figure
"General Oigi!al 1/0" for
Detai!s
L------

. .2. ATmega 328: -

ATmega 328
,
.
,
. ATmega 328 (. .3).
ATmega, Arduino Uno,
.
, . .3
. ()

1.
, , .
:
+ VCC - ( Arduino 5 );
+ AVCC - ( Arduino 5 );
330

(PCtNT14/RSET) 6 1 26 5 (ADC5/SCL/PCINT13)
(PCINT16/RXD) PDO 2 27 4 (ADC4/SDA/PCINT12)
(PCINT17/TXD) PD1 3 26 (ADC/PCINT11)
(PCINT18/INTO) PD2 4 25 2 (ADC2/PCINT10)
(PCINT19/0C2BIINT1) D 5 24 1 (ADC1/PCINT9)
(IN20//) PD4 6 23 (ADCO/PCINT8)
vcc 7 22 GND
GND 8 21 AREF
(PCINT6/XTAL 1/S1) 6 9 20 AVCC
(PCIN7/XTAL2/OSC2) 7 10 19 5 (SC/PCINT5)
(PCINT21/0COB/1) PDS 11 16 4 (MISO/PCINT4)
(PCINT22/0COA/AINO) PD6 12 17 (MOSI/OC2NPCINT)
(PCINT23/AIN1) PD7 13 16 2 (SS/OC1B/PCINT2)
(PCINTO/CLKOIICP1) 14 15 1 (OC1A/PCINT1)

. .3. ATmega 328

Atmega168 Pln Mapplng


Arduino functlon Ardulno tuncllon
,01 (PCINT14JRESET) 6 1 5 (ADCSISCUPCIN13) al(IQ lput 5
d1g1!11I pin (RX) (PCINT16IRXO) 2 4 (ADC4JSDAIPCIN12) ar1atog ir1pul 4
cllgltal pin t {'f ) (IN17/) 1 3 (ADC31PCIN11) !Q lnp,it 3
diJi!.il pin ;,> (PCINT18JINTO) 2 4 PC2 IADC2.IPCIN10) an1!09 lnptil 2
d!gitat pir1 (f'1WM) (PCINT19/0C2SIIN1) & 24 1 (AOC1/PCINT9) lllll'lf'J \11p1.1t 1
di{ltli!I li)in 4 (IN201/) 4 (AOCOJPCIN8) .inat09 1put
vcc vcc 7 GND GND
(,) 2t AREF ana!og mlcrenoo
Cl)!!\l/11 (PCINT61XTAL 1/S1) 6 9 20 AVCC vcc
Cf\11:11111 (PCIN7JXTAL.2/OSC2) 7 10 19 S (SCJPCIN5) dlgit.il pin 13
di!,lllal 5 (PWM) (IN21/8/1) PDS tl 18 4 (MISOJPCINT4) d!ilal pl11 12
ctt11ital pin 1'1 (P\I\IM) (PCINT22/0COAIAINO) PDS ll 11 P(MOSIIOC2AIPCIN3) di9ilal 111 t1(PW)

'"
tlig!l.11\ pitl 7 (PCIN23/AIN1) 07 13 2 (SSIOC1IPCINT2) digital p!n 10 (PWM)
di;i!AI pin 8 (PCINTO/CLKOIICP1) 14 1 (OC1AJPCINT1) g\lal pj1\ 9 (PWM)

DI\Jitlill Pi!\: 11, 1.?. 1:1 Mt u!'NJ lh !$!., 1111 MISO


MOSI S0<1Almt!IO \ 11, 18& 19) A\.Ok!IV
1mi:1,u,.,p1n 1 i'>;l!MIC$Pnl"J.>1r,
. .4. ATmega 328 Arduino
Tmega Arduino 331

+ AREF - (< 5 );
+ GND - .
- - .

Arduino, .
.
, PDO PD 1
Rx . 6 7
. Arduino Uno
16
-.
,
, . Arduino
http://arduino.cc/en/llacking/PinMappingl68
Tmega Arduino (. .4).

Arduino
-
, , Arduino. . .5
Arduino Uno.
, . .5,
Arduino? (MCU) ( ZU4
) , ATmega 328 .
, Tmega ,
(IDE) Arduino. ,
PDO PD 1 USART Rx . Arduino
,
16U2 ( USB ). ,
13 Arduino . , 13
PBS Tmega. ?
,
. .
PBS, , , MCU,
SCK, , SCK
.
. ,
Arduino, .

n
J.. f
s:1J
'k'l
-

.J_ - GIII)
1

11



1) UNO
- -- t.
---
- 11

-'511
-

19' +'51,t

i! 1 d I!F.:== 11 I

1-= iiil,
I
13

-!l>'/
12
(ft*C+:,84 11
.- 111
j,=:::.1 n-""1 11
(....:.-1)'81 8
xw.,

2.
IJ&C ft.<t<:PI/C!Jlllj\'C7
100,-.,&
-...!$
!1 (!',,10,.
J'C"'
:J (C>ll'C'
!C'f9t<-lf'l>JEI! (-

=;li:::E3SE -"'11'1>'
(::-.;
-- 1 6
""

+-"-41.............., l()allltlm!Pl!O
,.'11Gll16U2"'"1J(Q)

"61

. .5. Ardu,no Uno Rev 1


::

F
analogRead() 67, 74 F16 272
analogWrite() 50, 51 FAT32 272
Arduino for() 255
Due 32 FTDI 120
IDE 36
Leonardo 32 G
LilyPad 35
Mega 2560 32 General Puic License, GPL 22
Mega ADK32 GET 304, 313
Nano 32, 120 get() 142


Uno 28, 32
ArduPilot 35
ASCII 130
Tmega 328 119, 327 L- 308
329 - 91
attachlnterrupt() 256, 262

ipconfig 315
I- 303
constrain() 78
createChar() 209
L
LCD 203
D loop() 40, 47
datafile.close() 282
datafile.print() 282
delay() 40, 255

DHCP 304 map() 78, 96
digipot 190 millis() 247
digitalRead() 54
digitalWrite() 40, 47, 56
Domain Name System, DNS 305
N
DynDNS 316 notone() 111, 216
334

setup() 47
shiftOut() 158,161
Open Source 22 SparkFun USB Explorer 228
SPI 186
SPI.begin() 195
SPI.transfer() 195
PAN 223
pinMode() 40,47
Port Forwarding 316

POST 304 tone() 109,110,117,216
Processing 136,182
pull-down 52
pull-up 52
u
UART 227
R USB-xoc 124

RS-232 119
RTC 288
v
RTC.adjust() 290 volatile 262
RTC.now() 290

s w
Wire.beginTransmission() 178
SCL 170 Wire.read() 178
SD.begin() 282
SD.open() 286
SDA 170
SD- 272 224
Serial.availae() 129 X-CTU 230
Serial.begin() 124
Serial.parselnt() 134
Serial.print() 124 z
Serial.println() 67,124 ZigBee 224
Serial.read() 129
335

3
FDI 120 30
I2c 171 46
72
- ,
65, 173

66 227

r39
39
223 Arduino 28

Ethernet 308
HttpClient 318

LiquidCrystal 206 -304
RTClib 290 114
SD 280 28
serial 184 32U4 123

Servo 99
7414 259
SoftwareSerial 228
74595 155
SPI 195, 308
DS1307 289
TimerOne 264
4213 190
197
4231 190
Wire 173, 177
SN754410 91
Xively 318
223
235, 237
229

Linux 234
Windows 230


- Xively 317


72 ! = 57
% 144

const 48
for 49
if/else 54
AD7414 172 include 103
71, 104, 162, 296
71, 212, 323
74 172

75 40
110
55, 257 Arduino Leonardo 245
Arduino Uno 247
Leonardo 143
43
-203 226
336

Arduino 31

SD- 276 264
67 86
190 259

254
264
- 86 126

I2c 110
SPI 187
HTML 308
CSV 143, 271
47
154 76

52, 173, 257 78
215
52


45, 114

,
109
44 for49
58
98
98
51
100 I2c 110
SPI 186
- ,
85 50, 104

100
- 91
Arduino Uno 331 " " 161