You are on page 1of 87

ROBOT .

HEAD to TOE
Examples Guide PTK40A

PTK40A
PIC16F EXAMPLES GUIDE

V1.3

Sep 2014

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

Index
1. Introduction

2. Getting Started

2.1 Power and Programmer

2.2 Using MPLAB

2.3 PICkit 2 Programmer

10

2.4 Using Hyperterminal

12

2.5 PTK40A Jumpers Section

13

3.

Examples:

3.1 LED Blinking

14

3.2 BUZZER

15

3.3 7-Segment: 00 to 99

16

3.4 Display Hello World on LCD

17

3.5 Read Keypad, display on 7 segment

18

3.6 Read Keypad, display on LCD

19

3.7 ADC (temperature) on 7 Segment

20

3.8 ADC (potentiometer) control DC motor

21

3.9 ADC (potentiometer) to control stepper motor rotation speed

22

3.10 ADC (potentiometer) to control RC Servo motor position

24

3.11ADC: Read Ultrasonic Range Finder

26

3.12 ADC: Read Infrared Distance Sensor

28

3.13 Digital Input with IR01A

30

3.14 Digital input with PIR sensor

32

3.15 Tachometer in RPM

34

3.16 UART, motor control from keyboard

35

3.17 Real Time Clock from Timer 1

37

3.18 I2C with DS1307 RTC

38

3.19 UART, motor control from SKPS

39

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.20 Wireless with SKXBee

41

3.21 Wireless with BlueBee, Bluetooth

43

3.22 Digital Infrared Sensor

45

3.23 Password Door Security System

49

3.24 Using SD02B from PTK40A via normal digital output pin (JP26)

52

3.25 Using SD02B from PTK40A via UART interface

54

3.26 Using MD10C from PTK40A via normal digital output pin (JP27)

57

3.27 Using MD10C from PTK40A - Locked Antiphase mode

59

4.Troubleshooting and Error

63

5. Conclusion

65

Appendix A - Revision History

66

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

1. INTRODUCTION
PTK40A Training Board is developed based on Microchip 8-bit 40 pins PIC MCU
(MicroController Unit). It is compatible between PIC16F and PIC18F. It covers
programming, interfacing, and applications of microcontroller and mechanical hardware to
help users in learning and developing their project with PIC MCU.
The systems hardware is well configured so that it can be programmed by any compatible
programming language such as assembly, BASIC and C (for PIC MCU). MPLAB IDE from
Microchip Technology .Inc is included in this kit which has assembler that enable user to
develop the program with assembly language. However, the explanation and sample
programs provided in the users manual are based on C language due to its relatively
flexibility and easiness in understand and developing program.
This document provides guidance to operate the examples code/applications.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

PTK40A LAYOUT

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

2.GETTING STARTED
2.1 The Power and Programmer
Please connect the power supply from adapter and the USB (mini) cable provided as shown
in the below picture, please make sure the PTK40A is being powered up.

2.2 Open Example from MPLAB IDE


Please refer to the guide to install MPLAB IDE and HI-TECH C Compiler from PTK40A
Users Manual. After installation completed, double click the project file Example 1.mcp
to open the project. All examples should be under PTK40A Examples folder in PTK40As
CD.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

Or open it from MPLAB IDE Open Project icon, click on the icon shown in the picture:

Choose the desire project file to open:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

ROBOT . HEAD to TOE


Examples Guide PTK40A

The example project will appears as the picture shown:

Please check the settings at: Programmer ->Settings (On MPLAB IDE Toolbar), ensure the
settings are same as picture shows.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

10

ROBOT . HEAD to TOE


Examples Guide PTK40A

You can start editing the example program or compile it and load into PTK40A by clicking
the Build All icon as shown::

If the USB cable is connected correctly and PTK40A is powered up, the program will be
loaded into PTK40A and the output window in MPLAB IDE will show this:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

11

ROBOT . HEAD to TOE


Examples Guide PTK40A

2.3 PICkit 2 Programmer


Please refer to UIC00B Users Manual to install PICkit 2 Programmer. Another method to
load example code is to use the standalone PICkit 2 Programmer GUI. Connect the USB
cable to PTK40A and ensure the PTK40A is powered up. After installation is completed,
click the PICkit2 to open the program.
This is the interface of the PICkit2:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

12

ROBOT . HEAD to TOE


Examples Guide PTK40A

First, check the communication.

If the Programmer is connected and detected, import the HEX file from the desire example
folder.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

13

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

14

ROBOT . HEAD to TOE


Examples Guide PTK40A

Click on write to load program after the file is being imported..

Once Programming is successful, you can check the result on PTK40A.

