Izuchaem Arduino
Izuchaem Arduino
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
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
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.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
. 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 -.
-
.
[Link]
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.
:
+ ;
+ ;
+ ;
+ .
[Link]
.
,
. Wiley
[Link]. -
21
Arduino ,
, .
Arduino, .
Arduino:
Arduino -
[Link]
Arduino -
[Link]
Arduino Adafruit -
[Link]
Arduino SparkFun -
[Link]
Arduino - [Link]
Arduino elementl4-
[Link]
,
Twitter (@sciguy14), , .
([Link] .
Arduino?
Arduino .
, -,
. , Arduino -
,
Arduino IDE. , , ,
( ) ,
Arduino "" .
, Arduino,
. ,
Arduino -
22
, ,
. Arduino
1. Arduino, -
,
Arduino.
Open Source
(Open Source),
.
, ,
Arduino .
- :
[Link]
, Arduino - ,
.
, Arduino,
,
Arduino.
Arduino,
. Arduino
Arduino ( Arduino)
. , Arduino
, . ,
MakerBot Replicator D-
Arduino Mega ([Link]
, ( )
GNU General Puic License (GPL),
, .
, ,
Arduino YouTube ([Link]
[Link]/sciguy14)1
.
, ,
, ,
I Arduino .
[Link] - . .
23
([Link]
. Arduino,
,
.
, ,
.
. Arduino!
"-"
, ,
, Arduino Uno,
.
[Link]
"-" ""
. -
:
+ Arduino -
[Link]
+ ,
, - [Link] [Link]
[Link]/:-.
Arduino
1.
2.
3.
:
+ Arduino Uno;
+ US-.
1
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
EI \
Arduino,
"".
: [Link]
JEREMY n .
, ,
.
1.1. Arduino
Arduino
, Arduino.
, ,
. ,<,
, -
!
Arduino [Link]
1
[Link]/2011/01/02/arduino-tutorial-series-it-begins/ Wiley.
I
: [Link]
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\)
(
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).
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 - .
rduin- ,
IDE Arduino , .
Seeeduino, Adafruit 32U4, SparkFun Pro
Arduino.
, . ,
ArduPilot - (. 1.1).
rduin- MakerBot
D-.
1.8.
, Arduino,
.
.
00'/\.l}(sd{f
. 1.11. [Link]
.
Arduino IDE. IDE Windows ,
Arduino .
1. , Arduino 37
OS ,
,
. Network Preferences ( ->
). Apply ().
Not Configured, .
System Preferences ( ).
Arduino Windows,
, . Arduino IDE
Windows .
IDE zi-,
:
+ ;
+ ;
38 /. Arduino
MRi=iiM
,
, Arduino, , ,
, Arduino.
. Upload (
), Arduino IDE. ,
, .
, 13 Arduino,
. !
.
1. , Arduino 39
1.8.3. Blink
Blink (. 1.13),
, Arduino.
----1+1
lil\l!
Urnz on arJ LED on tor one :econd, then of! fot 011 econd, [Link].
. 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 .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
, ,
, .
Arduino -.
m, , , -
, .
:
Arduino, (pull-up)
(pull-down) .
2. -, - 43
Arduino ,
- (). ,
-. , RG
.
-
[Link]
inky-things/ 1 .
,
, , -
[Link]
tutorial-3/2 .
2.1. 1
1 , , m
. Arduino
:
+ ;
+ ;
+ ;
+ ;
+ - ().
2.2.
Arduino.
9
. ,
, . , 9 Arduino
- ,
.
2.2.1.
,
. - ,
.
I
: htt://[Link]/:2--wm-.
2
: htt://[Link]/:3--.
44 /. Arduino
. , ,
. +5 .
. , ,
.
.
. 2.1 .
( )
( )
. 2.1.
2.3.
. ,
. ,
- .
: , .
: .
,
( +5 ), -
.
. .
2. -, - 45
9 Arduino ,
.
, .
220 . . 2.2.
2.3.1.
- - ,
( ), (
) ( ) .
(,
9 ) (-, , ).
, :
+
;
+ ,
. , -
46 /. Arduino
, - . ( )
( )
( ). , ,
;
+ .
() ,
, .
, .
, ()
.
:
U = lR,
- ; 1 - ; R - .
,
. ,
.
. ( ),
.
20 .
2 .
, . 2.3,
Rl.
g1+
--,:
i'
:
R1.
. 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 ).
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.
void setup()
{
pinode (LED, OUTPUT); //
void loop()
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
.
void setup()
{
pinode (LED, OUTPUT); //
void loop()
analogWrite(LED, i);
delay(10);
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% ,
, - .
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).
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 , .
void setup()
{
pinode (LED, OUTPUT); //
//
pinode (BUTTON, INPUT); //
//
/*
*
*
* .
*/
boolean debounce(boolean last)
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 ()
.
void setup ()
{
pinode (BLED, OUTPUT); //
// BLUE
2. -, -n 59
/*
*
*
* .
*/
boolean debounce(boolean last)
/*
* .
* .
*/
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- .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
.
" ",
. ,
, ,
.
,
Arduino.
64 /. Arduino
, ,
Arduino.
,
. ,
Arduino ,
,
.
- 1
[Link] inputs/ .
, , -
[Link] 2010/06/20/lets-get-digital-or-analog/.
3.1.
. . :
. - ,
: , IGH LOW, 1 , . .
() .
.
.
. ? , , ,
, , , ,
. .
, .
,
.
3.2.
. 3.1 ,
. ,
: 5 . ,
: HIGH LOW. .
, ( 5 ),
.
I
: [Link]
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
[Link]
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 -
[Link](). Arduino
3.1.
68 /. Arduino
. 3.3.
. 3.4.
. 69
//
const int =; //
int val = ; //
void setup(}
{
[Link](9600};
void loop(}
{
val = analogRead(POT};
[Link](val};
delay(500};
. ,
, Serial .begin(},
.
, .
,
.
9600 .
val ,
analogRead(} ,
( ). [Link](}
, .
( ,
).
Arduino , ,
, 500 ( , ).
, Arduino US
.
, Arduino IDE ,
, . 3.5.
.
, , .
, , - 1023.
. 3.6.
70 /. Arduino
,,[Link] ,.,tup II
(
Sexi"[Link](9600);
vo1.d .1.
{
val = anolc,gRead () ;
[Link](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. (
[Link]
- [Link]
Sharp .
.
5 Sharp (
http:// [Link]/wp-content/uploads/2013/06/[Link])
.
+ 36. ( [Link]
[Link]/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.
+ . (
[Link]
. ,
: , Z ( ).
.
3,3 ,
analogReference (),
3,3 Arduino.
+ . (
[Link]
, , .
. .
Arduino
SudoGlove ([Link]
-, ,
. 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
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(), :
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 //.
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
.
?
, . ,
Arduino
. Arduino, ,
,
. , ,
. ,
,
. , ,
. ,
- .
, ,
-
1
[Link]
!
9 , . .
, Arduino.
,
.
. ,
. , 5
9 .
4.1.
. ,
, , DVD-neepa.
. ,
, .
, .
, -, .
I
: htt://[Link]/: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()
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
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.
!! -
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,[Link]>
//
#include <Servo.h>
const int SERV0=9; // 9
//
const int =; //
Servo myServo;
int val = ; //
void setup ()
{
[Link](SERVO);
4. 103
void loop()
{
val = analogRead(POT); //
val = map(val, , 1023, , 179); //
[Link](val); //
delay(15);
include, ,
Servo. Servo myServo myservo.
, ,
myServo. setup() ,
9 Arduino. Arduino
, Servo Arduino.
loop() ,
. 15 ,
, .
4.1 .
, ,
. () ,
, .
,
.
.
,
,
" ". - .
- ,
. ,
. ,
, ,
.
- .
,
, , .
[Link]
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()
[Link](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);
[Link](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 .
[Link]
, . ,
[Link]/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
, .
, [Link]/content/ch5
112 //.
. Arduino .
, , , Arduino
. ,
, .
pitches.h, , , Arduino ,
. Arduino IDE .
(. 5.3).
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 .
,
!
[Link]/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;
+ . ([Link], Parallax Adafruit);
;
.
[Link]
, . ,
[Link]/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 [Link]
and-processing/ 1 Wiley.
USB.
,
( RS-232), . . US-.
. 6.1.
Arduino
9- .
, ,
RS232 USB. ATmega328,
1
: [Link]
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 [Link]
Exploring Arduino.
FTDI (US-
FTDI . 6.3)
(. 6.4).
Arduino FTDI ,
USB.
.
. USB 121
FTDI
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
:
+ Windows
.
Arduino IDE ( OS Linux );
+
. Arduino
. USB 123
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.6. Arduino
, , -
Arduino .
.
, ,
, , .
Arduino.
6.6.1.
:
+ [Link](baud_rate);
+ [Link]("Message");
+ [Link]("Message"),
baud_rate essage- , .
, [Link]()
setup(), .
[Link]() [Link]()
. ,
[Link]() .
, ,
Arduino, . 6.6.
,
6.1,
.
6. USB 125
. 6.6.
//
!/
const int =; //
void setup()
{
[Link](9600); //
// 9600
126 //.
void loop()
6.6.2.
"" ( )
,
. (\),
. ,
: .
,
\ t. , \n.
,
, , [Link]() . ,
,
\n \ t , \\n \\t,
. 6.2 6.1,
.
//
const int =; //
void setup()
{
[Link](9600); //
// 9600
void loop()
,
, , . 6.7.
87 6\
Ot
\
----------------------------
Analoq P1n aaw Vali,e
------- ------
[Link]
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.
[Link]() [Link]()
. ,
, . -
128 //.
6.1.
Decimal [Link](23); 23
Hexadecimal [Link](23,HEX); 17
Octal [Link](23,0CT); 27
Binary [Link](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 ([Link]), m .
6.6.5.
Arduino IDE,
Arduino. ,
.
Arduino . ,
, Arduino
, .
,
.
Arduino
Arduino , .
Arduino , .
, :
+ [Link] () - ( ),
Arduino.
, ,
;
+ [Link] () - ,
.
, Serial. read ()
, ,
serial. availae () . ,
serial. read () , ,
. 6.3 Arduino.
/ /
char data; //
void setup ()
{
[Link](9600); //
// 9600
130 //.
void loop()
//
if ([Link]() > )
data = [Link](); //
[Link](data); //
-
. , , ,
.
Newline,
(\n), , .
[Link]() 6.3
[Link]()
char int
-
"5" "". ,
.
, ,
ASCJJ. ASCII (. 6.9) 7-
, 128 .
, ,
, char (. 6.3).
, , ,
. 6.3,
data int, , 5,
53 ( "5").
, . 6.9.
, Arduino .
? . -,
. 1,
:
if([Link] () == '1')
1 ,
.
' ' :
int val = [Link]() - '0'
9,
. parseint(), Arduino IDE, -
. USB 131
Dec Char
NULL null
Dec Char
20 32 Space
Dec Char
40 64 @ 60 96 -
Dec Char
.
.
,
. "1",
, "", .
9 Arduino, . 6.10.
,
. , ,
1 . Arduino
6.4
.
132 //.
. 6.10. 9 Arduino
//
const int LED=9;
char data; //
void setup(}
[Link](9600}; //
// 9600
pinode(LED, OUTPUT};
. USB 133
void loop()
{
//
if ([Link]() > )
data = [Link](); //
//
if (data == '1')
digitalWrite(LED, HIGH);
[Link]("LED ON");
//
else if (data == '0')
digitalWrite(LED, LOW);
[Link]("LED OFF");
, else
else if. ,
. ,
[Link]() , 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.
//
// RG-
const int RED =11;
const int GREEN =10;
const int BLUE =9;
// RGB
int rval ;
int gval ;
int bval ;
void setup()
{
[Link](9600); //
// 9600
// OUT
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);
void loop()
//
while ([Link]() > )
(
rval [Link](); //
gval [Link](); //
bval [Link](); //
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.
[Link] ( www.
[Link])
. !
Processing, ,
. 6.12.
6.7.3. Arduino
Processing
Processing
Arduino , .
, . 6.6. Arduino
. ,
Processing, ,
.
. USB 137
. 6.12. Processing. ?
//
const int =; //
int val; //
void setup()
{
[Link](9600); //
// 9600
void loop()
138 11.
. 6.7
.
6.7 . Processing
.
"" . , Linux
/dev/ttyUSBO. ,
Arduino IDE.
// Processing JI
// Serial
import [Link].*;
Serial port;
float brightness = ; // JI
void setup()
{
size(500,500); //
port = new Serial(this, "", 9600); //
//
[Link]('\n'); //
void draw{)
background(O,O,brightness); //
brightness = float([Link]('\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() .
[Link]( \n ).
, float().
brigthness, .
,
rssing- ( ,
).
SudoGlove - -
. Processing
, SudoGlove.
[Link].
[Link]/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) .
[Link] ( )
. data ,
. rssing-
. . 6.14.
void setup()
{
size(640,256);
img = loadimage("[Link]"); //
6. USB 141
void draw()
background(O); //
irnage(img,0,0); //
void mousePressed()
//
print(colors); //
[Link](colors); // Arduino
. 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
[Link]
[Link].
6.8.1.
Leonardo US-, i
Arduino .
, .
Leonardo US-,
. .
, ,
( CSV), Excel
Google SpreadSheeets .
,
csv.
,
[Link].
, . 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
void setup()
{
pinode (LED, OUTPUT); // OUPUT
[Link](); //
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); //
//
[Link](counter); //
[Link](","); //
[Link](temperature); //
[Link](","); //
[Link](brightness); //
//
counter++; //
146 11.
else
digitalWrite(LED, LOW); // ,
//
/*
*
* .
*/
boolean debounce(boolean last)
delay(5); // 5
current = digitalRead(BUTTON); //
return current; //
//
,
.
, [Link]() setup().
loop() Arduino
.
. ! running.
,
1 , .
. [Link]()
.
.
[Link]() Arduino <Enter> ( <Retum>)
.
.
. , .
,
. ,
.
, . ,
.
6. USB 147
[Link]
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()
{
[Link]();
void loop()
[Link](EY_LEE'I'_GUI);
[Link]('l');
delay(100);
[Link]();
.
.
,
[Link]
:
[Link]() [Link](). [Link]()
.
<Windows> <L>, [Link]() .
, [Link](),
. [Link]
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 //.
[Link]();
void loop()
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
// , ,
if (digitalRead(pin) == HIGH)
if ( ! [Link](mouseCommand))
[Link](mouseCommand);
// J
else
if ([Link](mouseCommand))
. S 151
[Link](mouseCommand};
, , ,
. ,
.
,
setup (} . loop ()
.
.
readJoystick () .
1024, .
[Link](} .
, - . ,
. , readJoystick (} 1023
-1 1 .
,
. ,
512. ,
.
[Link](), .
[Link] () .
readutton() .
ouse. isPressed (}
Mouse. press(} [Link]().
[Link]
:
+ 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
[Link]
, . ,
[Link]/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 //.
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
_L _L
_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
_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).
void setup(}
{
// (OUTPUT}
pinode(SER, OUTPUT};
pinode(LATCH, OUTPUT};
pinode(CLK, OUTPUT};
7. 159
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).
2. 7, 5, 3, 1 [()'. ,
, 27, 25 , 23 i.
170. , ,
7.1.
shiftout() :
shiftOut(DATA, CLOCK, MSBFIRST, 170);
, , .
7. 161
7 .4.
.
.
" " "".
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()
, .
,
.
lightrider
[Link]
Wiley.
7 .4.2.
- ,
, , .
.
-
. 7.7.
7. 163
,
(. 7.8).
3 , -
1 ( 500,
).
.
.
8. 7.3
.
//
const int SER=8; // DATA
const int LATCH =9; // LATCH
164 11.
//
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()
00000000
0000000 1
000000 3
00000 7
0000 15
0000 31
0000 63
127
255
. 7.8.
7. 165
Arduino,
- . ,
. ,
maxVal minVal,
. ,
,
setup() [Link](DIST)
analogRead(DIST).
,
, [Link]
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;
+ ;
+ .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
, -,
? Arduino
,
.
,
. I2 c.
170 111.
I2C
-. I2c
( )
, .
I2C ,
, ,
. , ,
.
,
, [Link]
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
: [Link]
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
Peck&lge: -220-5
. 8.2. 74.
2
1
, I2 c
. ID,
.
, , AD7414 AD7415 (AS),
I2C. AD7414
(. 8.3).
AD7414 , AS
. , AS,
: , m .
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)"
.-. .
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.
. 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()
//
[Link](9600);
// Wire
[Link]();
void loop()
//
//
[Link](temp_address);
// asking
[Link](O);
// -
[Link]();
//
// 1
[Link](temp_address, 1);
//
while([Link]() == );
//
int = [Link]();
//
int f = round(c*9.0/5.0 +32.0);
178 111.
//
//
[Link](c);
[Link]("C ");
[Link](f);
[Link]("F");
delay(SOO);
. Wire. beginTransrnission()
, ( )
. [Link]() "", ,
. -,
[Link](), .
12. Wire. requestFrom () -
12 -.
[Link]() ,
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 .
-,
:
[Link](c);
[Link]("C,");
[Link](f);
[Link]("F.");
Processing
. ,
, .
-,
(. 7) map(),
. 7.3,
.
. , , (
).
, .
24 31 (75-88 F), .
8.2 .
// 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()
//
[Link](9600);
// Wire
[Link]();
2
8. 1 181
// (OUTPUT)
pinode(SER, OUTPUT);
pinode(LATCH, OUTPUT};
pinode(CLK, OUTPUT};
void loop()
//
//
[Link](temp_address};
// asking
[Link](O};
!/ -
[Link](};
//
// 1
[Link](temp_address, 1};
//
while([Link]() == );
//
int = [Link]();
//
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);
//
//
[Link](c);
[Link]("C,"};
[Link](f);
[Link]("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 [Link].*;
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);
[Link]('.');
// ,
font = loadFont("[Link]");
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);
data = [Link]('.');
data = [Link](O, [Link]() - l);
// -
index = [Link](",");
184 111.
//
temp_c = [Link](O, index);
//
temp_f = [Link](index+l, [Link]());
Processing,
serial . setup()
,
.
draw()
. fill()
Processing ( RGB) ,
. seria!Event()
bufferuntil(), ,
, .
, .
. 8.1 .
. 8.10. Processing
rssing-,
.
http:/[Link]/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;
+ ;
+ .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
, Arduino:
I2 c UART.
, Arduino, -
( SPI).
I2 c, SPI
, .
9. SPI 187
,
. SI-, I c,
2
. Arduino IDE
SPI Arduino r1
.
, ,
.
,
[Link]
spl-lnterfaces1. Wiley.
9.1. SPI
SPI, "",
,
()
. SPI
, SPI
(,
).
SPI, Arduino IDE.
!
SPI ,
, .
SPI. SI-
,
(SCLK).
, (
), SCLK
( ).
, SPI
(. 9.1).
SI
1 ModeO LOW
2 Mode 1 LOW
I
: [Link]
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
.__
. 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 [Link]/
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 .
,
.
-
(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 [Link]/
content/ch9. Wiley.
, ,
.
196 111.
// ,
//
// SPI
#iclude <SPI.h>
// SPI
//
// 11 = MOSI, 12 = MISO, 13 = CLK
// SS
pinode(SSl, OUTPUT);
pinode(SS2, OUTPUT);
// SPI
[Link]();
//
// Chip 1 (SS 10) -
// Chip 1 (SS 10) 1 -
// Chip 2 (SS 9) -
// Chip 2 (SS 9) 1 -
digitalWrite(SS, LOW); // SS ()
[Link](reg); //
[Link](level); // (0-128)
digitalWrite(SS, HIGH); // SS
void loop()
delay(300);
for (int i=128; i>=O; i--)
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.
delay(OO);
for (int i=128; i>=O; i--)
delay(OO);
freq = freq+lOO;
if (freq > 2000) freq = 100;
Arduino ,
, .
l 00 , 2000 .
, .
. ,
. :
+ (
,
);
+ ,
;
+ , ;
+ .
, Sl-
, http:// [Link]/
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
void setup()
// SS
pinode(SSl, OUTPUT);
pinode(SS2, OUTPUT);
// SPI
[Link]();
//
// Chip 1 (SS 10) -
// Chip 1 (SS 10) 1 -
// Chip 2 (SS 9) -
// Chip 2 (SS 9) 1 -
digitalWrite(SS, LOW); // SS ()
[Link](reg); //
[Link](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 ;
;
.
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
10. 203
,
. ,
, , .
(LCD) Arduino,
( , ,
. .)
.
, LCD Arduino,
Arduino LiquidCrystal
. , ,
, ,
, .
- ,
,
.
http:l/[Link]/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
: [Link]
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:
[Link]
10.3.
,
. , ,
.
LiquidCrystal:
#include <LiquidCrystal.h>
LiquidCrystal:
LiquidCrystal lcd (2,,4,5,6,7);
Arduino,
- : RS, EN, D4, DS, D,
D7. -, setup ()
begin (), -
-:
[Link] (16, 2);
10. 207
print() setcursor()
. ,
, :
[Link] (0,1);
[Link] ("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()
{
// - :
[Link](l, 2);
//
[Link]("Jeremy's Display");
void loop()
//
[Link](O,l);
208 111.
/!
[Link](time);
// 1
delay(lOOO);
//
time++;
.
LiquidCrystal. time
. LiquidCrystal
lcd , .
[Link] (16, 2) : 16 2 .
, setup()
[Link] (). ,
, ,
(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:
[Link] (0, 20);
[Link] ((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 ()
// - :
[Link](l, 2);
// -
[Link]("Jeremy's Display");
//
[Link](O, 20);
1. 211
[Link](l, 40);
[Link](2, );
[Link](, 80);
[Link](4, plOO);
void loop()
//
[Link](0,1);
//
// 16
[Link](" ");
//
for (int i = ; i<l; i++)
// (20 - plOO)
for (int j=O; j<5; j++)
{
[Link](i, 1); //
[Link](j); //
delay(lOO); //
16
( ). for() 16 .
for()
-.
, - -
, [Link]
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).
//
[Link](O, degree);
[Link](l, fan_off);
[Link](2, fan_on);
// -
[Link](O,O);
[Link]("Current:");
[Link](lO,O);
[Link]((byte) );
[Link](ll,O);
[Link]("C");
[Link](0,1);
[Link]("Set:");
[Link](l0,1);
[Link]((byte) );
[Link](ll,1);
[Link]("C");
[Link](15,1);
[Link](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 -
[Link](B,l);
[Link](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);
[Link](l5,l);
[Link](2);
//
else
!/
// one time false
!/ -n
noTone(SPEAER);
one time = false;
digitalWrite(FAN, LOW);
[Link](15,1);
[Link](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 - )
[Link]();
// ( )
[Link](l, 2);
//
[Link](O, degree);
[Link](l, fan_off);
[Link](2, fan_on);
//
[Link](0,0);
[Link]("Current:");
[Link](lO,O);
[Link]((byte)0);
[Link](ll,O);
[Link]("C");
[Link](O,l);
[Link]("Set:");
[Link](lO,l);
[Link]((byte) );
[Link](ll,l);
[Link]("C");
[Link](lS,l);
[Link]);
//
boolean debounce(boolean last, int pin)
return current;
void loop()
//
[Link](TEMP_ADDR);
[Link](0);
[Link]();
[Link](TEMP_ADDR, 1);
220 111.
//
// 1
while([Link]() );
int = [Link]();
//
//
[Link](B,0);
[Link](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++;
//
[Link](B,1);
[Link](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);
[Link](15,1);
[Link](2);
10. 221
// !
else
//
// one time false
// -
noTone(SPEAER);
one time = false;
digitalWrite(FAN, LOW);
[Link](lS,l);
[Link](l);
, , Arduino
.
.
, ,
[Link]
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 .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
!
.
11. 223
, Arduino
, Digi.
,
, .
,
, .
Arduino
Arduino. .
[Link]
[Link]/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://[Link]/: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
-
--------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
=
--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.
-,
.
.
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).
( )
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
[Link]
:
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
. 11.8. X-CTU
. 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)[Link]
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 [Link]
1 /J,1-Et1dDeviceAttooat!cm
11 () .2 - Coordir1e,1or Asociatn
11 () 1 -[Link] [Link]
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
. 11.11.
. 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()
[Link](9600); //
void loop()
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 [Link].*;
Serial port;
float brightness = ; //
void setup()
{
size(500,500); //
port = new Serial(this, "", 9600); //
//
11. 239
[Link]('\n'); //
void draw()
{
background(O,O,brightness); //
brightness = float([Link]('\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()
{
[Link](9600); //
// 9600
// OUT
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);
void loop()
//
while ([Link]() > )
{
rval [Link](); //
gval [Link](); //
bval [Link](); //
if ([Link]() -- '\n') //
// R,G,B
analogWrite(RED, rval);
analogWrite(GREEN, gval);
analogWrite(BLUE, bval);
, 6 (. 11.18). Arduino
.
, USB Explorer
Processing ( 11.4). , [Link]
data .
.
void setup()
{
size(640,256);
img = loadlmage("[Link]"); //
port = new Serial(this, "9", 9600); //
242 111.
void draw()
background(O); //
image(irng,0,0); //
void rnousePressed()
6. .
Arduino,
.
.
,
.
Arduino .
11.4.
Arduino
. Arduino ,
. Arduino,
, , .
Arduino, ,
. - , Arduino
, , .
, , ,
,
[Link]
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
[Link](9600);
void loop()
[Link](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.
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 ([Link]() > )
//
data = [Link]();
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.
, ,
[Link]
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 .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
.
, , delay ()
Arduino .
1 , millis (),
254 IV.
Arduino delay ( J.
, .
,
( , . .).
, ,
Arduino, ,
. ,
.
, .
[Link]
1
hardware-debouncing .
Wiley.
12.1.
( )
-. , ,
, .
.
, .
, ,
. ,
:{
!
1
2
1
+
3
!
4
!
5
. 12.1.
I
: htt://[Link]/: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
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.
. , ""
,
.
, .
.. 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
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()
analogWrite(selectedLED, i);
delay(lO);
Arduino,
(R, G ) RG- .
,
.
, Arduino
, [Link]
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
, [Link]
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);
[Link](lOOOOOO); // I 1000000
// (1 )
[Link](inky); // rn ink()
void loop()
//
//
void inky()
{
digitalWrite(LED, !digitalRead(LED)); //
[Link]()
. 1 (1000000 ).
[Link] () - ,
. ,
, .
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()
//
[Link](9600);
pinode (SPEAER, OUTPUT);
// RISING
attachinterrupt(BUTTON_INT, changeKey, RISING);
//Set up timer interrupt
[Link](500000); // 0,5
268 IV.
[Link](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()
[Link](": ");
[Link](key);
[Link](" Multiplier: ");
[Link](octave_multiplier);
[Link](" Frequency: ");
[Link](key*octave_multiplier);
delay(lOO);
.
. , key octave_
multiplier volatile,
. changeKey()
-
12. 269
:
+ : F
.
+ Arduino .
Due ,
.
+
R- .
+
Arduino.
+ imerOne
.
+ ,
, .
,.
1
" SDJ
:
+ Arduino ( Uno);
+ US- Arduino;
+ Arduino ( );
+ ;
+ ;
+ SD card shield;
+ SD;
+ ;
+ ;
+ .
[Link]
, . ,
[Link]/go/exploringarduino
Downloads.
Arduino
, ,
. . ,
, Arduino
(
).
, SD-. , Arduino SD-.
13. SD 271
,
SD-.
. ,
.
[Link]
datalogging/ 1 .
GS-
[Link]
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://[Link]/:11-sd----.
272 IV.
, .
,
. , , ,
. Excel
, , . 13.1.
13.1. SV- /
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
( 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.
Ntt1-.,I;
/IPotNIX
. 13.2. SD-
. 13.3.
13. SD 275
. 13.4.
3. SD-,
umount. SD- (. 13.5).
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.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 ([Link]
cooking-hacks-SD-shield) (. 13. 7)
. ,
(8-13 Uno), 6-
ICSP Arduino. 8-13 CS
1 . ICSP CS
Arduino. , 1
Arduino . SD- 2 .
; CS Ethemet 1 Arduino,
CS SD- - 4.
+ Official Arduino Wi-Fi SD shield ([Link]
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 ([Link] adafruit
data-logging-shield) (. 13. l l) ,
,
(RTC) SD-. CS SD-
(53 Mega, 10-
Arduino), 12 .
SparkFun MicroSD shield ([Link]
parts/spark-fun-microSD-shield) (. 13.12) SD-.
,
. CS SD- 8,
SD .
13.2.3. SD-
SD SD-.
. -
13. SD 281
[Link], .
, F16
"8.3", . . ,
- .
, SD Arduino
SD-. Cooking Hacks Micro SD shield ,
. 13.13 ( 8-13 Arduino
).
SD. , SD-
( 13 .1 ):
.r 13.1. SD"
if ()
{
[Link]("Card Failure");
return;
[Link]("Card Ready");
282 IV.
,
[Link](CS_pin), .
,
.
. ,
"hello" , , 13.2.
else
( ,
) [Link]. / ,
dataFile true, .
.
dataFile. println() ;
, dataFile. print().
[Link]().
, SD- [Link]
5 -
( 13.3). CSV (
millis()) .
, ,
, .
// CS
const int CS_PIN = 10;
// SD-
const int POW PIN =8;
void setup()
{
[Link](9600);
[Link]("Initializing Card");
// CS
pinode(CS_PIN, OUTPUT);
// 8, HIGH
pinode(POW_PIN, OUTPUT);
digitalWrite(POW_PIN, HIGH);
if ()
{
[Link]("Card Failure");
return;
[Link]("Card Ready");
void loop()
//
[Link](timeStamp);
[Link](",");
[Link](dataString);
else
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-
[Link]. .
. 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
[Link] .PJace-:.
,.: Libro,in
: Oocmt.1its
.4'.\i..
J Gott O,Ne
J! Mu;i<
]Pictu,e,
II v,...,
;4Hom09roup
<\INotv.,,
!. !
. 13.16.
286 IV.
, ,
.
[Link](),
FILE _WRITE. File
( , serial), ,
parseint(). 13.4.
else
13.4
. ,
. .
13.3 13.4 ,
[Link], 13.5.
void setup()
{
[Link](9600);
[Link]("Initializing Card");
// CS
pinode(CS_PIN, OUTPUT);
// 8, HIGH
pinode(POW_PIN, OUTPUT);
digitalWrite(POW_PIN, HIGH);
if ( )
{
[Link]("Card Failure");
return;
[Link]("Card Ready");
!! ([Link])
File comandFile = [Link]("[Link]");
if (comrnandFile)
{
[Link]("Reading Comrnand File");
while([Link]())
{
refresh_rate = [Link]();
else
void loop()
//
[Link](timeStarnp);
[Link](",");
[Link](dataString);
else
delay(refresh_rate);
, .
(. 13 .17).
13.3.
. (R)
, ,
. millis(),
, Arduino. -
13. SD 289
,
SD-.
13.3.1.
.
, ,
.
DS1307.
DS1307
DS1307 Arduino I2 c
,
. ,
. adafruit-DS1307-breakout
([Link]
DS1307, , ,
1 2 .
Arduino (. 13.18).
, . ,
Arduino. 32,768 ,
2,2 3,0 .
,
, . 13.19.
290 IV.
. 13.19. ,
Arduino RTClib
,
Arduino.
(RTC). RTClib,
JeeLabs, Adafruit Indusrtries.
- [Link]
libraries, 12.
.
[Link] () .
RTC
RTC. now () .
.
13.3.2.
SD- ,
. ,
,
millis ().
13. SD 291
. 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, .
!
,
, .
- , ,
[Link]()
[Link]() . ,
,
Arduino. F(),
[Link] (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()
{
[Link](9600);
[Link](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
[Link]();
[Link]();
// RTC , /
if ( ! [Link]())
{
[Link](F("RTC is N running ! "));
[Link](DateTime( DATE, TIME ));
}
// SD-
if ( )
[Link](F("Card Failure"));
return;
[Link](F("Card Ready"));
// ',' ([Link])
File conandFile = [Link]("[Link]");
if (commandFile)
{
[Link](F("Reading Command File"));
while([Link]())
{
refresh_rate = [Link]();
else
//
F'ile dataFile = [Link]("[Link]", FILE_WRITE);
if (dataFile)
{
[Link](F("\nNew Log Started !"));
294 /V.
[Link](F("Date,Time,Phrase"));
[Link]();
//
[Link](F("\nNew Log Started!"));
[Link](F("Date,Time,Phrase"));
else
void loop()
//
DateTime datetime = [Link]();
year = String([Link](), DEC);
month = String([Link](), DEC);
day = String([Link](), DEC);
hour = String([Link](), DEC);
minute = String([Link](), DEC);
second = String([Link](), DEC);
//
date = year + "/" + month + "/" + day;
time = hour + ":" + minute + ":" + second;
String dataString = "Hello There!";
//
File dataFile = [Link]("[Link]", FILE_WRITE);
if (dataFile)
{
[Link](date);
[Link](F(","));
[Link](time);
[Link](F(","));
[Link](dataString);
[Link]();
//
[Link](date);
[Link](F(","));
[Link](time);
[Link](F(","));
[Link](dataString);
else
delay(refresh_rate);
13. SD 295
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()
{
[Link](9600);
[Link](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
[Link]();
[Link]();
// RTC , /
if (! [Link]())
{
[Link](F("RTC is NOT running!"));
[Link](DateTime( DATE, TIME ));
}
// SD
if ()
[Link](F("Card Failure"));
return;
13. SD 299
[Link](F("Card Ready"));
//
File dataFile = [Link]("[Link]", FILE_WRITE);
if (dataFile)
else
void loop()
!/
DateTirne datetirne = [Link]();
year = String([Link](), DEC);
rnonth = String([Link](), DEC);
day = String([Link](), DEC);
hour = String([Link](), DEC);
rninute = String([Link](), DEC);
second = String([Link](), 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)
[Link](F(","));
[Link](time);
[Link](F(","));
[Link](raw);
[Link](F(","));
[Link](active);
[Link]();
//
[Link](date);
[Link](F(","));
[Link](time);
[Link](F(","));
[Link](raw);
[Link](F(","));
[Link](active);
else
update_time = ;
delay(50);
update_time++;
13.4.3.
Arduino
.
, SD- - CSV
. ,
, .
, . -
, ,
, .
. -,
. ,
Google. - [Link]
.
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;
+ ;
+ ;
+ .
[Link]
, . ,
[Link]/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, [Link].
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-. [Link] 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 .
,
, ,
. , ,
, .
, -
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. , [Link].
, , -,
<body> <header>.
. L- 14. l.
14. Arduino 307
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
// [Link]
#include <Ethernet.h>
#include <SPI.h>
const int BLUE =5;
const int GREEN =;
310 IV.
// r! RG-
// ,
//
int freq = ;
int pin;
// -
//
//
byte mac[] = { 90, 2, OxDA, , 4, };
// 80
EthernetServer server = EthernetServer(80); // 80
boolean receiving = false; // GET
void setup()
{
[Link](9600);
pinode(RED, OUTPUT);
pinode(GREEN, OUTPUT);
pinode(BLUE, OUTPUT);
// DHCP
if ()
{
[Link]("Could not Configure Ethernet with DHCP.");
return;
else
[Link]("Ethernet Configured!");
//
[Link]();
[Link]("Server Started.\nLocal IP: ");
[Link]([Link]());
void loop()
while ([Link]())
if ([Link]())
{
char = [Link](); //
if(receiving && == ' ') receiving = false; //
//
if(c == '?') receiving = true; // ?
// GET
if(receiving)
// ( L)
if ( == 'L')
// ( S)
else if ( == 'S')
//
//
//
if( !sentHeader)
{
//
[Link]("HTTP/1.l 200 ");
[Link]( "Content-Type: text/html \n");
// RGB
[Link]("<fon action='' method='get'>");
[Link]("<input type='hidden' name='L' value='7' />");
[Link]("<input type='sumit' value='Toggle Red' />");
[Link]("</form>");
312 IV.
// RGB
[Link]("<form action='' method='get'>");
[Link]("<input type='hidden' name='L' value='' />");
[Link]("<input type='sumit' value='Toggle Green' />");
[Link]("</form>");
// RGB
[Link]("<form action='' method='get'>");
[Link]("<input type='hidden' name='L' value='5' />");
[Link]("<input type='sumit' value='Toggle Blue' />");
[Link]("</form>");
//
[Link]("<form action='' method='get'>");
[Link]("<input type='range' name='S' min='O' max='lOOO'"
"step='lOO' value='O'/>");
[Link]("<input type='sumit' value='Set Freq.' />");
[Link]("</form>");
//
//
sentHeader = true;
currentLineisBlank true;
else if ( ! = '\r')
currentLineisBlank false;
delay(5); // -
[Link](); //
,
. - , Ethemet
aamepa. , 14.2.
Arduino .
, Arduino
DHCP.
I- (. 14.4).
, . 14.4, Arduino I-
[Link]. . 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
:!'[Link] 1n 5
Togg11n1J P.1n 5
Toggl1ng P1n S
Toggl111\'I Fl.n 6
. 14.5. Arduino -
, Arduino ,
http:l/[Link]/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 [Link], ,
( ), [Link].
, .
(
). ,
, .
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) . , ,
[Link]
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- -.
- (, [Link]),
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
, [Link]
. , ,
.
, Develop
, . Add Device. (. 14.6)
.
.
Add Device.
. , . .
Arduino.
318 IV.
. 14.6. Xively
Xively HTTPClient
Xively Arduino ,
. Xively HttpClient ,
GitHub. : https://
[Link]/xively/xively-Arduino [Link]
Download ZIP .
- [Link]
, :
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 .
Xively
.
, Arduino.
Xively. : -
Ethemet, Xively API key Feed ID. - ,
. xively API key Feed ID Xively
API Keys (. 14.8).
+ Adcfiey
. 14.8. Xiveli API key Feed ID
#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()
//
[Link](9600);
[Link]("Starting single datastrearn upload to Xively...");
[Link]();
while ([Link](rnac) != 1)
{
[Link]("Error getting IP address via DHCP, trying again...");
delay(15000);
void loop()
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
L ej, R ::
tl'P"1Qa\[Link] !"t,::-;--
to XJ,;,r-e)y -- -
s1lyc1ient ,p'l:t [Link] lOti
.. -- . -
1242622121
"
41d. 17en.:Q:t v,1uo 619'.
O'[Link]' 1t: t XiVt!:l;i
x:i..[Link] :.'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()
//
[Link](9600);
[Link]("Starting doue datastream upload to Xively...");
[Link]();
while ([Link](mac) != 1)
{
[Link]("Error getting IP address via DHCP, trying again...");
delay(15000);
void loop()
, , () 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
; U'r le,ed
<'
AtUplt1:ad.111.g 1t to [Link]
[!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,
[Link]
. (. .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 [Link] 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 [Link]
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
,
, .
, , DF-,
.
-, ,
. 13-1
1/0-Ports , . .2.
, ,
Arduino. ,
- ,
.
Cpin, .
P,nt------------------- Logic
See Figure
"General Oigi!al 1/0" for
Detai!s
L------
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)
'"
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)
+ AREF - (< 5 );
+ GND - .
- - .
Arduino, .
.
, PDO PD 1
Rx . 6 7
. Arduino Uno
16
-.
,
, . Arduino
[Link]
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
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
[Link]() 282
[Link]() 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
[Link]() 195
[Link]() 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
[Link]() 290 volatile 262
[Link]() 290
s w
[Link]() 178
SCL 170 [Link]() 178
[Link]() 282
[Link]() 286
SDA 170
SD- 272 224
[Link]() 129 X-CTU 230
[Link]() 124
[Link]() 134
[Link]() 124 z
[Link]() 67,124 ZigBee 224
[Link]() 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