You are on page 1of 198

XT 1

ArduinoPOP-BOT XT

Arduino compatible robot kit activity manual

XT
2

XT

... .. 2537

1.

2.

3.
--


108 . 101/2 . 10260
0-2747-7001-4
0-2747-7005

XT 3

XT

POP-BOT XT

Arduino
C/C++

Programmable Mobile Robot

1. POP-XT


2.

-
3.

C/C++ Arduino POP-BOT


XT

C Arduino POP-XT

-,
POP-BOT XT robot kit POP-BOT XT Lite robot kit

Arduino

C/C++

XT
4

XT 5

...........................................................7

POP-BOT XT

POP-BOT XT..............................................................................19
3 Arduino 1.0..................................................................................27
4 Arduino..................................................................................47
5

POP-BOT XT Arduino 1.0.....................75


6 POP-XT
POP-BOT XT.............................................................................................................. 83
7

POP-BOT XT..........................101
8

POP-BOT XT................................................................................131
9

POP-BOT XT ....................................145
10

POP-BOT XT ....................................................153
11

POP-BOT XT ...................................175
12

POP-BOT XT ................................................183

XT
6

XT 7

XT

POP-BOT XT

2

1. POP-BOT X T Lite kit
ATmega32U4 LCD ,
(sensor) , DC motor gearbox

POP-BOT XT Lite
C/
C++
2. POP-BOT XT Standard kit POP-BOT XT Lite
, 2 ( 4 ),
,
POP-BOT XT

1.1

POP-BOT XT
1. POP-XT AA 4
2. 2
3. LED 2
4. ZX-03 2 ( Lite) 4 (
Standard)
5. BO2 48:1 IDC 2
6. 2
7. 80x60 80x80 2
8. 1
9. / *
10. *
11.
12.

13. USB-miniB
14.

XT
8

15. C ()
16. GP2D120**
17. **
*
POP-BOT XT Standard kit
** POP-BOT XT Standard kit

1.2
1.2.1 POP-XT
POP-XT AVR
ATmega32U4 Atmel (www.atmel.com) USB

POP-XT

( : open source) Arduino (www.arduino.cc/en) Arduino Leonardo
Arduino1.0 Arduino1.0



POPXT


POP-XT 1-1
8 ATmega32U4 Atmel
10 12 32
10,000 1024 2.5 2560
16MHz
25 JST 3 12


RESET
USB

(DC INPUT)
4.8
7.2V -

+5V



8 A0 A7 ( Di18 Di23,
Di4 Di6)

XT 9

1-1 POP-XT
I2C 1 Di2 (SDA) Di3 (SCL)
UART 1 Di0 (RxD) Di1 (TxD)
2
3 Di30, Di12 Di13
( SV1, SV2 SV3)
Di11
ISP
ISP (
PX-400 PX-4000 inex)
128 x 160
() (5x7 ) 21 16
(21x16)
( OK) 1
(KNOB)
8
POP-XT 1-2

XT
10

PF1
A4 22

PF5
A2 20

+Vm

PF7
A0 18

SWITCH
ON

+5V

K3
BATT
4.8-7.2V
3

PF0
A5 23

PF4
A3 21

PF6
A1 19

L1
10 H
1

C6
100F
10V

C5
0.1F

44 43 42 41 40 39 38 37 36 35 34
1
33
32
2
31
3
4

UGnd
5
UCap

VBus
PB0

C1
1F

IC1
ATMega32U4
(TQFP44)

6
7

8
17
PB1 9
15
PB2 10
16
PB3
11
14

30
29
28
27
26

Pxx

C12
0.1F

4
G

GND
RST
+

R5
4k7

R6
4k7

0
1
4

23
22
21

30
12
6

20
19
18

PB4

+Vm
SW2
RESET

RST

11

+Vm
PWMA
AIN2
AIN1
Vcc
STB
GND
BIN1
BIN2
PWMB
+Vm
+Vm

A8

R3
4k7
ISP

CR1
16MHz

+Vm

24 23 22 21 20 19 18 17 16 15 14 13

IC2
TB6612FNG

+5V

SP1
PIEZO
Speaker

+Vm

A1
A1
PG
PG
A2
A2
B2
B2
PG
PG
B1
B1

1 2 3 4 5 6 7 8 9 10 11 12
GND
+Vm

PC6
3

SCL
PD0

RXD
PD2

A7
PD7

ADIR

R8
1k

R7
1k

PE6
7

APWM 9

TXD
PD3

-+
SDA
PD1

+3.3V
IC5
LM1117-3.3V

C14
10F
16V

25-character
16-line

C16
10F
16V

C15
0.1F

R11
4.7k
PB0
R13
4.7k

31

SV1

30

DC. MOTOR
OUTPUT

A6
PD4

GLCD
160x128 pixel

16

SV2

12

GND
+Vm

+5V

R12
4.7k

PB1

R15
4.7k

R14
4.7k

+5V
R11
1k

1 2 3 4 5 6 7 8 9 10 11 12 13 14

PB2

R17
4.7k

N/C
GND
CS
Vcc
Vcc
CLK
MISO
D/C
/RST
GND
LEDA
LEDK
GND
N/C

15

GND
+Vm

PB6

-+

BDIR

10 BPWM

PB5

17

SV3

13

C3
10F
16V

R16
4.7k

+3.3V

VR1
KNOB

SW5
OK

PE2
+3.3V

R18
4.7k
+3.3V

R10
4.7k
RST
C17
0.1F

1-2 POP-XT

D1
1N4148

C18
0.1F

PB4

R9
4.7

SW3
RESET

R11
1k

PE2

+5V
C9
0.1F

C2
0.01 F

+
7
GND
REF

31
13
5

C8
0.1 F

Q2
KRC102

17
15
16
14
3
2

+5V

+5V
Q1
KRC102

GND

31

C13
220 F
10V

11
10
9

PB7
RST
Vcc
GND
XTAL2
XTAL1
PD0
PD1
PD2
PD3
PD5

25
24
23
12 13 14 15 16 17 18 19 20 21 22

PE2
PC7
PC6
PB6
PB5
PB4
PD7
PD6
PD4
AVcc
GND

1,2,3

SPI
Ext.

PE6
UVcc
DD+

R1 R2
27 27

VUSB
DD+
ID
GND

AVcc
GND
AREF
PF0
PF1
PF4
PF5
PF6
PF7
GND
Vcc

C4
+5V 0.1F

+USB

R4
4k7
LED1
BLUE

IC4
NCP1450
- 5.0

xx
C7
0.1F

5,6,7,8
C11
470 F
16V
Q3
FDS6680A

+5V

K1
mini B-USB
USB port

IC3
2
KIA278R05

C10
470 F
16V

+5V

+5V
D1
MBRS340

XT 11

1.2
1.2.1
BO-2 48:1 2

+3 +9Vdc

130mA (
+6V )

170 250 (
+6V )
30


0.5 -

( x x ) 42 x 45 x 22.7

1.2.2 : ZX-LED
LED 8 1 1-3

LED1
R1
(Default = 510)

1-3 ZX-LED

Q1
KRC102
(DTC114)

XT
12

1.2.3 ( POP-BOT XT Standard kit)


3 (S)
(+V) (G)

1-10

+4.8 +6Vdc
60 (
+5V )

45

3.40 - 47 -

( x x ) 40.5 x 20 x 38 1.60 x 0.79 x 1.50

1.3
1.3.1 : ZX-01
1-4 0

LED1

Indicator

+V

R2
10k
R1
510

R3
220

DATA

Signal output
S1
GND
Switch

1-4

POP-BOT XT

XT 13

+V
TCRT5000

OUT
GND

10k

510

POP-BOT XT
1-5

1.3.2 : ZX-03
1-5


TCRT5000


LED TCRT5000

ZX-03

POP-BOT XT

XT
14

1.3.3 GP2D120
( POP-BOT XT Standard kit)
GP2D120 3
(Vcc),
(GND) (Vout) GP2D120

32.7 52.9 ( 1 0.001 )
1-6
GP2D120 30
+5V 0.25 0.55V
0.4V

4 2.25V 0.3V
LED

GP2D120

(V)
2.8

GP2D12
GP2D120

2.4
Vout

GND

2.0

Vcc

1.6

(L)


L F

A X

FA
X

1.2
0.8
0.4
0

12

16

20

24

28

32

(cm)

L
A

LED

GP2D120

1-6 GP2D120

XT 15

POP-BOT XT
1.4
1.4.1 JST3AA-8 :
JST3AA-8 POP-XT
3 8

JST 3
2
2 .

2 .

GND
S
+5V

1.4.2 USB-miniB
USB POP-XT

XT
16

POP-BOT XT
1.5
1.5.1
65

1.5.2
ABS 80x60 80x80 1
3 5

1.5.3

ABS


3

XT 17


1.5.4

3 ,
3 30 (60 POPBOT XT Standard kit)

1.5.5

3


3 3, 5
12 4

1.5.6
RBX-168

XT
18

1.5.7

7.5 3
3 1x2 , 2x2 2x5 4

1.5.8

2 (2 ), 3x8
(4 ), 3x10 (30 ), 3x15 (4 ), 3x40 (4 ), 3x8
(10 ) 3 (30 )

1.5.9

,
32 3 4

1.6.10

, ABS
3
3 (4 ), 10 (4 ), 15 (4 ) 25 (4 )

XT 19

XT
POP-BOT X T AVR
ATmega32U4

LCD

POP-BOT XT

POP-BOT XT
Arduino Leonardo compatible robot

ATmega32U4

,
,

LCD
RC 3

AA 4

USB

XT
20

x 1

x 2

3 , 5 12

POP-XT x1

x 2

ZX-03 x 2

x 1

33 . x 4

x 2

2 . x 2

2x2 x 2

XT 21

(1) 3 x 8 .

3x8
(2) 32 . 3 x 8 .

32 .

32 .
(3) 2 .
2 .

XT
22

(4) 3 x 6 .

(5) ZX-03 3 x 15 . 5 2

(6) (5)
3x10 .

ZX-03

ZX-03

XT 23

(7) 5

3x10 .

3x10 . 3 .


(8)

3 .


3x10 .

XT
24

(9)

(10) POP-XT

XT 25

(11)



LED LED

LED

ZX-03 A1/19 ZX-03


(12)
A0/18 A5/23
A4/22
ZX-03 A1/19
ZX-03 A0/18

ZX-01 A5/23
ZX-01 A4/22

XT
26

(13)

POP-BOT XT

XT 27

Arduino1.0
POP-BOT XT Arduino1.0

XP ,

MAC OS Linux

Arduino
3.1
POP-BOT XT Arduino 1.0
POP-XT