2.4 Using HyperTerminal


Please refer to this page for setting up HyperTerminal, click HERE
Setting USB to UART Converter
learn the UART Protocol
how to interface with computer
Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

15

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

16

ROBOT . HEAD to TOE


Examples Guide PTK40A

2.5 PTK40A Jumpers Section

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

17

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

18

ROBOT . HEAD to TOE


Examples Guide PTK40A

3. Examples
3.1 LED BLINKING
Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

Jumpers Section
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example1.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

The LED of RD4 will keep blinking after the buzzer beep for once.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

19

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.2 BUZZER
Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example2.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

Press SW1,
SW2 to stop buzzer sound.

buzzer will sound; Press

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

20

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.3 7-Segment: 00 to 99
Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example3.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

7-segment will display value from 00 to 99 with increment of 1, and interval of 500ms.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

21

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.4 Display Hello World on LCD


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example4.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

After pressing SW1 the LCD will display Cytron PTK40A and Hello World.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

22

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.5. Read Keypad, display on 7 segment


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example5.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

23

ROBOT . HEAD to TOE


Examples Guide PTK40A

Keypad value will appear on 7-segment display according to button pressed.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

24

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.6 Read Keypad, display on LCD


Jumper Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example6.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

25

ROBOT . HEAD to TOE


Examples Guide PTK40A

Keypad value will appear on LCD according to button pressed.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

26

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.7. ADC (temperature) on 7 Segment


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

JP14

TEMP

CONNECT TO TEMPERATURE

Please load the Example7.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None
Expected Result:

Temperature reading from LM35 is display on 7-segment. Touch the temperature sensor to
see the temperature changes.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

27

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

28

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.8 ADC (potentiometer) control DC motor


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

PWM

CONNECT TO PWM

JP20

DC MOTOR

CONNECT TO DC MOTOR

JP21

DC MOTOR

CONNECT TO DC MOTOR

JP14

POT

CONNECT TO POTENTIOMETER

Please load the Example8.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumper
Additional Hardware:
None
Expected Result:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

29

ROBOT . HEAD to TOE


Examples Guide PTK40A

Turn the potentiometer to see the speed changes at the DC motor.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

30

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.9 ADC (potentiometer) to control stepper motor rotation speed


Jumpers Configuration
JUMPER NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

PWM

PWM

JP14

POT

CONNECT TO
POTENTIOMETER

JP20

STEPPER

CONNECT TO STEPPER
MOTOR

JP21

STEPPER

CONNECT TO STEPPER
MOTOR

JP23

UNIPOLAR

STEPPER MOTOR IN
UNIPOLAR

JP24

UNIPOLAR

STEPPER MOTOR IN
UNIPOLAR

Please load the Example9.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting up
the jumpers.
Additional Hardware:
None

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

31

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

The stepper motor rotation speed will based on the ADC value from potentiometer.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

32

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.10 ADC (potentiometer) to control RC Servo motor position


Jumpers Configuration
JUMPER NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP9

SERVO

CONNECT TO SERVO

JP10

BUZZER

CONNECT TO BUZZER

JP14

POT

CONNECT TO
POTENTIOMETER

Please load the Example10.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumper.
Additional Hardware:
None

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

33

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

Turn the potentiometer to see the servo motor turning.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

34

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.11 ADC: Read Ultrasonic Range Finder


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

JP14

EXT

CONNECT TO ULTRASONIC

Please load the Example11.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
Ultrasonic sensor x 1, please refer to the datasheet for further details.
Ultrasonic Connection:

Ultrasonic Pin

PTK40A External Analog Pin

GND

GND

+5V

5V

AN

IN

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

35

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

Once the connections are done and example code is loaded into PTK40A, the distance
detected by Ultrasonic will be displayed on LCD.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

36

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.12 ADC: Read Infrared Distance Sensor


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

JP14

EXT

CONNECT TO IR SENSOR

Please load the Example12.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumper
Additional Hardware:
Sharp Analog Distance Sensor x 1, please refer to the datasheet for further
details.
IR Analog Distance Sensor Connection:

IR Distance Sensor Pin

PTK40A External Analog Pin

Vo

IN

GND

GND

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

37

ROBOT . HEAD to TOE


Examples Guide PTK40A

Vcc

5V

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

38

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

The LCD will display the result of the IR sensor, distance from IR sensor until obstacle.

This is how to measure distance using IR sensor.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

39

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.13 Digital Input with IR01A


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

JP15

5V

CONNECT TO 5V

Please load the Example13.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
IR01A Sensor x 1, please refer the Users Manual for further detail.
IR01A connection:

IR01A Pin

PTK40A External Digital Input Pin

V+

GND

IN

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

40

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

The buzzer will sound if the IR01A sensor detected obstacle.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

41

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.14 Digital input with PIR sensor


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

JP15

5V

CONNECT TO 5V

Please load the Example14.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
PIR Sensor
PIR sensor connection:

Please refer to the PIR Users Manual for more information.


PIR Sensor Pin

PTK40A External Digital Input Pin

GND

OUT

IN

V+

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

42

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

The LED at RD5 will active (ON) there is change in environment. The PIR sensor detect
infrared.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

43

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.15 Tachometer in RPM


Jumpers Configuration
JUMPER NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

PWM

CONNECT TO PWM

JP20

DC MOTOR

CONNECT TO DC MOTOR

JP21

DC MOTOR

CONNECT TO DC MOTOR

JP14

POT

CONNECT TO
POTENTIOMETER

Please load the Example15.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
None
Expected Result:

Turn the potentiometer to control the speed of motor and further display the RPM on LCD. If
the encoder is too sensitive please adjust the threshold for the encoder by turning the
Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

44

ROBOT . HEAD to TOE


Examples Guide PTK40A

potentiometer labeled Threshold.


3.16 UART, motor control from keyboard
Jumpers Configuration
JUMPER NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

PWM

CONNECT TO PWM

JP14

TEMP

CONNECT TO TEMPERATURE
SENSOR

JP20

DC MOTOR

CONNECTED TO DC MOTOR

JP21

DC MOTOR

CONNECTED TO DC MOTOR

Please load the Example16.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
UC00A or UC00B
Connection:
Please refer to Using HyperTerminal to setup the necessary connection and COM port. .
Connect UC00A or UC00B to PTK40A UART pin. Please refer to respective Users Manual
for details, UC00A Users Manual, UC00B Users Manual. This example will use UC00A.

UC00A/B

PTK40A UART PORT

RX

TX

TX

RX

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

45

ROBOT . HEAD to TOE


Examples Guide PTK40A

GND

Expected Result:

The brush motor will turn according to the key pressed from computer keyboard.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

46

ROBOT . HEAD to TOE


Examples Guide PTK40A

While you control the motor from keyboard, PTK40A will also send temperature update to
HyperTerminal.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

47

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.17 Real Time Clock from Timer 1


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example17.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
None
Expected Result:

Time is displayed on LCD as shown.


instruction
SW1 = increase hours
SW2 = increase minutes
SW3 = increase seconds

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

48

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.18 I2C with DS1307 RTC


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP3

I2C

CONNECT TO I2C

JP5

I2C

CONNECT TO I2C

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example18.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
None
Expected Result:

The LCD will display the seconds, minutes, hours, date, month and year as shown.
To configure the clock information:
SW1 = choose mode
SW2 = increase the value

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

49

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.19 UART, motor control from SKPS


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP9

SERVO

CONNECT TO SERVO

JP10

PWM

CONNECT TO PWM

JP20

DC MOTOR

CONNECT TO DC MOTOR

JP21

DC MOTOR

CONNECT TO DC MOTOR

Please load the Example19.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
SKPS, please refer to SKPS Users Manual for further information.
PS2 controller
Connection:

Connect the SKPS with PS2 controller to dedicated slot on PTK40A as shown. Please ensure
the pin is connected correctly and properly as wrong connection will most probably
damage the SKPS.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

50

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

Push the knob up,down,left and right of the both joystick to see the result at servo and DC
motor.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

51

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.20 Wireless with SKXBee


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section))

JP10

BUZZER

CONNECT TO BUZZER

JP14

TEMP

CONNECT TO TEMPERATURE

Please load the Example20.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
Xbee Starter Kit x 2 units, please refer to SKXBee Users Manual for further
information.
Setup of SKXBee with X-CTU, please refer to this tutorial.

Red circle part is to pairing the XBee and PanID must same

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

52

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

53

ROBOT . HEAD to TOE


Examples Guide PTK40A

SKXBee Connection:

Please connect one of the SKXBee on PTK40A as shown, please ensure the connection is
correct and proper to avoid any damage. Another SKXBee connect to computer via USB
cable as shown.
Expected Result:

Reading from temperature sensor will shown in X-CTU and motor will turn if pressed key
Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

54

ROBOT . HEAD to TOE


Examples Guide PTK40A

from the keyboard for motor speed, slow speed from 1, and increase until 9.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

55

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.21 Wireless with BlueBee, Bluetooth


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer Jumpers Section)

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example21.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware :
BlueBee x1, please refer to BlueBee Users Manual for further details.
Bluetooth USB doggle x1
To setup the Bluetooth connection, please refer to here.
Connection:

Please connect the USB Bluetooth Dongle to any available USB port on computer or laptop.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

56

ROBOT . HEAD to TOE


Examples Guide PTK40A

Please connect the BlueBee module on SKXBee further connect it onto PTK40A as shown.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

57

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:
After Bluetooth SPP (Serial Port Profile) link is created and HyperTerminal is setup, please
press the Reset button on PTK40A.

HyperTerminal will show the message to request for value from keyboard.

The number (only number value) pressed on computer keyboard will be displayed on 7segment, PTK40A.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

58

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.22 Digital Infrared Sensor


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

JP10

BUZZER

CONNECT TO BUZZER

JP15

5V

5V TO POWER UP THE DEVICE

Please load the Example22.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
Low cost infrared sensor x 1, please refer to the Users Manual for further
details.
Connection:

Please connect the digital sensor to External Digital Port of PTK40A as shown.
Digital Sensor Pin

PTK40A External Digital Input Pin

Brown (Vcc)

V+

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

59

ROBOT . HEAD to TOE


Examples Guide PTK40A

Blue (Ground)

GND

Black (Signal output)

IN

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

60

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

61

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

Indicator LED helps to identify the output of its signal.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

62

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

63

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.23 Password Door Security System


Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

JP7

RELAY

CONNECT TO RELAY

JP10

BUZZER

CONNECT TO BUZZER

Please load the Example23.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
Magnetic Door Lock x 1
Connection:

Connect the magnetic lock as shown in picture.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

64

ROBOT . HEAD to TOE


Examples Guide PTK40A

The magnetic is activated when the relay is off.


Expected Result:

When switch on the power, the magnetic lock is activated and you need to key in 6 digit
password.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

65

ROBOT . HEAD to TOE


Examples Guide PTK40A

If wrong password is key-in, Error message will appear and the program restart in 3 second.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

66

ROBOT . HEAD to TOE


Examples Guide PTK40A

If correct password is correct, SUCCESS will appear on LCD and the lock release the metal.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

67

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.24 Using SD02B from PTK40A via normal digital output pin (JP26)
Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

JP10

PWM

CONNECT TO PWM

Please load the Example24.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware :
SD02B x1, please refer to SD02B Users Manual for further information.
STEPPER MOTOR x1
Connection:

Please connect the Stepper motor according to SD02B Users Manual. Further connect
SD02B to PTK40A Stepper port as shown in above diagram. Move the jumper on SD02B
to Vmotor.
SD02B

PTK40A SDXXX Stepper Port

Vmotor

VIN

GND

GND

PULSE

PULSE

DIR

DIR

EN

EN

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

68

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

69

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

Follow the instructions on LCD. SW1 to increase speed while SW2 to decrease speed. SW3
will activate/deactivate the turning of Stepper motor. SD02B have default step to
microstepping of 10:1, so it might be very slow, try to increase speed to maximum.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

70

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.25 Using SD02B from PTK40A via UART interface


Jumpers Configuration
JUMPER NUMBER

JP10

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

BUZZER

CONNECT TO BUZZER

Please load the Example25.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
SD02B x1, please refer to the Users Manual for further information.
STEPPER MOTOR x1
Connection:

Connection of SD02B to PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

71

ROBOT . HEAD to TOE


Examples Guide PTK40A

Connection from PTK40A to SD02B board

Power supply from the PTK40A board

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

72

ROBOT . HEAD to TOE


Examples Guide PTK40A

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

73

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

SW1 and SW 2 is to change direction, SW3 is for active or deactivate the SD02B.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

74

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.26 Using MD10C from PTK40A via normal digital output pin (JP27)
Jumpers Configuration
JUMPER NUMBER

JP10

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

PWM

CONNECT TO PWM

Please load the Example26.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
DC Brushed Motor x 1
MD10C x1, please refer to the Users Manual for further details.
Connection:

This is the basic diagram of the connection

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

75

ROBOT . HEAD to TOE


Examples Guide PTK40A

MD10C connection

Connection at the PTK40A board


MD10C

PTK40A MDXXX Port

VIN

VIN

DIR

CW

PWM

PWM

GND

GND

Please move the jumper for BOARD SUPPLY to VIN on MD10C.


Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

76

ROBOT . HEAD to TOE


Examples Guide PTK40A

Expected Result:

The DC brush motor will rotate in a direction when SW1 is pressed, while in another
direction when SW2 is pressed.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

77

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.27 Using MD10C from PTK40A: Locked Antiphase mode


Jumpers Configuration
JUMPER NUMBER