POP-BOT XT
Arduino
Leomardo, POP-BOT XT popxt.h

( 7)
(3.1.1)

POP-BOT XT
Arduino1.0 POP-BOT XT Setup.exe Next
Next

XT
28

(3.1.2) Start Menu Next


Install

XT 29

(3.1.3)

USB
POP-XT

POP-BOT XT Next

(3.1.4)
Install this driver software anyway

XT
30

(3.1.5)

Arduino LLC Finish

(3.1.6) Arduino1.0 Start Menu


Start Menu Arduino

Arduino 1.0

XT 31

POP-BOT XT 7
3.2

POP-BOT XT

( 7 64 )
(3.2.1) POP-XT
AA 4
1800mAH
POP-XT

POP-BOT XT

(3.2.2)

POP-BOT XT
( 10 )

USB-miniB

USB USB

USB

XT
32

(3.2.3) POP-XT USB


My Computer Properties

(3.2.4) Control panel


Device Manager

(3.2.5) Ports Unicon@POP-XT (COMxx) COM

COM

POP-XT Arduino1.0

XT 33

(3.2.6) USB-miniB POP-XT


( 7 10 )

Click here for details



POP-XT Bootloader

Unicon Board & POP-XT (COMxx) Ready
to us COM Device Manager

(3.2.3)
(3.2.5)

XT
34

POP-BOT XT 7
3.3

3.2
7 64
3.2
(3.3.1) POP-BOT XT ( 10 )
USB-miniB USB

USB


7 10 USB

(3.3.2)

(3.3.4) My Computer > Properties


Device Manager

XT 35

(3.3.5) Device Manager Arduino Leonardo !


Update
Driver Software..

(3.3.6)
Browse my computer for driver software

XT
36

(3.3.7) C:\Arduino\Drivers
Next

(3.3.8)

Install this
driver software anyway

XT 37

(3.3.9)


Device Manager

Unicon Board & POP-XT (COMxx) COM


COM2

(3.3.10)

COM
(3.2.8) Arduino1.0 (

COM2)

POP-BOT X T

XT
38

POP-BOT XT XP
3.4

7
XP
(3.4.1) AA 4 POP-XT POP-XT
POP-BOT XT
(3.4.2)

POP-BOT XT
( 10 )

USB-miniB USB

USB USB

USB

100 F

ATMega32U4

220 F

100
TB6612

(3.4.3) USB
Install from a list or
specific location (Advanced)
Next

XT 39

(3.4.4) C:\Arduino\Drivers Next

(3.4.5) Finish

XT
40

(3.4.10) POP-XT
Control Panel > System
> Hardware > Device Manager

Ports Unicon Board & POP-XT (COM xx)


COM104

POP-XT
POP-BOT XT

XT 41

Arduino1.0 Macintosh
3.5
OSX 10.6

Arduino1.0 Macintosh

.ZIP

(3.5.1) Arduino1.0.zip www.inex.co.th


www.uniconboard.com Desktop
(3.5.2) Open With > Archive Utility
.zip

(3.5.3) Arduino

(3.5.4) Finder Arduino Applications

XT
42

(3.5.5) Arduino Tools Board POP-XT

(3.5.6) POP-XT


10
USB POP-XT USB Macintosh
(3.5.7) Tools Serial Port /dev/tty.usbmodemxxxx xxxx

POP-XT
POP-BOT XT

XT 43

3.6 Arduino1.0
3-1
(Menu)
(Toolbar)

(Tabs)
(

)
(Text editor)
C/C++

(Message area)

(Menu)

(Tools bar)
(Tab)


(Text Editor)

(Message area)

3-1 Arduino1.0

Serial Monitor

Arduino

XT
44

(Text area)

Serial Monitor


Arduino

Serial Monitor

Arduino

Serial.print Arduino
Send
(baud rate) Serial.begin Mcintosh

Linux Arduino Serial monitor

3.6.1
()

3.6.1.1 File
(Sketch)

Arduino
(Sketchbook)

--

New :
Open
Sketchbook :

Example :

Arduino1.0

XT 45

Save :
Save as :

Upload to I/O board : POP-XT POP-BOT XT
Arduino Leonardo
Page setup :

Print :

Preference :
Quit :

3.6.1.2 Edit



Undo :
Redo :
Cut :
Copy :
Paste :
Select All :
Comment/Uncomment : //
//
Find :
Find Next :

3.6.1.3 Sketch

Verify/Compile :
Stop :

Arduino
Add file :





Arduino IDE
Import Library :

#include
Show Sketch folder :

XT
46

3.6.1.4 Tools
,

Arduino,
POP-BOT XT
Auto Format :

Archive Sketch :



-510123.zip
Export Folder :

POP Board : Arduino POP-XT

POP-XT Unicon
BOT XT POP-XT Unicon Board

inex
Arduini Leomardo
Serial Port : Arduino
POP-XT Unicon Board

3.6.1.5 Help




( .html)



Arduino IDE

3.6.2 ( : Tools bar)


Arduino1.0


Verfy/Compile

Upload to I/O Board

Arduino

New ()
Open File Sketchbook ()
Save

XT 47

POP-XT POP-BOT XT
C/C++ Arduino (Arduino programming language) 1.0

Arduino
wiring Arduino 2
1. (structure)
2. (function)
Arduino C/C++ Arduino (
POP-MCU) Arduino

Arduino C
Arduino

C
Arduino
POP-BOT XT

4.1 Arduino
Arduino
void setup()

void loop()




setup()

loop()



loop()

XT
48

4.1.1 setup()