JP10

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

PWM

CONNECT TO PWM

Please load the Example27.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware :
DC Brushed Motor x 1
MD10C x1, please refer to the Users Manual for further details.
Connection:

Full connection

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

78

ROBOT . HEAD to TOE


Examples Guide PTK40A

MD01C Connection

PTK40A Connection

MD10C

PTK40A MDXXX Port

VIN

VIN

DIR

PWM

PWM

CCW

GND

GND

Expected result:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

79

ROBOT . HEAD to TOE


Examples Guide PTK40A

MOTOR EXPECTED TO STOP TURNING

MOTOR EXPECTED TO TURN CW DIRECTION

MOTOR EXPECTED TO TURN AT CCW DIRECTION


Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

80

ROBOT . HEAD to TOE


Examples Guide PTK40A

The DC brush motor will rotate in a direction when SW1 is pressed, while in another
direction when SW2 is pressed.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

81

ROBOT . HEAD to TOE


Examples Guide PTK40A

3.28 reserve
Jumpers Configuration
JUMPER
NUMBER

PIN NAME

CONDITION

LOCATION NUMBER
(refer location chart above)

JP3

I2C

NOT APPLICABLE

JP5

I2C

NOT APPLICABLE

JP6

SPI

NOT APPLICABLE

JP7

SPI

NOT APPLICABLE

JP9

SK_RST

NOT APPLICABLE

JP10

BUZZER

CONNECT TO BUZZER

JP14

POT

NOT APPLICABLE

JP15

5V

NOT APPLICABLE

JP18

OUT

NOT CONNECTED

JP20

STEPPER

NOT APPLICABLE

JP21

STEPPER

NOT APPLICABLE

JP23

UNIPOLAR

NOT APPLICABLE

JP24

UNIPOLAR

NOT APPLICABLE

Please load the Example 22.hex (Using MPLAB IDE or PICkit 2 Programmer) after setting
up the jumpers.
Additional Hardware:
DC Brushed Motor x 1
MD10C x1, please refer to the Users Manual for further details.
Connection:
Expected Result:

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

82

ROBOT . HEAD to TOE


Examples Guide PTK40A

4.TROUBLESHOOTING & ERROR


4.1 Compiler Version
There are differences in code when different version of HI-TECH C Compiler is used. The
examples given (Jul 2012) is being compiled under MPLAB IDE v8.63 with HI-TECH C
Compiler for PIC10/12/16 V9.80. Yet, it is compatible with V9.82. So, if you are using
different version of HI-TECH, please re-install it either with V9.80 or V9.82. We cannot
ensure the compilable of the code if you are using other version of compiler.
The examples code are compiled under HI-TECH C Compiler V9.80, if you are using later
version such as V9.82, please follow the steps below.
1st, click on the system.h

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

83

ROBOT . HEAD to TOE


Examples Guide PTK40A

2nd, change version support code

Thats all.
4.2 PICkit 2 not detected or error message
Connection and power of PTK40A might sometime lead to problem to load program. So
when you see the PICkit2 cannot get the ID of the PTK40A, please check weather the power
of PTK40A is activated and the USB cable is connected properly.
If problem still occur please check weather the setting is correct according to above setting.

4.3 Other Problems


If you still encounter problem which are unable to be solved. You are welcome to discuss it
in our technical forum anytime. Please explain the condition and capture photo of the
PTK40A problem.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

84

ROBOT . HEAD to TOE


Examples Guide PTK40A

5. CONCLUSION
Examples provided for PTK40A is aiming as references, not as a complete project. Please
feel free to modify it and suite it to your own purpose.
If you have any inquiry/problem, please do discuss in our technical forum. We prefer to have
a good learning and sharing environment where public may contribute and benefit from the
discussion, an open forum provide that.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

85

ROBOT . HEAD to TOE


Examples Guide PTK40A

Appendix A - Revision History


V1.0 (July 2012) - Initial Complete Release
V1.1 (June 2014) - Correction of the steps in Example 3.2, update address and phone
number.

Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

86

ROBOT . HEAD to TOE


Examples Guide PTK40A

Prepared by
Cytron Technologies Sdn. Bhd.
No. 16, Jalan Industri Ringan Permatang Tinggi 2,
Kawasan Industri Ringan Permatang Tinggi,
14100 Simpang Ampat,
Penang, Malaysia.
Tel:
Fax:

+604-504 1878
+604-504 0138

URL: www.cytron.com.my
Email: support@cytron.com.my
sales@cytron.com.my
Back to Index
Created by Cytron Technologies Sdn. Bhd. All Rights Reserved

87

You might also like