4-1
int buttonPin = 3;
void setup()
{
beginSerial(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite(H);
else
serialWrite(L);
delay(1000);
}

C
C AVR GCC ( C
GCC AVR)
int main(void)
{
init();
setup();
for (;;)
loop();
return ;

void

setup()

void

loop()

4.1.2 loop()
setup() loop()


4-2
int buttonPin = 3; // setup initializes serial and the button pin
void setup()
{
beginSerial(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pin each time and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite(H);
else
serialWrite(L);
delay(1000);
}

XT 49

4.2
4.2.1 if


if (someVariable > 50)
{
// do something here
}

someVariable 50


x == y (x y)
x != y (x y)
x < y (x y)
x > y (x y)
x <= y (x y)
x >= y (x y)

== ( if (x==10) ) = ( if(x=10)




x 10
)

if if....else

XT
50

4.2.2

if...else

if
500
500
4-3
if (pinFiveInput < 500)
{
// do Thing A
}
else
{
// do Thing B
}

else if
if....else...if
4-4
if (pinFiveInput < 500)
{
// do Thing A
}
else if (pinFiveInput >= 1000)
{
// do Thing B
}
else
{
// do Thing C
}

else if ( switch case


if...else...if )

if...else
else

XT 51

4.2.3

for()


for







for() 3
for (initialization; condition; increment){
//statement(s);
}


initialization
condition



increment

4-5
for (int i=1; i <= 8; i++){
// statement using the value i;
}

for

for
for


initialization, condition increment for

4.2.4

switch-case

var

default


break case
switch-case break

break
4-6
switch (var)
{
case 1:
//do something when var == 1
break;
case 2:
//do something when var == 2
break;
default:
// if nothing else matches, do the default
}

XT
52

4.2.5 while




while()

while() while

while(expression){
// statement(s)
}

expression

()

4-7
var = 0;
while(var < 200){
// do something repetitive 200 times
var++;
}

XT 53

4.3
5 + (),- (), * (), / () % ()

4.4.1

9/4 2

9 4 (int)
(overflow)


( 9/4 = 2 9/4.0 = 2.25)

result = value1 + value2;


result = value1 - value2;
result = value1 * value2;
result = value1 / value2;

value1 :
value2:
4-8
y = y + 3;
x = x - 7;
i = j * 6;
r = r / 5;



(0 1)
(0 -32768)
float

cast (int)myfloat

XT
54

4.4.2 %
2
(float)

result = value1 % value2;

- byte,char,int long
value2 - byte,char,int long


4-9
value1

x = 7 % 5;
x = 9 % 5;

// x now contains 2
// x now contains 4

x = 5 % 5;

// x now contains 0

x = 4 % 5;

// x now contains 4

(roll over)
4-10
// check a sensor every 10 times through a loop
void loop()
{
i++;
if ((i % 10) == 0)
{
x = analogRead(sensPin);
// read sensor every ten times through loop
}
/ ...
}
// setup a buffer that averages the last five samples of a sensor
int senVal[5];
// create an array for sensor data
// counter variables
int i, j;
long average;
// variable to store average
...
void loop()
{
// input sensor data into oldest memory slot
sensVal[(i++) % 5] = analogRead(sensPin);
average = 0;
for (j=0; j<5; j++)
{
average += sensVal[j]; // add samples
}
average = average / 5;
// divide by total

XT 55

4.4

if()

()
x == y (x y)
x != y (x y)
x < y (x y)
x > y (x y)
x <= y (x y)
x >= y (x y)

4.5
if() 3 &&, || !

4.5.1 && ( )

4-11
if (x > 0 && x < 5)
{
// ...
}

x 0 5 ( 1 4)

4.5.2 && ( )

4-12
if (x > 0 || y > 0)
{
// ...
}

x y 0

4.5.3 ! ()

4-13
if (!x)
{
// ...
}

x ( x = 0 )

XT
56

4.5.4
&&
&

|| () | (
)

NOT (~) (!)


4-14
if (a >= 10 && a <= 20){}
// true if a is between 10 and 20

4.6

( Arduino) 6 & (bitwise AND), | (OR), ^
(Exclusive OR), ~ (NOT), << (
) >> (
)

4.6.1 AND (&)


AND &

1
1 0

0
0

0
1

1
0

1
1

Operand1
Operand2

Returned result


AND
Arduino int 16
16
4-15
int a =

92;

// in binary: 0000000001011100

int b = 101;

// in binary: 0000000001100101

int c = a & b; // result:

0000000001000100 or 68 in decimal.

16 a b
16 c
01000100 68
AND ()
int

masking

XT 57

4.6.2 OR (|)
|


OR

1 1 0


0
0

Operand1

0 1 0 1

Operand2

Returned result

4-16
OR
int a =

92;

// in binary: 0000000001011100

int b = 101;
// in binary: 0000000001100101
int c = a | b; // result:
0000000001111101 or 125 in decimal.

4-17
AND OR
AND OR Read-Modify-Write
on a port 8 8

8 8
0,1,2,3,4,5,6,7 1
PORTD

HIGH ( pinMode()
) PORTD = B00110001; 2,3 7 HIGH

0 1

Arduino

PORTD ( AND)
( OR)
PORTD

XT
58
int i;

// counter variable

int j;
void setup()
{
DDRD = DDRD | B11111100;
// set direction bits for pins 2 to 7,
// leave 0 and 1 untouched (xx | 00 == xx)
// same as pinMode(pin,OUTPUT) for pins 2 to 7
Serial.begin(9600);
}
void loop()
{
for (i=0; i<64; i++)
{
PORTD = PORTD & B00000011;
// clear out bits 2 - 7, leave pins 0
// and 1 untouched (xx & 11 == xx)
j = (i << 2);
// shift variable up to pins 2 - 7 to avoid pins 0 and 1
PORTD = PORTD | j;
// combine the port information with the new information for LED pins
Serial.println(PORTD, BIN);
delay(100);

// debug to show masking

}
}

4.6.3 Exclusive OR (^)


C/C++ exclusive OR ( XOR)
^ OR
1
0
0

Operand1

Operand2

0 1 1 0

Returned result

XOR 0

4-18
int x = 12;
int y = 10;

// binary: 1100
// binary: 1010

int z = x ^ y;

// binary: 0110, or decimal 6

XT 59

XOR int 0 1
1 0
XOR mask 1 mask 1

5 (Di 5)
4-19
// Blink_Pin_5
// demo for Exclusive OR
void setup()
{
DDRD = DDRD | B00100000;
Serial.begin(9600);

// set digital pin five as OUTPUT

}
void loop()
{
PORTD = PORTD ^ B00100000;

// invert bit 5 (digital pin 5),


// leave others untouched

delay(100);
}

4.6.4 NOT (~)



NOT ~
0 1 1 0

1 0

Operand1
~ operand1

int a = 103;

// binary: 0000000001100111

int b = ~a;

// binary: 1111111110011000

b -104 ()

() int 1
(2s complement)
int
signed int

XT
60

(<<)
(>>)
4.6.5
C/C++
<<
>>


variable << number_of_bits


variable >> number_of_bits

variable

32 (

byte, int long)


4-20
int a = 5;

// binary: 0000000000000101

int b = a << 3;

// binary: 0000000000101000 or 40 in decimal

int c = b >> 3;

// binary: 0000000000000101 or back to 5

4-21
x y (x

<< y

)
x y

// binary: 0000000000000101
int a = 5;
int b = a << 14; // binary: 0100000000000000


1 <<

==

1 <<

==

1 <<
1 <<

2
3

==
==

4
8

...
1 <<

==

256

1 <<

==

512

1 << 10
...

== 1024

x y (x >> y)
x int sign bit
1

sign bit


sign eXTension
4-22
int x = -16;
int y = x >> 3;

// binary: 1111111111110000
// binary: 1111111111111110

XT 61

0 (

unsigned int)

(typecast)

x
unsigned int

int x = -16;
int y = unsigned(x) >> 3;

// binary: 1111111111110000
// binary: 0001111111111110

sign eXTension
2
int x = 1000;
int y = x >> 3;

// integer division of 1000 by 8, causing y = 125.

4.7 Arduino
4.7.1

( - semicolon)


4-23
int a = 13;

4.7.2 {

( - curly brace)

{ }
Arduino IDE


BASIC C
RETURN subroutine
(function) ENDIF NEXT FOR

Enter

XT
62

(Function)
void myfunction(datatype argument){
statements(s)
}

(Loops)
while (boolean expression)
{
statement(s)
}
do
{
statement(s)
} while (boolean expression);
for (initialisation; termination condition; incrementing expr)
{
statement(s)
}

(condition)
if (boolean expression)
{
statement(s)
}
else if (boolean expression)
{
statement(s)
}
else
{
statement(s)
}

4.7.3 // /*...*

2
(1) // 2
(2) / *
/* blabla */

XT 63

4.7.4 #define

Arduino #define

#define constantName value

#
4-24
#define ledPin 3

ledPin 3

#define

4.7.5 #include

#include <file>
#include file

4-25
#include <stdio.h>
#include popxt.h

stdio.h
Arduino Arduino
2 popxt.h

XT
64

4.8

Arduino

4.8.1 char :
1 (8 ) C
A (
ABC) ASCII
A +1 66

ASCII A 65

char sign = ;

char var = x;

char



x
var

4.8.2 byte : 8 1
byte 8 0 - 255
4-26
byte b = B10010;

// B is the binary formatter (18 decimal)

4.8.3 int :
interger

int

2 -32,768 32,767 (
-215 (215- 1)
(2s complement)
sign bit 1
Arduino

(>>)

int var = val;

var

int
val

XT 65

4-27
int ledPin = 13;

(roll over)

4-28
int
x =
x =
x =
x =

x
-32,768;
x - 1;
// x now contains 32,767 - rolls over in neg. direction
32,767;
x + 1; // x now contains -32,768 - rolls over

4.8.4 unsigned int :

int
2
0 65,535 (216 -1)

unsigned int var = val;

var

int
val

4-29
unsigned int ledPin = 13;



4-30
unsigned int x
x = 0;
x = x - 1;
// x now contains 65535 - rolls over in neg direction
x = x + 1; // x now contains 0 - rolls over

XT
66

4.8.5 long : 32

int long



32 (4 ) -2,147,483,648 2,147,483,647

long var = val;

long
var

val
4-31
long time;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print(Time: );
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send
// massive amounts of data
delay(1000);
}

4.8.6 unsigned long : 32




32 (4 ) 0

4,294,967,295 232 -1

unsigned long var = val;

var

unsigned long
val

4-32
long time;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print(Time: );
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send
// massive amounts of data
delay(1000);
}

XT 67

4.8.7 float :

int float 4.4028235 x 1038 -4.4028235 x


1038

32 (4 )
float int

float

floating point

float var = val;

float
var

val
4-33
float myfloat;
float sensorCalbrate = 1.117;

4-34
int x;
int y;
float z;
x = 1;
y = x / 2;

// y now contains 0, integers cant hold fractions

z = (float)x / 2.0;

// z now contains .5 (you have to use 2.0, not 2)

XT
68

4.8.8 double :
8
1.7976931348623157 x 10308
Arduino

4.8.9 string :

char

4-35
char Str1[15];
char Str2[8] = {a,r,d,u,i,n,o};
char Str3[8] = {a,r,d,u,i,n, o,\0'};
char Str4[ ] = arduino;
char Str5[8] = arduino;
char Str6[15] = arduino;

Str2
null character
Str3 null
string
Str4
+ 1 null string
Str5

Str6
Str1

4.8.9.1
(null termination)
C (null string)

\0 () + 1
Str2 Str3 4-35 Arduino 7
[8]


4-35 Str1 Str6 14

4.8.9.2

Abc (char)

XT 69

4.8.10 (array)

Arduino C

int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
int mySensVals[6] = {2, 4, -8, 3, 2};
char message[6] = hello;

myInts
myPins


mySensVals
char

4.8.10.1

0
mySensVals
mySensVals[0] == 2, mySensVals[1] == 4 ,

mySensVals[0] = 10;

x = mySensVals[4];

4.8.10.2 for
for for

int i;
for (i = 0; i < 5; i = i + 1) {
Serial.println(myPins[i]);
}

KnightRider
Tutorials www.arduino.cc

XT
70

4.9
Arduino (scope)

BASIC
global

4.9.1


(global variable)


4-36
int gPWMval;
void setup(){

// any function will see this variable


// ...

}
void loop(){
int i;
float f;
}

// i is only visible inside of loop


// f is only visible inside of loop

4.9.2 (static)


(keyword)


()

static

4.10 (constants)


Arduino

4.10.1 HIGH, LOW :


2 HIGH LOW
HIGH
+5V +3V
HIGH
HIGH 1 (TRUE)
LOW
0V +2V
LOW LOW 0 (FALSE)

XT 71

4.10.2 INPUT, OUTPUT :

2
INPUT
OUTPUT

POP-Note
Arduino
Arduino 123
(decimal)

10 (decimal)
123
2 (binary)
B1111011
8 (octal)
0173
16 (hexadecimal)
0x7B
Decimal
101 == 101 decimal ((1 * 2^2) + (0 * 2^1) + 1)
Binary 0 1
B101 == 5 decimal ((1 * 2^2) + (0 * 2^1) + 1)
8 ( 1 ) 0 (B0) 255 (B11111111)
16 ( int)
myInt = (B11001100 * 256) + B10101010; // B11001100 is the high byte

Octal 0 7
0101 == 65 decimal ((1 * 8^2) + (0 * 8^1) + 1)
0
8
Hexadecimal (hex) 0 9 A 10, B 11
F 15
0x101 == 257 decimal ((1 * 16^2) + (0 * 16^1) + 1)

XT
72

4.11

4.11.1 cast :


cast

(type)variable

( int, float, long)


Variable
4-37
Type

int i;
float f;
f = 4.6;
i = (int) f; // now i is 3

float int
(int)4.2 (int)4.7

4.11.2 sizeof :


sizeof(variable)
sizeof variable

Variable (int, float, long)


4-38
sizeof ()



char myStr[] = this is a test;
int i;
void setup(){
Serial.begin(9600);
}
void loop() {
for (i = 0; i < sizeof(myStr) - 1; i++){
Serial.print(i, DEC);
Serial.print( = );
Serial.println(myStr[i], BYTE);
}

XT 73

4.12 Arduino

C Arduino



# Constants

# Datatypes

HIGH
LOW
INPUT
OUTPUT
SERIAL
DISPLAY
PI
HALF_PI
TWO_PI
LSBFIRST
MSBFIRST
CHANGE
FALLING
RISING
false
true

boolean
byte
char
class
default
do
double
int
long
private
protected
public
return
short
signed
static
switch
throw
try
unsigned
void

null
# Port Constants
DDRB
PINB
PORTB
DDRC
PINC
PORTC
DDRD
PIND
PORTD

# Other
abs
acos
+=
+
[]
asin
=
atan
atan2
&
&=
|
|=
boolean
byte
case
ceil
char
char
class
,

//
?:
constrain
cos
{}

default
delay
delayMicroseconds
/
/**
.
else
==
exp
false
float
float
floor
for
<
<=
HALF_PI
if
++
!=
int
<<
<
<=
log
&&
!
||
^
^=
loop
max
millis
min
%
/*
*
new
null
()

PII
return
>>
;
Serial
Setup
sin
sq
sqrt
=
switch
tan
this
true
TWO_PI
void
while
Serial
begin
read
print
write
println
available
digitalWrite
digitalRead
pinMode
analogRead
analogWrite
attachInterrupts
detachInterrupts
beginSerial
serialWrite
serialRead
serialAvailable
printString
printInteger
printByte
printHex
printOctal
printBinary
printNewline
pulseIn
shiftOut

XT
74

XT 75

XT

POP-BOT XT
C

5.1

POP-BOT XT
5.1.1 POP-XT
LCD
5.1.2 2

5.1.3
5.1.4

5.2
C/C++ AVR
(open source)
Arduino1.0 C/C++


( Arduino )
Arduino

Arduino www.arduino.cc POP-BOT XT
Arduino1.0

5.3 C POP-BOT XT

POP-BOT XT 5-1

XT
76

- Arduino1.0 C/C++
,

- POP-XT
Unicon Arduino Leonardo

C Arduino IDE

USB

USB
1. USB-miniB USB
POP-BOT XT
2. USB Serial port (COMx)

3. Unicon Board
POP-XT POP-BOT XT
Unicon
Arduino Leonardo
4.

RESET
POP-BOT XT

5-1

POP-BOT XT C
Arduino1.0

XT 77

POP-BOT XT
5.4

POP-XT

POP
BOT XT
3


POP-BOT XT
Arduino1.0 Start > Arduino1.0 > Arduino
Arduino

XT
78

POP-BOT XT
5.4.1
Arduino

5.4.1.1
Tools Board POP-XT Unicon Board ()

5.4.1.2

Arduino POP-BOT XT

Tools Serial Port


POP-BOT XT (virtual COM port)
COM 2
COM104

XT 79

5.4.2
Arduino

(Sketchbook)
New
(1) File > New
#include <popxt.h>
void setup()
{
glcd(1,0,"Hello World");
}
void loop()
{
}

//Include POP-XT library

//Show message on GLCD

(2) HelloWorld.ino

(3) Sketch Verify/Compile

XT
80

(4)

Done compiling
Binary sketch size: 11006 bytes (of a 30720 byte maximum)
11,006
30,720

5.4.3

POP-BOT XT

POP-BOT XT Arduino C

POP-BOTXT (upload)


(download)

10
(1) POP-BOT XT
USB
USB

USB-miniB

F
0
2
2
F
0
0
1

0
0
1
AT Mega32U 4

TB6612

POP-BOT XT

XT 81

(2) POP-BOT XT

File > Upload

(3) RESET
HelloWorld Hello World 1 0
LCD POP-BOT XT

C Arduino POP


BOT XT
C
Arduino

XT
82

XT 83


XT

C/C++ Arduino1.0

5


POP-XT

POP-BOT XT


POP-XT 4
1 LCD ( 3 )
2
3 KNOB OK POP-XT
4


Arduino1.0
POP-XT POP-BOT XT

POP-XT

10
POP-BOT XT

POP-XT

RESET

XT
84

(A1.1.1) Arduino1.0 A1-1


(A1.1.2) POP-XT USB

USB

USB-miniB

F
0
2
2
F
0
0
1

0
0
1
AT Mega32U 4

TB6612

POP-BOT XT

(A1.1.3)


Tools > Board > POP-XT Unicon Board
(

XT 85

//
#include <popxt.h>
void setup()
{
glcd(1,0,"Hello World");
//
}
void loop()
{
}

Hello World

1 0
void setup()

A1-1 HelloWorld.ino POP-XT

POP-BOT XT Tools
(A1.1.4) POP-XT
> Serial Port ()

(A1.1.5) POP-XT

File > Upload

LCD POP-XT Hello World


Hello

100 F

World

ATMega32U4

220 F

100
TB6612

XT
86


POP-XT 128 x 160 5 x 7
21 16
glcd

popxt.h

glcd
A1-2
(A1.2.1) Arduino1.0 A1-2
#include <popxt.h>
int i,j;
void setup()
{
glcdFillScreen(GLCD_WHITE);
setTextColor(GLCD_BLACK);
setTextBackgroundColor(GLCD_WHITE);
for (i=0;i<16;i++)
{glcd(i,0," Row %d ",i);
}
}
void loop()
{}

//

//

//
//

// 16

//


3

1. glcdFillScreen

2. setTextColor
3. setTextBackground

Row

i
i

Row0

2 Row 1
1 15 ( 16)
Row 15 15

A1-2 MultipleTextline.ino POP-XT

XT 87

(A1.2.2) POP-XT USB


(A1.2.3) POP-XT

File > Upload

LCD POP-XT Row 0 Row 15

100 F

ATMega32U4

Row00
Row01
RRRow02
RRRRow03
RRRRRow04
RRRRRRow05
RRRRRRRow06
RRRRRRRRow07
RRRRRRRRRow08
RRRRRRRRRRow09
RRRRRRRRRRRow010
RRRRRRRRRRRRow011
RRRRRRRRRRRRRow012
RRRRRRRRRRRRRRow013
RRRRRRRRRRRRRRRow014
RRRRRRRRRRRRRRRRow015

100

220 F

TB6612

XT
88

POP-XT

6 x 10 ( 5 x 7 )
setTextSize
setTextSize(2) 2 12 x 20 1
setTextSize(3) 3 18 x 30 1
21 16
10 8

glcdMode()
0 (glcdMode(0)
3 1, 2 3
90
1 90 , 2 180
3 270
(A1.3.1) Arduino1.0 A1-3
#include <popxt.h>
int x,m;
void setup()
{
setTextColor(GLCD_RED);
}
void loop()
{
for (x=1;x<6;x++)
{
setTextSize(x);
for(m=0;m<4;m++)
{
glcdClear();
glcdMode(m);
glcd(0,0,%dX,x);
glcd(1,0,M=%d,m);
sleep(500);
}
}
}

//

//
//
//
//
//

A1-3 SetText_FlipDisplay.ino

POP-XT

XT 89

(A1.3.2) POP-XT USB


(A1.3.3) POP-XT

File > Upload

LCD POP-XT

, ,
1X, 2X, 3X , 4X 5X 4 M
M = 0
3

M = 1 90
4

M = 2 180

M = 0
4

M = 3 270
5

XT
90


LCD
glcd

glcdRect(int x1,int y1,int width,int height,uint color)


glcdFillRect(int x1,int y1,int width,int height,uint color)

glcdLine(int x1, int y1, int x2, int y2,uint color)


glcdCircle(int x, int y, int radius,uint color)

glcdFillCircle(int x, int y, int radius,uint color)


glcdClear(uint color)
A1-4

POPXT

XT 91

#include <popxt.h>
int i,j;
void setup()
{}
void loop()
{
glcdClear;
sleep(300);
for (i=0;i<160;i+=4)
{
glcdLine(0,0,128,i,GLCD_WHITE);
}
for (i=0;i<128;i+=4)
{
glcdLine(0,0,i,160,GLCD_RED);
}
sleep(2000);
glcdRect(32,40,64,80,GLCD_BLUE);
sleep(300);
glcdFillCircle(32,40,31,GLCD_GREEN);
glcdFillCircle(96,40,31,GLCD_YELLOW);
glcdFillCircle(32,120,31,GLCD_MAGENTA);
glcdFillCircle(96,120,31,GLCD_SKY);
sleep(1000);
glcdCircle(64,40,31,GLCD_GREEN);
glcdCircle(32,80,31,GLCD_BLUE);
glcdCircle(64,120,31,GLCD_YELLOW);
glcdCircle(96,80,31,GLCD_SKY);
sleep(1000);
glcdFillRect(0,0,128,160,GLCD_YELLOW);
sleep(1000);
}

//

//

// 0,0

// 0,0
//
//
//
//
//
//
//
//
//
//

A1-4 Simplegraphic.ino POP-XT

XT
92

POP-XT glcdArc()

7
popxt.h

(A1.5.1) Arduino1.0 A1-5


(A1.5.2) POP-XT USB
(A1.5.3) POP-XT

File > Upload

#include <popxt.h>
int i;
//

void face()
{
glcdFillCircle(64,70,50,GLCD_WHITE);
glcdArc(48,60,16,30,150,GLCD_RED);
glcdCircle(48,55,5,GLCD_BLUE);
glcdCircle(80,55,5,GLCD_BLUE);
glcdArc(80,60,16,30,150,GLCD_RED);
glcdFillCircle(64,70,7,GLCD_YELLOW);
glcdArc(64,80,30,220,320,GLCD_RED);
glcdArc(64,80,29,220,320,GLCD_RED);
}
void setup()
{}
void loop()
{
for(i=0;i<4;i++)
{
glcdClear();
glcdMode(i);
//

face();
sleep(1000);
}
}

A1-5 SmileFace_ArcTest.ino POP-XT

XT 93

(A1.5.4) POP-XT

1 90

XT
94


POP-XT

300 3,000Hz popxt.h


2 beep() sound()

A2-1 beep()
1
A2-2 sound()


Arduino1.0

A2-1 A2-2

POP-XT
RESET 10
POP-XT
#include <popxt.h>
void setup()
{}
void loop()
{
beep();
sleep(1000);
}

//

//

A2-1 BeepTest.ino POP-XT

XT 95

#include <popxt.h>
void setup()
{}
void loop()
{
sound(500,500);
sound(2500,500);
}

//

// 500Hz 0.5
// 2500Hz 0.5

A2-2 SoundTest.ino POP-XT

XT
96


POP-XT

KNOB OK

100 F

ATMega32U4

220 F

100
TB6612

A3-1 KnobSwitchTest.ino
POP-XT
POP-XT
Press OK ( 2x)
OK
1
Knob value ( 2x)

XXXX ( 3x)
xxxx
80 1023
KNOB POP-XT
Knob KNOB
OK
500Hz 0.5 POP-XT
OK

XT 97

#include <popxt.h>
void setup()
{
glcdClear;
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
beep();
glcdClear;
}
void loop()
{
if (sw_ok())
{
sound(500,500);
}
glcd(1,0,"Knob value");
setTextSize(3);
glcd(2,2,"%d ",knob());
setTextSize(2);
}

//
//
// 2
//
//

OK
//
//
// OK
// 500 Hz 0.5
//
// 3
// KNOB

// 2

A3-1 KnobSwitchTest.ino KNOB OK

XT
98


popxt.h out(int num,int _dat)
0 1
POP-XT POP-BOT XT
LED
ZX-LED LED
1 0 POP-XT
(A4.1) ZX-LED 1 6 /A7 2 4/A6

ZX-LED

(A4.2) A4-1 LEDTest.ino


(A4.3) POP-XT 10
USB
(A4.4) POP-XT POP-BOT XT
(A4.5) ZX-LED
POP-XT
Press OK

OK LED ZX-LED

XT 99

#include <popxt.h>
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
}
void loop()
{
out(4,1);
out(6,0);
sleep(400);
out(4,0);
out(6,1);
sleep(400);
}

//
// 2
// GLCD
// OK

// LED 4 (Di 4)
// LED 6 (Di 6)
// LED 4 (Di 4)
// LED 6 (Di 6)

A4-1 LEDTest.ino

XT 101

XT
C/C++ Arduino POP-BOT XT
popxt.h

POP-BOT
XT
popxt.h

XT
102

7.1 popxt.h
,
LCD POP-BOT XT ()
sleep
in_out

analog

sound
motor
servo
serial
USB
TxD RxD POP-XT

POP-BOT XT
popbot.h
glcd

#include <popxt.h>

popxt.h

XT 103

popxt.h
7.2
7.2.1
LCD
7.2.1.1 glcd

LCD 21
16

void glcd(unsigned char x, unsigned char y ,char *p,...)

x 0 15
y 0 20
*p


%c %C - 1
%d %D - -32,768 32,767
%l %L - -2,147,483,648 2,147,483,647
%f %F -

( 3 )
7-1
glcd(2,0,Hello World); // Hello World 2 ( 3)
100 F
HelloRWorld
RRRRow03
RRRRRow04
RRRRRRow05
RRRRRRRow06
RRRRRRRRow07

7-2
int x=20;
glcd(1,2,Value = %d,x);

Row00
RRValueR=R20
RRRow02
RRRRow03
RRRRRow04
RRRRRRow05
RRRRRRRow06
RRRRRRRRow07

//
// 2 1 ( 2)
100 F

XT
104

7.2.1.2 colorRGB

RGB (
) 16
5 6
5

unsigned int colorRGB(uint red,uint green,uint blue)

red - 0 31 31 31
green - 0 63 63 63
blue - 0 31 31 31
7-3
#include <popxt.h>
int colors;
void setup()
{
int colors;
colors=colorRGB(31,0,0);
// 16 colors
glcdFillScreen(colors);
//

}
void loop()
{}

100 F

ATMega32U4

Row00
RRValueR=R20
RRRow02
RRRRow03
RRRRRow04
RRRRRRow05
RRRRRRRow06
RRRRRRRRow07
RRRRRRRRRow08
RRRRRRRRRRow09
RRRRRRRRRRRow010
RRRRRRRRRRRRow011
RRRRRRRRRRRRRow012
RRRRRRRRRRRRRRow013
RRRRRRRRRRRRRRRow014
RRRRRRRRRRRRRRRRow015

100

220 F

TB6612

XT 105

7.2.1.3 color[ ]
8
color[]

unsigned int color[]= { GLCD_RED,


GLCD_GREEN,
GLCD_BLUE,
GLCD_YELLOW,
GLCD_BLACK,
GLCD_WHITE,
GLCD_SKY,
GLCD_MAGENTA};

GLCD_RED -
GLCD_GREEN -
GLCD_BLUE -
GLCD_YELLOW -
GLCD_BLACK -
GLCD_WHITE -
GLCD_SKY -
GLCD_MAGENTA -
7-4
glcdFillScreen(color[5])
//

7-5

glcdFillScreen(GLCD_BLUE) //

XT
106

7.2.1.4 setTextColor
glcd()

void setTextColor(unsigned int newColor)

newColor 16 color[]
7-6
//
setTextColor(GLCD_YELLOW);

7.2.1.5 setTextBackgroundColor




(screen background)
glcdFillScreen

void setTextBackgroundColor(unsigned int newColor)

newColor 16 color[]
7-7

setTextBackgroundColor(GLCD_GREEN); //

100 F

ATMega32U4

Hello World
RRValueR=R20
RRRow02
RRRRow03
RRRRRow04
RRRRRRow05
RRRRRRRow06
RRRRRRR Row07
RRRRRRRRRow08
RRRRRRRRR Row09
RRRRRRRRRR Row010
RRRRRRRRRRR Row011
RRRRRRRRRRRR Row012
RRRRRRRRRRRRR Row013
RRRRRRRRRRRRRR Row014
RRRRRRRRRRRRRRR Row015

100

220 F

TB6612

XT 107

7.2.1.6 glcdClear



setTextBackGroundColor()
glcdClear()

void glcdClear()
7-8
glcdClear();

//

7.2.1.7 glcdFillScreen

void glcdFillScreen(unsigned int color)

color 16 color[]
7-9
glcdFillScreen(GLCD_BLUE); //

XT
108

7.2.1.8 glcdMode

( 0), 90 ( 1), 180 ( 2) 270 ( 3)

glcdMode(unsigned int modeset)

modeset 0 3 0 90 180
270
0

7-10
#include <popxt.h>
void setup()
{
setTextSize(2);
}
void loop()
{
glcdClear();
glcdMode(0);
glcd(0,0,POP-BOTXT);
sw_ok_press();
glcdClear();
glcdMode(1);
glcd(0,0,POP-BOTXT);
sw_ok_press();
glcdClear();
glcdMode(2);
glcd(0,0,POP-BOTXT);
sw_ok_press();
glcdClear();
glcdMode(3);
glcd(0,0,POP-BOTXT);
sw_ok_press();
}

// 2
//
// 0
//
//

XT 109

7.2.1.9 setTextSize


6x10 1 21 16

setTextSize(unsigned int newSize)

newSize 1 16

7-11
#include <popxt.h>
void setup()
{
setTextSize(1);
// 1
setTextColor(GLCD_GREEN); //
glcd(0,0,Size1);
//
setTextSize(2);
glcd(1,0,Size2);
// 2
setTextSize(3);
glcd(2,0,Size3);
// 3
setTextSize(4);
glcd(3,0,Size4);
// 4
}
void loop()
{}

XT
110

7.2.1.10 getTextColor

unsigned int getTextColor()

textColor 16 colorRGB()
7-12
unsigned int color;
color=getTextColor();
// color

7.2.1.11 getTextBackgroundColor

unsigned int getTextBackgroundColor()

textBackgroundColor 16 colorRGB()
7-13
unsigned int color;
color=getTextBackgroundColor(); //
color

7.2.1.12 getTextSize

unsigned int getTextSize()

textSize
7-14
unsigned int textSize;
textSize=getTextSize();
// textSize

XT 111

7.2.1.13 glcdGetMode

unsigned int glcdGetMode()

mode 0 3

0 , 90
, 180 270
7-15
unsigned int Mode;
Mode=glcdGetMode(); // GLCD

7.2.1.14 glcdPixel
128 x 160

void glcdPixel(unsigned int x,unsigned int y,unsigned int color)

x x 0 127
y y 0 159
color 16 color[]
7-16
#include <popxt.h>
int i;
void setup()
{
for (i=0;i<128;i+=4)
{
glcdPixel(i,80,GLCD_RED);
// 4 x
}
for (i=0;i<160;i+=4)
{
glcdPixel(64,i,GLCD_RED);
// 4 y
}
}
void loop()
{}

XT
112

7.2.1.18 glcdRect

void glcdRect(unsigned int x1,unsigned int y1,unsigned int width,unsigned int


height,unsigned int color)

x1
x 0 127
y1
y 0 159
width
() 1 128
height
() 1 158
color 16 color[]
7-17
#include <popxt.h>
void setup()
{
glcdRect(32,40,64,80,GLCD_RED); //
64 x 80
}
void loop()
{}

XT 113

7.2.1.19 glcdFillRect


glcdRect

void glcdFillRect(unsigned int x1, unsigned int y1, unsigned int width, unsigned int
height,unsigned int color)

x1
x 0 127
y1
y 0 159
width
() 1 128
height
() 1 158
color 16 color[]
7-18
#include <popxt.h>
void setup()
{
glcdFillRect(32,40,64,80,GLCD_RED); //
64 x 80
}
void loop()
{}

XT
114

7.2.1.20 glcdLine

void glcdLine(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int
y2,unsigned int color)

x1 x 0 127
y1 y 0 159
x2 x 0 127
y2 y 0 159
color 16 color[]
7-19
#include <popxt.h>
void setup()
{
glcdLine(0,0,127,159,GLCD_RED); //
}
void loop()
{}

XT 115

7.2.1.21 glcdCircle

void glcdCircle(unsgined int x, unsgined int y, unsgined int radius,unsgined int color)

x x 0 127
y y 0 159
radius
color 16 color[]
7-20
#include <popxt.h>
void setup()
{
glcdCircle(32,120,31,GLCD_MAGENTA); // 31
}
void loop()
{}

XT
116

7.2.1.22 glcdFillCircle

glcdCircle

void glcdFillCircle(unsigned int x, unsigned int y, unsigned int radius,unsigned int color)

x x 0 127
y y 0 159
radius
color

16 color[]
7-21
#include <popxt.h>
void setup()
{
glcdFillCircle(32,120,31,GLCD_MAGENTA); // 31
}
void loop()
{}

XT 117

7.2.1.23 glcdArc

void glcdArc(unsigned int x,unsigned int y,unsigned int r,int start_angle,int


end_angle,uint color)

x x
y y
r
start_angle
end_angle
color
7-22
#include <popxt.h>
void setup()
{
glcdArc(48,80,16,30,150,GLCD_RED);
glcdCircle(48,75,5,GLCD_BLUE);
glcdCircle(80,75,5,GLCD_BLUE);
glcdArc(80,80,16,30,150,GLCD_RED);
glcdFillCircle(64,90,7,GLCD_GREEN);
glcdArc(64,100,30,220,320,GLCD_RED);
}
void loop()
{}

XT
118


7.2.2
7.2.2.1 sleep delay

void sleep(unsigned int ms)


void delay(unsigned int ms)

ms - 0 65,535
7-23
// 20
sleep(20);
delay(1000);
// 1

7.2.2.2 delay_us

void delay_us(unsigned int us)

us - 0 65,535
7-24
// 100
delay_us(100);


7.2.3
7.2.3.1 beep


500Hz 100
POP-BOT XT

void beep()

7-25
beep();

// 500Hz 100

7.2.3.2 sound

void sound(int freq,int time)

freq - 0 32,767
time - 1 0 32,767
7-26
sound(1200,500); // 1200Hz 500

XT 119


7.2.4
7.2.4.1 in

POP-BOT XT

char in(x)

x -

0 1
7-27
char x;
// x
x = in(2);
// 2 (Di2) x

7.2.4.2 out

out(char _bit,char _dat)

_bit -
7-28
out(4,1);
// 4/A6 1
out(6,0);
// 6/A7 0

XT
120


7.2.5
7.2.5.1 analog

A0 A7
0 +5V

unsigned int analog(unsigned char channel)

channel - 0 7

A0 A7


10 0 1,023

7.2.5.2 knob
KNOB POP-XT
analog(8) 80 1023

OK

POP-XT

unsigned int knob()

KNOB POP-XT 80 1023


7-29
int val=0;
//
val=knob(); // KNOB POP-XT val

7.2.5.3 sw_ok()
OK POP-XT

unsigned char sw_ok()

1 ()
0 ()
OK Knob 0

XT 121

7-30
if(sw_ok())
{
beep(); // OK
}

7.2.5.4 sw_ok_press()
OK POP-XT

7-31
........
//
OK
sw_ok_press();
......

7.2.6

7.2.6.1 motor

void motor(char _channel,int _power)

_channel -

POP-BOT XT 1 2
_power - -100 100
_power (1 100)
_power (-1 -100)
_power 0 0
motor_stop
7-32
// A 60%
motor(1,60);
motor(1,-60);
// A 60%

7-33
// B 100%
motor(2,100);

XT
122

7.2.6.2 motor_stop

void motor_stop(char _channel)

_channel - 1, 2 ALL ALL 2

7-34
// A
motor_stop(1);
motor_stop(2);
// B
7-35
motor_stop(ALL);
// 2

7.2.6.3 fd
forward POP-BOT XT

fd(unsigned int speed)

speed 0 100
7-36

60
fd(60); //

7.2.6.4 fd2

forward2 POP-BOT XT

fd2(unsigned int speed1 ,unsigned int speed2)

speed1 A 0 100%
speed2 B 0 100%
7-37
//


B A
fd2(30,80);

XT 123

7.2.6.5 bk
backward POP-BOT XT

bk(unsigned int speed)

speed 0 100
7-38
//

POP-BOT XT 90
bk(90);

7.2.6.6 bk2

POP-BOT XT

backward2

bk2(unsigned int speed1 ,unsigned int speed2)

speed1 A 0 100
speed2 B 0 100
7-39
//

bk()
bk2(80,80);

fd2() bk2()
2

POP-BOT
XT
speed1 speed2

7.2.6.7 tl tr

turn left turn right

tl(unsigned int speed) tr(unsigned int speed)

speed 0 100
7-40
//

60
tl(60);
tr(100);
//

100

XT
124

7.2.6.8 sl sr
spin left spin right

sl(unsigned int speed) sr(unsigned int speed)

speed 0 100%
7-41
//

70%
sl(70);
sr(100);
//

100%

7.2.6.9 ao
all motor off
motor_stop(ALL);

ao()
7-42
void setup()
{
fd(100);
sleep(2000);
ao();
}

//

// 2
//

7.2.7

1
servo

3

void servo(unsigned char _ch, int _pos)

_ch - 8 13
_pos - 0 180 -1
-1

XT 125


7.2.8

(UART)

7.2.8.1

UART0
USB POP-XT ()
USB

UART1
RXD1 ( 2) TXD1 ( 3)

7.2.8.2 uart
UART0 4,800

void uart(char *p,...)

p - UART0

%c %C 1
%d %D -32,768 +32,767
%l %L -2,147,483,648 +2,147,483,647
%f %F ( 3 )
\r

\n

7.2.8.3 uart_set_baud
UART0

void uart_set_baud(unsigned int baud)

baud -

UART0 2400 115,200


7-43
uart_set_baud(4800); // 4,800

XT
126

7.2.8.4 uart_available
UART0

unsigned char uart_available(void)

- 0
- 0
7-44
char x =uart_available();
// UART0 x 0
// uart_getkey

7.2.8.5 uart_getkey
UART0

char uart_getkey(void)

- 0 UART
-
7-45
#include <popxt.h>
//

void setup()
{
glcdClear();
//
setTextSize(2);
// 2
glcdMode(1);
//
}
void loop()
//
{
if(uart_available())
//
{
if(uart_getkey()==a)
// a
{
glcd(1,0,Key a Active!); //

a
sleep(1000);
// 1
}
else
{
glcdClear;
//
}
}
}

XT 127

Serial Monitor Arduino1.0


No line ending 115200 Autoscroll a
Send
POP-XT USB
USB Serial port

POP-XT a Key a Active!



uart
UART uart_getkey
115,200 8


uart_set_baud

XT
128

7.2.8.6 uart1
UART1
9,600

void uart1(char *p,...)

p - UART1

uart

7.2.8.7 uart1_set_baud
UART1

void uart1_set_baud(unsigned int baud)

baud - UART1 2400 115,200


7-46
uart1_set_baud(19200);
// 19,200

7.2.8.8 uart1_available
UART1

unsigned char uart1_available(void)

- 0
- 0
7-47
char x =uart1_available();
// UART1
// x 0 uart1_getkey

7.2.8.9 uart1_getkey
UART1

char uart1_getkey(void)

- 0
-

XT 129

GP2D120
7.3

popbot.h
POP-BOT XT POP-BOT XT
popxt.h

POP-BOT XT 1 GP2D120
GP2D120 gp2d120_lib.h
GP2D120
gp2d120_lib.h

#include <gp2d120_lib.h>

GP2D120

POP-BOT XT
A0 A7

7.3.1 getdist
GP2D120

unsigned int getdist(char adc_ch)

adc_ch 0 7

7-48
dist = getdist(3);
// GP2D120 A3

XT
130

XT 131

XT

POP-BOT X T

POP-XT
TB6612

8.1

, ,





(motor
driver)


20mA (
ATmega32U4)

8.2


(PWM)

8-1 () 50% 50%


(50 x 4.8) /100 = 2.4V 8-1 () ()


75% 25%

XT
132

(V)

(V)

4.8V

4.8V

50%

2.4V

()

(V)

75%

4.8V

()

(V)

25 %

4.8V

3.6V
1.2V

()

()

8-1


PWM ()
() PWM
50% () PWM 75% () PWM 25%

8.3 PWM Arduino


Arduino analogWrite()
PWM (Pulse Width Modulation)




0
255
0

0V
255

+5V
0 255

0 5V

5V
51 +5V 20%
0V 80% 20%

127 +5V 0V
50%
191
+5V

0V

75%
8-2 PWM

XT 133

20%

tW
50%

T
t
D w 100%
T

75%

tw
T
1

8-2 PWM

Output_voltage = (on_time / off_time) * max_voltage

PWM analogWrite()
LED




PWM a na logWrite
digitalRead digitalWrite
Arduino Leonardo ( POP-XT )
5 3, 5, 9, 10 11 POP-XT 5, 9 10
3 SDA 11

PWM analogWrite()
analogWrite(pin,value);

pin (3, 5, 9 11)


0 255
value

XT
134

8.4
C/C++ POP-BOT XT
popxt.h
motor(_channel,_power);
motor_stop(_channel);

fd(speed);


bk(speed);
tl(speed);

tr(speed);
sl(speed);
sr(speed);
ao();

8.4.1 motor

void motor(char _channel,int _power)

_channel -

POP-BOT XT 1 2
_power - -100 100
_power (1 100)
_power (-1 -100)
_power 0 0
motor_stop
8-1
motor(1,60);
// A 60%
motor(1,-60);
// A 60%

8-2
motor(2,100);
// B 100%

XT 135

8.4.2 motor_stop

void motor_stop(char _channel)

_channel - 1, 2 ALL ALL 2

8-3
// 1
motor_stop(1);
motor_stop(2);
// 2
8-4
motor_stop(ALL);
// 2

8.4.3 fd
forward POP-BOT XT

fd(unsigned int speed)

speed 0 100
8-5

60
fd(60); //

8.4.4 fd2

forward2 POP-BOT XT

fd2(unsigned int speed1 ,unsigned int speed2)

speed1 A 0 100%
speed2 B 0 100%
8-6

B A
fd2(30,80); //

XT
136

8.4.5 bk
backward POP-BOT XT

bk(unsigned int speed)

speed 0 100
8-7
//

POP-BOT XT
bk(90);
90

8.4.6 bk2
backward2

POP-BOT XT

bk2(unsigned int speed1 ,unsigned int speed2)

speed1 A 0 100
speed2 B 0 100
8-8
bk2(80,80);
//

bk()
fd2() bk2() 2 POPBOT XT


speed1 speed2

8.4.7 tl tr
turn left turn right

tl(unsigned int speed) tr(unsigned int speed)

speed 0 100
8-9
tl(60);
//

60
tr(100);
//

100

XT 137

8.4.8 sl sr
spin left spin right

sl(unsigned int speed) sr(unsigned int speed)

speed 0 100%
8-10
sl(70);
//

70%
sr(100);
//

100%

8.4.9 ao
all motor off
motor_stop(ALL);

ao()
8-7
void setup()
{
fd(100);
//

sleep(2000); // 2
ao();
//

XT
138

XT
A5-1

Arduino IDE
POP-BOT XT

USB


LED

1 LED

#include <popxt.h>
void setup()
{}
void loop()
{
fd(80);
sleep(1000);
bk(80);
sleep(1000);
}

A5-1 ForwardBackward.ino C Arduino1.0

POP-BOT XT

XT 139


A1-2

OK

#include <popxt.h>
void setup()
{
fd2(30,90);
sw_ok_press();
ao();
}
void loop()
{}

A5-2 CircleMove.ino C Arduino1.0

POP-BOT XT

XT
140


A5-3
OK POP-XT

#include <popxt.h>
void setup()
{
setTextSize(2);
glcd(1,1,Press OK);
glcd(2,1,to Start);
sw_ok_press();
glcdClear();
glcd(1,1,Moving...);
}
void loop()
{
fd(80);
sleep(900);
tr(80);
sleep(400);
}

//
// 2
//
// OK
//
// 80%
// 80%

A5-3 Rectangle_Running.pde C Arduino

POP-BOT XT


XT 141


A5-4
0.6
0.4 0.6 0.3 0.6
0.3

#include <popxt.h>
//
void setup()
{
glcdClear();
// GLCD
setTextSize(2);
// 2
glcd(1,1,Press OK);
//
glcd(2,1,to Start);
sw_ok_press();
//

beep();
//
glcdClear();
// GLCD
}
void loop()
{
glcdFillScreen(GLCD_RED);
// GLCD
fd(80);
// 80
sleep(600);
// 0.6
glcdFillScreen(GLCD_GREEN); // GLCD

tl(60);
// 60
sleep(400);
// 0.4
glcdFillScreen(GLCD_BLUE); // GLCD
bk(80);
// 80
sleep(600);
// 0.6
glcdFillScreen(GLCD_YELLOW); // GLCD

sr(60);
// 60
sleep(300);
// 0.3
glcdFillScreen(GLCD_MAGENTA); // GLCD

bk(80);
// 80
sleep(600);
// 0.6
glcdFillScreen(GLCD_WHITE); // GLCD
sl(60);
// 60
sleep(300);
// 0.3
}

A5-4 MultiDirectionMove.ino C Arduino

POP-BOT XT

XT
142

USB

POP-BOT XT

Press OK
to Start

OK POP-BOT XT

fd2(speed1,speed2) bk2(speed1,speed2)

fd() bk() fd2() bk2()

2 A B

POP-BOT XT
POP-BOT XT 2

A5-5

fd2 bk2

XT 143

#include <popxt.h>
void setup()
{
setTextSize(2);
glcd(1,1,Press OK);
glcd(2,1,to Start);
sw_ok_press();
glcdClear();
glcd(1,1,Moving...);
fd2(70,70);
}
void loop()
{}

//
// 2
//
// OK
//
//

70%

A5-5 MoveAlignment.ino C Arduino

POP-BOT XT

fd


speed1 fd2


speed2 fd2

XT 145

XT

(switch)

POP-BOT XT





POP-BOT XT

ZX-01 9-1

1 0

POP

POP-BOT XT


BOT XT

LED1

Indicator

+V

R2
10k

:
0
LED
1
LED

R1
510

R3
220

DATA

Signal output
S1
GND
Switch

9-1 ZX-01

POP-BOT XT

XT
146


ZX-01 0
1


(A6.1) ZX-01 22/A4 23/A5

Press OK to Start

ATMega32U4

100
TB6612

(A6.2) Arduino1.0 A6-1 TouchSwitchTest.ino


(A6.3) POP-XT

POP-BOT XT 10

USB
(A6.4) POP-XT

POP-BOT XT
(A6.5)

Press OK To Start

OK POP-XT POP-BOT XT

ZX-01 22/A4
1kHz 0.3

ZX-01 23/A5
2kHz () 0.3

XT 147

#include <popxt.h>
void setup()
{
setTextSize(2);
glcd(1,1,Press OK);
glcd(2,1,to Start);
sw_ok_press();
glcdClear();
glcd(1,1,Lets go!);
}
void loop()
{
if(in(22)==0)
{
sound(1000,300);
glcdFillScreen(GLCD_RED);
}
if(in(23)==0)
{
sound(2000,300);
glcdFillScrren(GLCD_YELLOW);
}
}

//
// 2
//
// OK
//

// 22
// 1kHz
//
// 23
// 2kHz
//

A6-1 TouchSwitchTest.ino C Arduino1.0

POP-BOT XT

XT
148

XT
2

1. :

POP-BOT XT
2. :

POP-BOT XT
3. 22/A4 :

POP-BOT XT

4. 23/A5 :

POP-BOT XT

#include <popxt.h>
//
void setup()
{
setTextSize(2);
// 2
glcd(1,1,Press OK);
//
glcd(2,1,to Start);
sw_ok_press();
// OK
glcdClear();
glcd(1,1,Lets go!);
//
}
void loop()
{
if(in(22)==0&&in(23)==0)
//

{
fd(60);
//
}
else if(in(22)==0)
//
22
{
tl(60);
//

}
else if(in(23)==0)
//
23
{
tr(60);
//

}
else
{
ao();
//

}
}


&&

2

if

A7-1 RemoteSwitch.ino C Arduino1.0

POP-BOT XT

XT 149

POPBOT XT A7-1
(A7.1) ZX-01

POP-XT

POP-BOT XT
ZX-01

POP-BOT XT

(A7.2) A7-1 POP-BOT XT

POP-BOT XT
(A7.3)

XT
150

POP-BOT XT

POP-BOT X T

POP-BOT XT

POP-BOT XT

POP-BOT XT

XT 151

POP-BOT XT
A8-1
(A8.1) A8-1 POP-BOT XT
(A8.2) USB


Press OK
to Start

POP-BOT XT

POP-BOT XT
OK

XT
152

//
#include <popxt.h>
void setup()
{
setTextSize(2);
// 2
glcd(1,1,Press OK);
//
glcd(2,1,to Start);
sw_ok_press();
// OK
glcdClear();
glcd(1,1,Lets go!);
//
}
void loop()
{
fd(70);
if(in(22)==0)
//
{
bk(80);
//
sleep(300);
sr(80);
//
sleep(200);
}
if(in(23)==0)
//
{
bk(80);
//
sleep(400);
sl(80);
//
sleep(400);
}
}


Sleep()

A8-1 ObjectAvoider.ino C Arduino1.0


POP-BOT XT

XT 153

XT

POP-BOT XT

POP-BOT XT

10.1

TCRT5000
10-1


LED TCRT5000

510
10k

+V

TCRT5000

OUT

510

GND

LED

10k

TCRT5000

+V

OUT

GND

LED

10-1

XT
154

10.2
10.2.1



(

)
1. (

) 90 x 60
1

POP-BOT XT


2. 1 2 3M

3.

10.2.2

C Arduino

POP-BOT XT analog
0 1023

0
1023 9


POP-BOT XT

XT 155

ZX-03

(A9.1) Arduino1.0 C A9-1


(A9.2)

POP-BOT XT USB
(A9.3)
30x30 .

ZX-03

ZX-03
(A9.4)
18/A0 ZX-03 19/A1
#include <popxt.h>
//
void setup()
{
setTextSize(3);
glcdMode(3);
glcd(1,1,"Press OK");
//
sw_ok_press();
//

OK
}
void loop()
{
glcd(1,0,"L=%d ",analog(0)); // ZX-03
glcd(3,0,"R=%d ",analog(1)); // ZX-03
sleep(100);
}

A9-1 SurfaceRead.pde C Arduino1.0


LCD

POP-BOT XT

XT
156

TB6612

R=100

100

L=100

(A9.5)

POP-BOT XT

(A9.3)

80 250

100
TB6612

TB6612

R=900

100

L=900

POP-BOT XT

(A9.6)
700 1000

100
TB6612

700 1000

80 250

(700+250) /2 = 500

30

XT 157

(
) ZX-03

()

(A10.1) Arduino1.0 C A10-1
(A10.2)

POP-BOT XT USB
(A10.3)

(A10.4)

#include <popxt.h>
void setup()
{}
void loop()
{
if(analog(0)<20)
{
sound(2500,500);
glcdFillScreen(GLCD_RED);
}
else
{
glcdClear();
}
}

//

// ZX-03
//
//

//

A10-1 AlarmBOT.ino C Arduino1.0

POP-BOT XT

XT
158


10

POP-BOT XT


POP-BOT XT

POP-BOT XT
ZX-03

ZX-03

POP-BOT XT

(A11.1) Arduino1.0 C A11-1


#include <popxt.h>
int L,R;
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
glcd(2,1,"to Start");
sw_ok_press();
glcdClear();
glcd(1,1,"Moving...");
}

//

// 2
//
// OK
//

XT 159

void loop()
{
fd(60);
//
L=analog(0);
// A0
R=analog(1);
// A1
if (L<500&&R<500)
//

{
bk(80);
//
sound(1000,100);
//
sleep(500);
sr(60);
//

sleep(300);
}
else if(L<500)
//
{
bk(80);
//
sound(1500,100);
//
sleep(400);
sr(60);
//

sleep(300);
}
else if(R<500)
//
{
bk(80);
//
sound(1500,100);
//
sleep(300);
sl(60);
//

sleep(500);
}
}

2 L R
ZX-03
IF


sound

(bk();)
sound

A11-1 EdgeDetect.ino C

POP-BOT XT

XT
160

(A11.2)

POP-BOT XT USB
(A11.3)

OK

ZX-03


ZX-03

2
1 00

1 00

100

TB 66 12

TB 66 12

TB 66
12

100

10
0

TB 66
12

100

TB 661
2

TB6
61 2

100

10
0

TB6
61
2

100

TB 661
2

TB6
61
2

100
61

10
T B6

TB6 612

TB

66

12

10
0

XT 161

XT
9

POP-BOT XT
500 ZX03 500

POP-BOT XT

POP-BOT XT

(A12.1) Arduino1.0 C A12-1


(A12.2)

POP-BOT XT USB
(A12.3) 30 .
(A12.4)

60 .

OK

ZX-03

(A12.5) A12-1
ao();






A12 -2
(A12.6) A12-2 POP-BOT XT
(A12.7)

(A11.4)

OK

ZX-03

A12-1

XT
162

//
#include <popxt.h>
void setup()
{
setTextSize(2);
// 2
glcd(1,1,"Press OK");
//
sw_ok_press();
// OK
glcd(1,1,"Moving...");
//
fd(60);
//
while(analog(0)>500);
// A0

ao();
//
}
void loop()
{}

OK

ZX-03 A0 (
) 500

ao();

A12-1 BlackLineDetect.ino C Arduino1.0

POP-BOT XT
#include <popxt.h>
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
glcd(1,1,"Moving...");
fd(60);
while(analog(0)>500);
bk(100);
sleep(100);
ao();
}
void loop()
{}

//
// 2
//
// OK
//
// A0

//

//

A12-2 BlackLineDetect2.ino C Arduino1.0

POP-BOT XT

bk();

XT 163

XT

100

TB 6612

100

TB66
12

XT
164

10

12
TB 66

100

TB6612

(A13.1) Arduino1.0 C A12-1


(A13.2)

POP-BOT XT USB

XT 165

(A13.3) 90 x 60 (

POP-BOT XT

OK


(A13.4)

POP-BOT XT

(A13.5)

POP-BOT XT


1.
ZX-03
A0/18
A1/19
2. A B
A ( 1) B ( 2)
3.

5 10

4.
9

XT
166

#include <popxt.h>
int L,R;
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
glcd(1,1,"Moving...");
}
void loop()
{
L=analog(0);
R=analog(1);
if (L<500&&R<500)
{
fd(60);
sound(2000,200);
}
else if(L>500&&R>500)
{
fd(60);
}
else if(L<500)
{

sl(60);
sleep(20);

}
else if(R<500)
{

sr(60);
sleep(20);

//

// 2
//
// OK
//

//
//
//
//

//

//

//

//
//

//

//
//

A13-1 SimpleLineTracking.ino C Arduino1.0

POP-BOT XT

XT 167

Maze Solving

90x60 (



90

R90()

90

ZX-03


A14-1

R90()

POP-BOT XT

XT
168

A14-1

R90()

(A14.1) Arduino1.0 C A14-1


(A14.2)

POP-BOT XT USB
(A14.3)

POP-BOT XT

OK

POP-BOT XT

XT 169

#include <popxt.h>
//
int L,R;
/* */
void R90()
{
fd(60);
//
sound(1500,100);
while(analog(1)>500)
//

{
sr(60);
}
while(analog(1)<500)
//

{
sr(60);
}
}
void setup()
{
setTextSize(2);
// 2
glcd(1,1,"Press OK");
//
sw_ok_press();
// OK
glcd(1,1,"Moving...");
//
}
void loop()
{
L=analog(0);
//
R=analog(1);
//
if (L<500&&R<500)
//
{
R90();
// 90
}
else if(L>500&&R>500)
//

{
fd(60);
//

}
else if(L<500)
//

{
sl(60);
//

sleep(20);
}
else if(R<500)
//

{
sr(60);
//

sleep(20);
}
}

A14-1 SimpleMaze.ino C Arduino1.0


POP-BOT XT

XT
170

XT

1 2 3
4

(A15.1)
90x120 .

(A15.2) Arduino1.0 C A15-1


(A15.3)

POP-BOT XT USB

XT 171

#include <popxt.h>
int L,R,x=0;

//

/*

*/
void R90()
{
fd(60);
//
sound(1500,100);
while(analog(1)>500)
//

{
sr(60);
}
while(analog(1)<500)
//

{
sr(60);
}
}
/* */
void L90()
{
fd(60);
//
sound(1500,100);
while(analog(0)>500)
//

{
sl(60);
}
while(analog(0)<500)
//

{
sl(60);
}
}
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
glcd(1,1,"Moving...");
}
void loop()
{
L=analog(0);
R=analog(1);

// 2
//
// OK
//

//
//

XT
172

if (L<500&&R<500)
{
if(x==6)
{
x=0;
}
x++;
if (x==3)
{
R90();
}
else
{
L90();
}
}
else if(L>500&&R>500)
{
fd(60);
}
else if(L<500)
{
sl(60);
sleep(20);
}
else if(R<500)
{
sr(60);
sleep(20);
}

// ()
// 1
//
//
x


// 3
// 3

// 3
//

//

//

//

//

//



[R90()]
[L90()]

A15-1 MultipleCrossingTrack.ino C Arduino1.0

POP-BOT XT

XT 173

(A15.4)

POP-BOT XT

OK

POP-BOT XT 1, 2, 4, 5, 6, 7 8

XT
174

XT 175

XT

POP-XT

Arduino

GP2D120
GP2D120


GP2D120 POP-BOT XT (contact
less)

11.1 GP2D120

4 30

4.5 5V 33 mA
0.4 2.4V

+5V

LED

GP2D120

(V)
2.8

GP2D120

2.4
Vout GND

Vcc

2.0
1.6

1.2
0.8

38.39.6

0.4

1 2
5

12

16

20

24

28

32

(cm)

* R-27 Kodak
90%

11-1 GP2D120

XT
176

GP2D120 3
(Vcc),
(GND) (Vout) GP2D120

32.7 52.9


10-1
GP2D120 30
+5V 0.25 0.55V
0.4V

4 2.25V 0.3V

11.2 GP2D120
GPD120

POP-BOT

XT
GP2D120



GP2D120

11.3 GP2D120

Vout 0.5V
GP2D120
26 Vout 2V 6
Vout 11-1

GP2D120
GP2D120

gp2d120_lib.h

#include <gp2d120_lib.h>

GP2D120

POP-BOT XT
A0 A7

GP2D120 getdist()

unsigned int getdist(char adc_ch)

adc_ch 0 7

11-1
dist = getdist(3); // GP2D120 An3

XT 177

11-1 Vout GP2D120


()

XT
178

XT
XT

3x10 . 3 .
(A16.1.1) 2x3 GP2D120

(A16.1.2) GP2D120

3x10 . 3 .

XT 179

(A16.1.3) GP2D120 20/A2

20/A2

POP-BOT XT


GP2D120
POP-BOT XT

POP-BOT XT
GP2D120 gp2d120_lib.h
(A16.2.1) Arduino1.0 C A16-1
#include <popxt.h>
#include <gp2d120_lib.h>
int raw,dist;
void setup()
{
setTextSize(2);
glcdMode(1);
glcd(1,1,Press OK);
sw_ok_press();
glcdClear();
}
void loop()
{
raw=analog(20);
dist=getdist(20);
glcd(2,1,RAW Data = %d ,raw);
glcd(3,1,Distance = %d CM,dist);
sleep(100);
}

//

// GLCD
//

//
//
//

//

A16-1 GP2D120_Reading.ino C Arduino1.0


GP2D120

POP-BOT XT

XT
180

(A16.2.2)

POP-BOT XT

(A16.2.3) POP-BOT XT
GP2D120

100 F

A
TM
e
g
a
3
2
U
4

220 F

TB
6
6
1
2

100

4 32

XT 181

XT
A16-1 GP2D120
4 30

10

POP-BOT XT


(A17.1) Arduino1.0 C A17-1
(A17.2)

POP-BOT XT
(A17.3)

POP-BOT XT

POP-BOT XT
#include <popxt.h>
//
void setup()
{
setTextSize(2);
// 2
glcd(1,1,"Press OK");
//
glcd(2,1,"to Start");
sw_ok_press();
// OK
glcdClear();
glcd(1,1,"Lets go!");
//
}
void loop()
{
fd(70);
if(analog(20)>250)
// 10
{
bk(80);
//
glcdFillScreen(color[random(8)]); //

sleep(300);
sl(70);
//

sleep(600);
}
}

A17-1 TouchlessObjectAvoider.ino C Arduino1.0

POP-BOT XT

XT
182

(A17.4)

POP-BOT XT 10 ()

0.3
8 , ,
, , , ,
0.6

100

100

100

TB66 12

TB66 12

TB661 2

5
0
10

0
10

TB

2
1
66
TB

12
66

XT 183

XT

POP-BOT XT POP-XT

3 30 (SV1), 12 (SV2) 13 (SV3)


12.1

POP-BOT XT

R/C R/C Radio Control

,
R/C


(actuator)


0 90 0 180 0
180 360 3
(S),
(+V) (G) 12-1

12-1

STANDARD
SERVO MOTOR

XT
184


12-2
2

12.1.1

2
12-2
S J
Futaba J

12.1.2
12-3 ,
, (POT : Potentiometer)

P = kwg
P
k
w (rpm : round per minute)
g (torque)

XT 185

12-3
POT

0 180

POT
2 POT
(spline)


(horn)

, , ,
Hitec 24 Futaba 25

12.1.3

12-4
20 1
1.5

2


1.5 2
1.5


2
1 1.5

1

XT
186

STANDARD
SERVO MOTOR

STANDARD
SERVO MOTOR

12-4

STANDARD
SERVO MOTOR

XT 187

12.1.4

0 180

12-5





0 1 H-

H- 1%
50%

12-5

XT
188

12.1.5
3
(1) :



(2) :






(3) (Karbonite) :

Hitec


12.1.6
2 (speed) (torque)

0.15 60


60 0.15
- (ounce-inches : oz-in) - (kg-cm)

1 ( 1
0.028 1 35.274 )


4.8 6V

POP-BOT XT
12.2
popxt.h
POP-BOT XT

servo
3

void servo(unsigned char _ch, int _pos)

_ch - 1 3
_pos - 0 180 -1
-1

XT 189

KNOB
POP-XT
(A18.1) Arduino IDE C A18-1
(A18.2) POP-XT

POP-BOT XT

(A18.3) SV1 POP-XT


,

(S)

(A18.4) POP-XT OK

KNOB
POP-XT
KNOB

KNOB
KNOB

XT
190

#include <popxt.h>
int x;
void setup()
{
glcdMode(1);
setTextSize(2);
glcd(1,1,"Press OK");
sw_ok_press();
glcdClear();
}
void loop()
{
x=map(knob(),80,1023,0,180);
glcd(2,1,"Servo = %d ",x);
servo(1,x);
}

//

// 1
// 2
//
// OK

// KNOB 0 180 x
//

// SV1

A18-1 ServoKnob.ino C Arduino1.0


POP-XT

XT 191

XT
(A20.1.1) 2x3 2 3x6 . 3 .

(A20.1.2)

3x10 .

XT
192

(A20.1.3)

() 3x10 .
2 3 .

(A20.1.4) 12

(A20.1.2)
1 SV1

ObjectHitter-BOT

XT 193

POP-BOT XT ObjectHitter-BOT

(A20.2.1) Arduino IDE C A20-1



(A20.2.2) POP-XT

POP-BOT XT

(A20.2.3)

30 .
(A20.2.4) OK


POP-BOT XT


180
0

#include <popxt.h>
int L,R,x=0;
void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
glcd(2,1,"to Start");
sw_ok_press();
glcdClear();
glcd(1,1,"Lets go!");
servo(1,0);
sleep(1000);
fd(60);
}
void loop()
{
if(analog(0)<500)
{
ao();
servo(1,180);
sleep(1000);
servo(1,0);
while(1);
}
}

//

// 2
//
// OK
//
// 0
//

//
// 180
//
// 0
//

A20-1 ServoHitting.ino C Arduino

POP-BOT XT ObjectHitter-BOT

XT
194

START

STOP

START

4
1.

L90()
2.

R90()
3.

FF()
4.

hit()


4 4

(y) (x)
1

XT 195

1.


2.



3.

4.



5.

(A20.3.1) Arduino IDE C A20-2


(A20.3.2) POP-XT

POP-BOT XT

XT
196

#include <popxt.h>
//
int L,R,x=0,y=0;
/*
*/
void FF()
{
fd(60);
sleep(300);
}
/*
*/
void R90()
{
fd(60);
//
sound(1500,100);
while(analog(1)>500)
//

{
sr(60);
}
while(analog(1)<500)
//
{
sr(60);
}
}
/*
*/
void L90()
{
fd(60);
//
sound(1500,100);
while(analog(0)>500)
//

{
sl(60);
}
while(analog(0)<500)
//
{
sl(60);
}
}
/*
*/
void hit()
{
bk(100);
//
sleep(50);
ao();
//
servo(1,180);
// 180
sleep(1000);
servo(1,0);
bk(60);
// 0
sleep(200);
R90();
// 90
}

XT 197

void setup()
{
setTextSize(2);
glcd(1,1,"Press OK");
glcd(2,1,"to Start");
sw_ok_press();
glcdClear();
glcd(1,1,"Lets go!");
}
void loop()
{
L=analog(0);
R=analog(1);
if (L<500&&R<500)
{
if(x==5)
{
x=0;
y++;
if (y==4)
{
ao();
servo (1,-1);
while(1);
}
}
x++;
if (x==1)
{
L90();
}
else if(x==2||x==4)
{
hit();
}
else if (x==3)
{
FF();
}
else if (x==5)
{
R90();
}
}

// 2
//
// OK
//

//
//
//
// 1
//
//

// 4
//
//

//
x

// 1

// 2 4

// 3

// 5

XT
198

else if(L>500&&R>500)
{
fd(60);
}
else if(L<500)
{
sl(60);
sleep(20);
}
else if(R<500)
{
sr(60);
sleep(20);
}

//

//

//

//

//

//

A20-1 ObjectHitterBOT.ino C Arduino


POP-BOT XT ObjectHitter-BOT


(A20.3.4) OK



STOP

You might also like