EasyRFIDkit_e121202

Page 1

Easy RFID Education kit 1. Kit Contents 1. i-Stamp2P module board

x1

2. JX-2P plus Project board

x1

3. UCON-4 USB download cable

x1

4. RFID reader serial board

x1

5. 400-point Breadboard

x1

6. DC adaptor +12Vdc 500mA

x1

7. #22 AWG hook up wire set

x1

8. IDC1MF wire set (5-wire mix color)

x1

9. IDC1FF wire set (5-wire mix color)

x1

10. LCD16x2 with cable

x1

11. Documentation

x1

12. CD-ROM

x1

13. Experiment component set 10.1 Resistor 1/4W 220

x8

10.2 Resistor 1/4W 510

x 16

10.3 Resistor 1/4W 1k

x4

10.4 Resistor 1/4W 2.2k

x2

10.5 Resistor 1/4W 4.7k

x6

10.6 Resistor 1/4W 10k

x5

10.7 Capacitor 15pF 50V ceramic

x2

10.8 Capacitor 0.1F 50V ceramic

x2

10.9 Capacitor 10F 16V electrolytic

x1

10.10 Diode 1N4148

x2

10.11 LED 3mm. Red

x 16

10.12 Tact switch

x4

10.13 Piezo Speaker 32

x1

10.14 RFID Rectangle Tag

x1

10.15 RFID 50mm Round Tag

x1

Easy RFID Education kit documentation

1


2. Main hardware information summary 2.1 i-Stamp2P microcontroller board  Features are compatible with the BASIC Stamp 2P 40 module (BS2P40-IC)  20MHz clock frequency. Operate up to 12,000 P-BASIC command/second  16KByte memory, separate 8 sections, 2KByte/each, erasable 100,000+ times  32 byte RAM with 64 byte Scratchpad RAM  Consumption of 65mA in full operation and 200A in sleep mode  Connecting to PC’s serial port for programming and debuging  32 I/O, freedom separeted work or set in groups from 4, 8 and 16 pins  30mA/30mA source/sink current. Maximum 60mA/60mA source/sink current per 8-pins groups (P0-P7/P8-P15/A0-A7/A8-A15)  LED power status  Board sizes 2.25" x 1.5"  Develop with BASIC Stamp Editor program

2.2 JX-2P plus Project board  Socket for i-Stamp2P (OEM BASIC Stamp2P40)  RJ-11 female connector for downloading and communication  +5V power supply on board  Free 24 of i-Stamp2P port (P0 to P15 and A0 to A7)  Provides in 3-pin JST connector for P0 to P7  3 of RC servo motor port (P13 to P15)  LCD module interfacing with brightness adjustment (LCD module 16x2 with cable is optional) connected with A9 to A15 of i-Stamp2P port.  DS18B20 1-wire Temperature sensor IC on-board (A8 port)  Prototype area 8.5x5.5 cm. with 200 soldering pad both 100mil (2.54mm.) spacing and 80mil (2.0mm.) spacing. Support the small beadboard (optional - sold sold separated)  Board size 9.5 x 13 cm.  2 of power supply terminals - For i-Stamp2P and any interfacing circuit; use the external power suypply such as DC adpator or battery 6 to12V 500mA (not include), on-board polarity protection circuit. Include the power switch and LED indicator. - For the servo motor; support 4.8 to 6Vdc. Use 2-pin terminal block and have the power swith with LED indicator.  Use with DC adaptor +12V 500mA, on-board polarity protection circuit.

2

Easy RFID Education kit documentation


TX RX ATN GND P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

GND RES +5V A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

PIN

NAME

FUNCTION

1

Tx/SOUT

Serial Out: connects to PC serial port RX pin (DB9 pin 2) for programming.

2

Rx/SIN

Serial In: connects to PC serial port TX pin (DB9 pin 3) for programming.

3

ATN

Attention: connects to PC serial port DTR pin (DB9 pin 4) for programming.

4

VSS/GND

System ground: (same as pin 23) connects to PC serial port GND pin (DB9 pin 5) for programming.

5-20

P0-P15

P0-P15 General-purpose I/O pins

21-36

A0-A15

A0-A15 General-purpose I/O pins

37

+5V

5-volt DC input

38

RES

Reset input/output: goes low

39

Vss/GND

40

N/A

System ground Not use

Figrure 1 : i-Stamp2P pin assignment

3. Introduction to i-Stamp2P microcontroller i-Stamp2P is the emulator of BS2P40-IC module which is designed by Innovative Experiment Co.,Ltd., Thailand under the co-operation with Parallax Inc., manufacturer BASIC Stamp from USA. The size is different from BS2P40-IC. i-Stamp2P requires 40-pin female header to fit on the board. The i-Stamp2P use BASIC Stamp interpreter licenced by Parallax Inc. Figure 1, shows i-Stamp2P pin assignment. It’s similar to BS2P40-IC. The only one different is i-Stamp2P no Vin pin because inside i-Stamp2P has not +5V regulator circuit. Figure 2 shows the schematic of i-Stamp2P. The heart of circuit is IC1 SX-48AC microcontroller. Inside this microcontroller contains PBASIC2P interpreter firmware. The users have already written PBASIC. The program is downloaded into i-Stamp2P via serial port. Opearing program is stored to IC2 which is 16KByte serial EEPROM 24LC128. It means IC2 is the system memory program. i-Stamp2P need +5V and at least 65mA supply from regulator. Users can just connect +5V and ground to i-Stamp2P and start working on it.

Easy RFID Education kit documentation

3


+5V

C6 0.1/63V +5V

4 C1

16

SOUT SIN ATN GND GND

RESET

C1-C5 10/25V

2

1

4 IC1 3 MAX232 5

C2 R1 4k7

27

20

19

26

19

33

25

18

47

24

17

23

16

22

15

21

14

20

13

17

12

16

11

15

10

14

9

13

8

12

7

11

6

10

5

45

36

44

35

43

34

C3

10

9

2

8

9

8

3

13

12

4

D1 1N4148

TxD RxD

1 MCLR R2 4k7

15

32

5

7

1

37

R3 150

6 C4

39

38 2

3 CR1 Ceramic Resonator 20MHz

IC2 SX48AC

+5V

2 1

A2 SDA A1 SCL

33

41

32

40

31

46

39

30

18

38

29

37

28

36

27

35

26

34

25

31

24

30

23

29

22

28

21

R4 4k7

8 3

BASIC Stamp 2P 42 Interpreter

5 6

6 7

A0 4

IC3 24LC128

SDA SCL

+5V P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

Figrure 2 : i-Stamp2P schematic diagram

4

Easy RFID Education kit documentation


LCD brightness Battery terminal for main circuit DC jack

To PC serial port

Vin

ON

LCD module connector RC servo supply terminal

LCD: A9-E,A10-RW A12-15 D4-D7 A11-RS

Power switch

Vs

i-Stamp2P

POW ER

ON

+Vs

BASIC Stamp2P OEM Board

Power switch for servo motor supply

Servo port C op yr i ght 2002 by I nnov at i v e E x per i m ent

P13 P12 P11

+Vs

RESET

A7 A6 A5 A4 A3 A2 A1 A0

+5V

0 1 2 3 4 5 6 7 8 9 101112131415

GND A8: DS18B20

RESET switch

DS18B20

+ 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

a b c d e f g

JX-2P plus i-Stamp2P Project board

Prototype area

h i j 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

+ -

-P0+

-P1+

-P2+

-P3+

-P4+

-P5+

-P6+

-P7+

P0 to P7 port with 3-pin of JST connector

Figrure 3 : JX-2P plus board layout; +5V is +5V regulated supply for main circuit, GND is system ground and +Vs is RC servo motor supply voltage. The i-Stamp2P is optional component (sold seprated)

Easy RFID Education kit documentation

5


K3 Battery input

+Vin 6-16V

IC1 2940-5.0

+ K4 +Vin DC input 7.5-16V

~ ~

C1 220 F 25V

C2 0.1F 63V

K5 SERVO supply

C4 47F 16V

SW1 POWER

+Vm

+Vm 6-7.2V

+5V LED1 POWER R1 510

C3 0.1F 63V

C8 2200F 10V

SW2 SERVO_POWER

LED1 POWER R3 1k

C7 0.1/50V

BD1 1A50V +5V 37 RxD TxD

C5 0.1/50V DTR C6 0.1/50V

K1 RS-232 (RJ-11 female)

1 2 3 4

+5V PORT

i-Stamp2P Socket

39

GND MCU port

38

S1 RESET

A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

A7 A6 A5 A4 A3 A2 A1 A0 +5V R2 2k2

1 2

P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 20 19 18 17 16 15 14 13 12 11 10

P15

P14

P13

P12

P11

P10

9

8

7

6

+5V

5

J1 P0 J2 P1

P9 P8 P7 P6 P5 P4 P3 P2 P1 P0

J3 P2

i-Stamp2P PORT

IC2 DS18B20

J4 P3

3

J5 P4

+5V D6 D4

VR1 BRIGHT.

RW

K2 UIC-LCD D5 D7

RS

J6 P5

DS18B20

J7 P6

+5V

E

J8 P7

GND DQ +V

P13 +Vm GND P14 +Vm GND P15 +Vm GND

+Vm

SERVO PORT

Figure 2 : JX-2P plus i-Stamp2P Project board schematic

4. Inside JX-2P plus : i-Stamp2P Project board JX-2P plus is the microcontroller project board that has become a standard for students, hobbyists, and even professional engineers. The board includes everything you need to get started with microcontroller applications at minimal expense . Just add your external circuits, code, and imagination. You can interface all components very easily. With the help of PBASIC programming you can understand about microcontroller interfacing concepts. Figure 3 shows the physical of JX-2P plus board and its schematic is shown in figure 4. SK1 is the 40-pin female header for support i-Stamp2P. +5V regulated voltage supply is connected to pin 21 of i-Stamp2P. Pin 22 connects with RESET switch to reset the operation of i-Stamp2P. For interfacing with serial port, use pin 1 to 4 connect with RJ-11 serial

6

Easy RFID Education kit documentation


connector. These interface are used for downloading and debugging via Debug Terminal in BASIC Stamp editor software. Some components are connected with i-Stamp2P auxiliary port. It includes LCD module and DS18B20 1-wire Temperature sensor. LCD module are assigned to connect with A9 to A15 port and A8 is connected with DS18B20. The JX-2P plus board supoprts the optiional power supply for high power circuit such as DC motor and Servo motor. +Vm is terminal for connecting with Motor supply voltage. The 6 to 7.2Vdc voltage is suitable for RC servo motor. Addition, the JX-2P plus board provides 3 servo ports. They are connected with P13, P14 and P15 of the main iStamp2P port. User can connect the servo motors direct to these connectors. If would not to use servo motor, +Vm terminal can support another DC power supply up to 9Vdc for supporting 4.5 to 9Vdc DC motors and small relays.

5. UCON-4 USB download cable driver installation Preparation of this kit requires the USB driver installation for UCON-4 download cable. Double click at the USBDriverInstallerV2.x.x.exe (x.x is number of version) file from the bundled CD-ROM to start the driver instalation. The installation dialogue-box will appear below.

Next, check the USB serial port address (1) Plug the UCON-4 cable to USB port. Wait a moment. Windows will be detect and prepare the suitable driver for this cable. (2) Check the Virtual COM port or USB Serial port address by clicking Start  Control Panel  System  Hardware  Device Manager

Easy RFID Education kit documentation

7


(3) See the list of USB serial port and remember the COM port address to work with UCON-4 cable. Normally it will create COM3 or higher. In this example is COM4

6. Software tools i-Stamp2P can work on the JX-2P plus Project board with BASIC Stamp editor software V2.39 or higher. This is free for download at www.parallax.com or see in the CD-ROM which bundled in the Easy RFID education kit. You can see after software installation, how to use and PBASIC command reference from BASIC Stamp editor m anual V2.0 or higher. This is free for download at www.parallax.com.

8

Easy RFID Education kit documentation


7. Getting start, Step by step (7.1) Put i-Stamp2P intothe 40-pin female header on the JX-2P plus board. You must put it in the right direction as shown in figure below.

(7.2) Connect the UCON-4 cable between the PC’s USB port and the JX-2P plus board. (7.3) Plug in the DC adaptor or 4 of AA battery pack for supplying voltage to the JX-2P plus Experiment board. Open the BASIC Stamp Editor software. (7.4) Check the communication between i-Stamp2P and the BASIC Stamp Editor software by pressing on the Ctrl I key or by clicking on the Identify button or by entering the RUN menu and then selecting Identify If all is done correctly,the Identification box will appear and show the version of PBASIC2SP chip as shown in the figure below. Observe COM4 box, it will show BASIC Stamp2P V1.x (x is any number). Now i-Stamp2P can connect with the BASIC Stamp Editor software.

Easy RFID Education kit documentation

9


(7.5) Make a simple program for testing. (7.5.1) Select the BASIC Stamp type by BASIC Stamp directive. Enter the Directive menu and select Stamp  BS2P. The message ‘{$STAMP BS2P} appears on first line. Press the Enter key. (7.5.2) At the Directive menu, select serial port by Port  Com4 (or any Com port that connect). Messge ‘{$PORT COM4} will appear at the second line. Pess Enter. (7.5.3) At Directive menu, select the version of PBASIC language by PBASIC  Version2.5. Message ‘{$PBASIC 2.5} will appear at the third line. Press Enter

(7.5.4) At programming area, type debug “welcome”. This short code iStamp2P send massage welcome to display on Debug Terminal of BASIC Stamp Editor. Press Enter. (7.5.5) Click Run button. Debug Terminal will appears and show message “welcome” on the screen.

(7.5.6) Press the RESET switch on the JX-2P plus board. The Debug Terminal screen repeats to show the same message. Because the RESET switch pressing means re-start the program running. (7.5.7) If dialogue box below is appeared, it means The communication between computer and i-Stamp is unsuccessful.

10

Easy RFID Education kit documentation


Check the UCON-4 cable and the status of USB serial port (created by Virtual COM port driver). This cable is used to connect between the computer’s USB port and the JX-2P plus board. The cable’s end uses a Modular plug RJ-11 6P4C (6-pins form and 4-contacts) Its Length is 1.5 meters approximation. The cable assignment is shown in the diagram below.

MCU_TxD MCU_RxD MCU_DTR GND

This cable requires +5V from USB port and support USB 1.0/2.0. User can set the baudrate up to 115,200 bit per second. Requires the driver installation before using. (7.5.8) All experiment PBASIC code of i-Stamp2P must be save in the filename extension .bsp

Easy RFID Education kit documentation

11


8. BASIC Stamp2P with starter experiment 8.1 Running light

i-Stamp2P

P15 R16

LED16

P14 R15

LED15

P13 R14

LED14

P12 R13

LED13

P11 R12

LED12

P10 R11

LED11

P9

R10

LED10

P8

R9

LED9

P7

R8

LED8

P6

R7

LED7

P5

R6

LED6

P4

R5

LED5

P3

R4

LED4

P2

R3

LED3

P1

R2

LED2

P0

R1

LED1

R1-R16 510 '****************************************** ' Connect P0-P15 to LED monitor '****************************************** ' {$STAMP BS2p} ' {PBASIC 2.5} X1 var NIB DIRS = $FFFF LOOP1 : outs = $0001 for X1 = 0 to 15 pause 500 outs = OUTS << 1 next goto LOOP1

12

Easy RFID Education kit documentation


8.2 Playing Note

i-Stamp2P

P0

C1 10ď ­F + -

SP1 PIEZO

FREQOUT generates one or two sine waves using a pulse-width modulation algorithm. The circuits in the figure below work by filtering out the high-frequency PWM used to generate the sine waves. FREQOUT works over a very wide range of frequencies so at the upper end of its range. '********************************************************** ' Program : note.bsp ' Make melody sounds on speaker ' Hardware : Connect Speaker to P0 '********************************************************** '{$STAMP BS2p} FREQ I C D E F G A B C1

VAR WORD VAR BYTE CON 278 CON 312 CON 350 CON 370 CON 416 CON 467 CON 524 CON 555

' ' ' ' ' ' ' ' '

Define Byte variable to keep frequency Define Byte variable to keep loop counter Note C Frequency Note D Frequency Note E Frequency Note F Frequency Note G Frequency Note A Frequency Note B Frequency ' Note C1 Frequency

OUTPUT 0 LOOP1: FOR I=0 TO 7 LOOKUP I,[C,D,E,F,G,A,B,C1],FREQ FREQOUT 0,1887,FREQ ' PAUSE 100 ' NEXT PAUSE 1000 GOTO LOOP1 '

Easy RFID Education kit documentation

' Read table 8 notes Make melody with duration 0.5 sec Delay 100 ms.

Goto loop

13


8.3 LCD Experiment

16x2 LCD module with cable

4 of AA battery or DC adaptor

The three LCD commands (LCDCMD, LCDIN and LCDOUT) allow the BS2p, BS2pe, or BS2px or i-Stamp2P to interface directly to standard LCD displays that feature a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16, and 4 x 20 character LCD displays. The Hitachi 44780 LCD controller supports a number of special instructions for initializing the display, moving the cursor, changing the default layout, etc. The LCDCMD command is used to send one of these instructions to the LCD. It is most commonly used to initialize the display upon a power-up or reset condition. Note that LCDCMD, LCDIN and LCDOUT use a 4-bit interface to the LCD which requires a specific initialization sequence before LCDIN and LCDOUT can be used. Specifics on the initialization sequence will follow.

14

Easy RFID Education kit documentation


'**************************************************************************************** ' Program: Show message ON LCD Module 16x2 ' Filename : lcd16x2.bsp ' Using 4 Bit mode interface, Connect D4-D7 TO A12-A15, RS TO A11, R/W TO A10 AND 'E TO A9 '**************************************************************************************** ' {$STAMP BS2p} ' {$PBASIC 2.5} ' {$PORT COM1} LCD_ PIN CHAR VAR Init_LCD: AUXIO PAUSE LCDCM PAUSE LCDCMD PAUSE LCDCMD PAUSE LCDCMD LCDCMD LCDCMD LCDCMD LCDCMD LCDCMD

9 Byte(16)

1000 LCD_, 5 LCD_, 1 LCD_, 1 LCD_, LCD_, LCD_, LCD_, LCD_, LCD_,

48

' allow LCD to power-up ' Send wake-up sequence (3x)

48 48 32 40 8 12 6 1

' ' ' ' '

' Set data bus to 4-bit mode Set 2-line mode with 5x8 font Turn display off Turn display on without cursor Auto-increment cursor Clear the display

Start: LCDOUT LCD_,1,["Hello!"] GOSUB ReadLCDScreen PAUSE 3000 LCDOUT LCD_,1,["I'm a 2x16 LCD!"] GOSUB ReadLCDScreen PAUSE 3000 GOTO Start ReadLcdScreen: DEBUG "LCD NOW Says:" LCDIN LCD_,128,[STR CHAR\16] DEBUG STR char\16,CR,CR RETURN

Easy RFID Education kit documentation

15


8.4 The 1-Wire Temperature sensor

Connect to the computer's serial port

4 of AA Battery or connect to DC adaptor

DS18B20

The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to ±0.5°C over the range of –10°C to +85°C. The 1-Wire protocol is a form of asynchronous serial communication developed by Maxim/Dallas Semiconductor. It only requires one I/O pin and that pin can be shared between multiple 1-Wire devices. The OWIN, OWOUT command allows the iStamp2P to receive data from a 1-Wire device.

16

Easy RFID Education kit documentation


' *************************************************** ' Filename : ds18b20.bsp ' Simple PC thermometer ' *************************************************** '{$STAMP BS2p} ' {$PBASIC 2.5} ' {$PORT COM1} Temp VAR Word 'Holds the temperature value TH VAR Byte TL VAR Byte Config VAR Byte Reserved1 VAR Byte Reserved2 VAR Byte Reserved3 VAR Byte CRC VAR Byte Point VAR Byte x VAR Word Start: AUXIO OWOUT 8, 1, [$CC, $44] 'Send Calculate Temperature command CheckForDone: 'Wait until conversion is done PAUSE 25 OWIN 8, 4, [Temp] 'Here we just keep reading low pulses until IF Temp = 0 THEN CheckForDone 'the DS1820 is done, then it returns high. OWOUT 8, 1, [$CC, $BE] 'Send Read ScratchPad command OWIN 8, 2, [Temp.LOWBYTE,Temp.HIGHBYTE,TH,TL,Config] ' Format Data ' S S S S S B6 B5 B4 : B3 B2 B1 B0 B-1 B-2 B-3 B-4 ' Convert LowByte To Point Temp = Temp & $0FFF DEBUG DEC temp/16,"." x =(Temp << 4) & $00ff x = 10000 */ x DEBUG DEC4 x,CR GOTO start

This PBASIC code demostrate the reading temperature from DS18B20 on the JX-2P plus board to display on the Debug Terminal of BASIC Stamp editor.

Easy RFID Education kit documentation

17


9. RFID Technology Overview Material in this section is based on information provided by the RFID Journal (www.rfidjournal.com). Radio Frequency Identification (RFID) is a generic term for non-contacting technologies that use radio waves to automatically identify people or objects. There are several methods of identification, but the most common is to store a unique serial number that identifies a person or object on a microchip that is attached to an antenna. The combined antenna and microchip are called an "RFID transponder" or "RFID tag" and work in combination with an "RFID reader" (sometimes called an "RFID interrogator"). An RFID system consists of a reader and one or more tags. The reader's antenna is used to transmit radio frequency (RF) energy. Depending on the tag type, the energy is "harvested" by the tag's antenna and used to power up the internal circuitry of the tag. The tag will then modulate the electromagnetic waves generated by the reader in order to transmit its data back to the reader. The reader receives the modulated waves and converts them into digital data. There are two major types of tag technologies. "Passive tags" are tags that do not contain their own power source or transmitter. When radio waves from the reader reach the chip’s antenna, the energy is converted by the antenna into electricity that can power up the microchip in the tag (typically via inductive coupling). The tag is then able to send back any information stored on the tag by modulating the reader’s electromagnetic waves. "Active tags" have their own power source and transmitter. The power source, usually a battery, is used to run the microchip's circuitry and to broadcast a signal to a reader. Due to the fact that passive tags do not have their own transmitter and must reflect their signal to the reader, the reading distance is much shorter than with active tags. However, active tags are typically larger, more expensive, and require occasional service. Frequency refers to the size of the radio waves used to communicate between the RFID system components. Just as you tune your radio to different frequencies in order to hear different radio stations, RFID tags and readers must be tuned to the same frequency in order to communicate effectively. RFID systems typically use one of the following frequency ranges: low frequency (or LF, around 125 kHz), high frequency (or HF, around 13.56 MHz), ultra-high frequency (or UHF, around 868 and 928 MHz), or microwave (around 2.45 and 5.8 GHz). The read range of a tag ultimately depends on many factors: the frequency of RFID system operation, the power of the reader, and interference from other RF devices. Balancing a number of engineering trade-offs (antenna size v. reading distance v. power v. manufacturing cost), the Parallax RFID Card Reader's antenna was designed specifically for use with low-frequency (125 kHz) passive tags with a read distance of around 4 inches.

18

Easy RFID Education kit documentation


10. About Parallax RFID reader - Serial Designed in cooperation with Grand Idea Studio (www.grandideastudio.com), the Parallax Radio Frequency Identification (RFID) Card Readers provide a low-cost solution to read passive RFID transponder tags up to 4 inches away. The RFID Card Readers can be used in a wide variety of hobbyist and commercial applications, including access control, user identification, robotics navigation, inventory tracking,

SOUT GND

VCC

/ENABLE

idea studio

GRAND

payment systems, car immobilization, and manufacturing automation.

10.1 Features  Low-cost method for reading passive, 125 kHz RFID transponder tags  Serial interface for microcontrollers  Bi-color LED for visual indication of status

Easy RFID Education kit documentation

19


10.2 RFID Compatibility The Parallax RFID Card Reader works exclusively with the EM Microelectronics EM4100-family of passive read-only transponder tags. Each transponder tag contains a unique, read-only identifier (one of 240, or 1,099,511,627,776 possible combinations).

10.3 Connections (Serial) The Parallax RFID Card Reader Serial version easily interfaces to any host microcontroller using only four connections (VCC, /ENABLE, SOUT, GND).

Pin Pin Name

Type

Function

1

VCC

power

System power. +5Vdc input.

2

/ENABLE

input

Module enable pin. Active LOW digital input. Bring this pin LOW to enable the RFID reader and activate the antenna.

3

SOUT

output

Serial output to host. TTL-level interface, 2400 bps, 8 data bits, no parity, 1 stop bit.

4

GND

power

System ground. Connect to power supply’s ground (GND) terminal.

Use the following example circuit for connecting the Parallax RFID Card Reader:

+5V GRAND idea studio

OE OUT

20

VCC /ENABLE

SOUT GND

Easy RFID Education kit documentation


10.4 Usage A visual indication of the state of the RFID Card Reader is given with the onboard LED. When the module is successfully powered-up and is in an idle state, the LED will be GREEN. When the module is in an active state searching for or communicating with a valid tag, the LED will be RED. The RFID Card Reader Serial is activated via the /ENABLE pin on the module’s 4pin header. When the RFID Card Reader is powered and /ENABLE is pulled LOW, the module will enter the active state. When /ENABLE is pulled HIGH or left unconnected, the module will enter the idle state. The face of the RFID tag should be held parallel to the front or back face of the antenna (where the majority of RF energy is emitted). If the tag is held sideways (for example, perpendicular to the antenna), you’ll either get no reading or a poor reading distance. Only one transponder tag should be held up to the antenna at any time. The use of multiple tags at one time will cause tag collisions and the reader may not detect any of them. The tags available in the Parallax store have a read distance of approximately 4 inches. Actual distance may vary slightly depending on the size of the transponder tag and environmental conditions of the application.

10.5 Communication Protocol All communication is 8 data bits, no parity, 1 stop bit, and least significant bit first (8N1) at 2400 bps. The RFID Card Reader Serial version transmits data as 5V TTL-level, noninverted asynchronous serial. When the RFID Card Reader is active and a valid RFID transponder tag is placed within range of the activated reader, the tag’s unique ID will be transmitted as a 12-byte printable ASCII string serially to the host in the following format: Start Byte Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Unique ID Stop Byte (0x0A) Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 Digit 6 Digit 7 Digit 8 Digit 9 Digit 10 (0x0D)

The start byte and stop byte are used to easily identify that a correct string has been received from the reader (they correspond to line feed and carriage return characters, respectively). The middle ten bytes are the actual tag's unique ID. For example, for a tag with a valid ID of 0F0184F07A, the following bytes would be sent: 0x0A, 0x30, 0x46, 0x30, 0x31, 0x38, 0x34, 0x46, 0x30, 0x37, 0x41, 0x0D.

Easy RFID Education kit documentation

21


11. RFID basic experiment with i-Stam2P (BASIC Stamp2P40 OEM board) 11.1 Component list 1. RFID reader Serial version 2. RFID tag card 3. RFID tag circle 4. i-Stamp2P with JX-2P plus project board 5. UCON-4 download cable 6. IDC1MF 4 wires 7. 16x2 LCD module with cable 8. DC adaptor (+6 to +12Vdc 500mA)

11.2 Experiment 1 : Simple reading the RFID tag (1.1) Connect RFID reader with the JX-2P plus board following figure 11-1 - Connect the /Enable pin of the RFID reader with P0 of i-Stamp2P - Connect the SOUT pin of the RFID reader with P1 of i-Stamp2P - Connect the VCC pin of the RFID reader with +5V on JX-2P plus board - Connect the GND pin of the RFID reader with GND or Ground of the JX-2P plus board (1.2) Open the BASIC Stamp editor

22

Easy RFID Education kit documentation


+12Vdc adaptor

+ Vin

ON

6-12Vdc

SERIAL

Connect to the computer's USB port via UCON-4 cable

LCD : A9-E, A10-RW, A12-A15 D4-D7 A11-RS

Vs POWER

ON

idea studio

P13 P12 P11

RESET

P0

+5V

A7 A6A5 A4 A3 A2A1 A0

0 1 2 3 4 5 6 7 8 9 1011 12 1314 15

GND

DS18B20

SOUT GND

/ENABLE

+Vs

VCC

GRAND

+Vs

P1

Figure 11-1 : RFID reader experiment 1 connection diagram

Easy RFID Education kit documentation

23


' {$STAMP BS2p} ' {$PBASIC 2.5} char_rfid VAR Byte (10) ' Declare the ID variable 10 bytes Main: LOW 0 ' Force Enable pin as low SERIN 1, 1021, [WAIT($0A),STR char_rfid\10] ' Read data from RFID reader from P1 ' and store 10-byte of ID to the char_rfid array variable. ' The first byte must be 0A Show_Tag: DEBUG "Tag ID: ", STR char_rfid DEBUG CR PAUSE 1000 GOTO Main END

' Show ID on the Debug Terminal ' Next line ' Do again

Listing 11-1 : RFID_ReadTerminal.bsp; Read the RFID tag card to show on the Debug terminal (1.3) Type the code following List 11-1 (1.4) Download the code to i-Stamp2P by clicking the RUN button or press the key CTRL+R. The Debug Terminal is opened. Choose the interfaced COM port. (1.5) Place the RFID tag card over the RFID reader at antenna side. See the results on the Debug Terminal window The Debug Terminal displays the ID of RFID tag below :

24

SOUT GND

/ENABLE

VCC

idea studio

GRAND

RFID tag Front side

Easy RFID Education kit documentation


(1.6) Change the RFID tag card to RFID tag circle and try again following the step

Easy RFID Education kit documentation

SOUT GND

/ENABLE

idea studio

VCC

GRAND SOUT GND

/ENABLE

idea studio

VCC

GRAND

(1.5)

25


11.3 Experiment 2 : Simple reading the RFID tag to show on LCD (2.1) Connect RFID reader with the JX-2P plus board following figure 11-2 - Connect the /Enable PIN of the RFID reader with P0 of i-Stamp2P - Connect the SOUT PIN of the RFID reader with P1 of i-Stamp2P - Connect the VCC of the RFID reader with +5V on JX-2P plus board - Connect the GND of the RFID reader with GND or Ground of the JX-2P plus board (2.2) Plug the LCD module with cable to LCD connector on the JX-2P plus board (2.3) Open the BASIC Stamp editor

+12Vdc adaptor

+ Vin

ON

6-12Vdc

SERIAL

Connect to LCD16x2

LCD : A9-E, A10-RW, A12-A15 D4-D7 A11-RS

Vs POWER

ON

idea studio

GRAND

+Vs

P13 P12 P11

RESET

P0

+5V

A7A6A5 A4 A3A2 A1 A0

0 1 2 3 4 5 6 7 8 9 1011 121314 15

GND

DS18B20

SOUT GND

/ENABLE

VCC

+Vs

P1

Figure 11-2 : RFID reader experiment 2 connection diagram

26

Easy RFID Education kit documentation


' {$STAMP BS2p} ' {$PBASIC 2.5} char_rfid VAR Byte (10) LOW 0 ' Send “0” to Enable pin of RFID reader AUXIO ' Change to AUX port Init_LCD: PAUSE 1000 LCDCMD 9, %00110000 PAUSE 5 LCDCMD 9, %00110000 PAUSE 0 LCDCMD 9, %00110000 PAUSE 0 LCDCMD 9, %00100000 LCDCMD 9, %00101000 LCDCMD 9, %00001100 LCDCMD 9, %00000110 LCDCMD 9, %00000001

' Initial LCD

' ' ' ' '

Set data bus to 4-bit mode Set to 2-line mode with 5x8 font Display on without cursor Auto-increment cursor Clear the display

Main: MAINIO ' Switch to Main port SERIN 1, 1021, [WAIT($0A),STR char_rfid\10] ' Read data from RFID reader from P1 ' and store 10-byte of ID to the char_rfid array variable. ' The first Byte must be 0A AUXIO ' Switch to AUX port LCDOUT 9, 1, [STR char_rfid] ' Show ID on LCD screen GOTO MAIN END

Listing 11-2 : RFID_ReadLCD.bsp; Read the RFID tag card and display on the 16x2 LCD module (2.4) Type the code following Listing 11-2 (2.5) Download the code to i-Stamp2P by clicking the RUN button or press the key CTRL+R. (2.6) Place the RFID tag card over the RFID reader at antenna side. See the results on the LCD module screen. The LCD module will show the ID below on the line 1 :

0414E50079 (2.7) Change the RFID tag card to RFID tag circle and try again following the step (2.6)

Easy RFID Education kit documentation

27


11.4 Experiment 3 : Test range reading of the RFID reader with any direction (3.1) Still use the connection diagram of figure 11-3 and using the code from Listing 11-3 (3.2) Open the BASIC Stamp editor (3.3) Type the code following Lisiting 11-3 (3.4) Download the code to i-Stamp2P by clicking the RUN button or press the key CTRL+R.

+12Vdc adaptor

+ Vin

ON

6-12Vdc

SERIAL

Connect to LCD16x2

LCD : A9-E, A10-RW, A12-A15 D4-D7 A11-RS

Vs POWER

ON

idea studio

P13 P12 P11

RESET

+5V

A7 A6A5A4 A3 A2 A1 A0

0 1 2 3 4 5 6 7 8 9 1011 12 1314 15

DS18B20

SOUT GND

/ENABLE

+Vs

VCC

GRAND

+Vs

GND

10ď ­ F + 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

a

a

b

b

c

c

d

d

e

e

piezo speaker f

f

g

g

P0

P1

h

h

i

i

j

j 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

+

Figure 11-3 : RFID reader experiment 3 connection diagram

28

Easy RFID Education kit documentation


+5V

GND

SOUT ENABLE VCC

RFID reader

+5V 6 E 5 RW

A9 A10 P0

4

A11

+V 2 Vo 3 G 1

RS

VR1 10k

D0 D1 D2 D3 D4 D5 D6 D7 7 8 9 10 11 12 13 14

i-Stamp2P P1 A12 A13 A14 A15 C1 10ď ­F P4

SP1 PIEZO SPEAKER

Figure 11-4 : RFID reader experiment 3 schematic diagram '************************************************************* ' RFID_ReadTest.bsp ' Detect and read RFID tag and drive sound with piezo speaker '************************************************************* ' {$STAMP BS2p} ' {$PBASIC 2.5} char_rfid VAR Byte (10) LOW 0 ' Send "0" to Enable pin of RFID reader AUXIO ' Change to AUX port Init_LCD: PAUSE 1000 LCDCMD 9, %00110000 ' Initial LCD PAUSE 5 LCDCMD 9, %00110000 PAUSE 0 LCDCMD 9, %00110000 PAUSE 0 LCDCMD 9, %00100000 ' Set data bus to 4-bit mode LCDCMD 9, %00101000 ' Set to 2-line mode with 5x8 font LCDCMD 9, %00001100 ' Display on without cursor LCDCMD 9, %00000110 ' Auto-increment cursor LCDCMD 9, %00000001 ' Clear the display Main: MAINIO SERIN 1, 1021, [WAIT($0A),STR char_rfid\10] FREQOUT 4,1000,1000 ' Output sound on port 4 AUXIO ' Switch to AUX port LCDOUT 9, 1, [STR char_rfid] ' Show ID on LCD screen PAUSE 2000 GOTO Main END

Listing 11-3 : RFID_ReadTest.bsp; Read the RFID tag card to show on the 16x2 LCD module and drive a beep signal.

Easy RFID Education kit documentation

29


(3.5) Place the RFID tag card over the RFID reader at antenna side. See the results on the LCD module screen.

SOUT GND

/ENABLE

idea studio

VCC

GRAND

RFID tag Front side

The LCD module will show the ID below on the line 1 :

0414E50079 and the piezo speaker drives a beep signal on every reading.

SOUT GND

/ENABLE

VCC

idea studio

GRAND

(3.6) Place the RFID tag circler over the RFID reader at antenna side. See the results on the LCD module screen.

The LCD module will show the ID of RFID tag circle (must different the RFID tag card) below on the line 1 :

0F02A68691 and the piezo speaker drives a beep signal on every reading.

30

Easy RFID Education kit documentation


(3.7) Back to use the RFID tag card. Move the card far from RFID reader until does not detect the RFID tag. Record the distance.

RFID tag Front side

Front side Back side

RFID tag adjust distance

Antenna side

SOUT GND

/ENABLE

idea studio

VCC

GRAND

RFID reader

Maximum operation distance is during 5 to 6cm. (3.8) Flip the RFID tag . The back side is over the RFID reader. See the ID on the LCD module annd move the RFID tag far from RFID reader until does not detect the RFID tag. Record the distance.

RFID tag Back side

Back side Front side

RFID tag adjust distance

Antenna side

SOUT GND

/ENABLE

idea studio

VCC

GRAND

RFID reader

Maximum operation distance is during 5 to 6cm. Summary is that the RFID reader can detect and read any side of the RFID tag card.

Easy RFID Education kit documentation

31


(3.9) Turn the RFID tag long edge over the RFID reader 3 positions following the figure below. Moving the tag is required to the RFID reader detects the tag.

RFID tag Front side

SOUT GND

/ENABLE

VCC

SOUT GND

/ENABLE

idea studio

GRAND

RFID tag

idea studio

GRAND

RFID tag

VCC

SOUT GND

/ENABLE

idea studio

VCC

GRAND

RFID tag

RFID tag Back side

adjust distance

adjust distance

Antenna side

Antenna side

RFID reader

RFID reader

The RFID reader cannot detect the tag in this direction.

32

Easy RFID Education kit documentation


(3.10) Turn the RFID tag short edge over the RFID reader 3 positions following the figure below. Moving the tag is also required to the RFID reader detects the tag.

RFID tag RFID tag

SOUT GND

RFID tag Back side

/ENABLE

idea studio

GRAND

VCC

SOUT GND

/ENABLE

RFID tag Front side

VCC

idea studio

GRAND SOUT GND

/ENABLE

idea studio

VCC

GRAND

RFID tag

adjust distance

adjust distance

Antenna side

Antenna side

RFID reader

RFID reader

The RFID reader also cannot detect the tag in this direction. Summary, RFID reader cannot detect and read the edge of the card. The best result reading are front and back sides orientation of RFID tag card.

Easy RFID Education kit documentation

33


Front side Back side

SOUT GND

/ENABLE

VCC

idea studio

GRAND SOUT GND

/ENABLE

VCC

idea studio

GRAND

(3.11) Change to the RFID tag circle. Move the tag far from RFID reader until does not detect the RFID tag. Record the distance. Try with both side of tag.

Back side Front side

RFID circle tag adjust distance

Antenna side

Antenna side

RFID reader

RFID reader

RFID circle tag adjust distance

Maximum operation distance is during 6 to 7cm. Summary : 1. The RFID reader can detect and read the RFID tag circle with any flat side. 2. The operation range of RFID reader is same with any flat side of RFID tag card.

34

Easy RFID Education kit documentation


RFID tag circle

B

RFID tag circle

SOUT GND

/ENABLE

idea studio

GRAND

C

VCC

SOUT GND

/ENABLE

VCC

idea studio

GRAND SOUT GND

/ENABLE

idea studio

VCC

GRAND

A

RFID tag circle

(3.12) Place the RFID tag over the RFID reader by edge side 3 positions following the figure below. Moving the tag is required to the RFID reader detects the tag.

adjust distance Antenna side RFID reader

The RFID reader detects and reads RFID tag circle only position A and C. Range is similar at 2 to 2.5cm. RFID reader does not detect the RFID tag circle in postion B.

Easy RFID Education kit documentation

35


(3.13) Change the direction of the RFID tag from step (3.12) following the figure below. Try to detect 3 positions. Moving the tag is required till the RFID reader detects the tag.

RFID tag circle

A

RFID tag circle

C GRAND

SOUT GND

/ENABLE

idea studio

RFID tag circle

VCC

SOUT GND

/ENABLE

idea studio

GRAND

VCC

SOUT GND

/ENABLE

idea studio

VCC

GRAND

B

RFID tag circle

adjust distance Antenna side RFID reader

The RFID reader detects and reads RFID tag circle only position A and C. Range is similar at 2 to 2.5cm. The RFID reader does not detect the RFID tag circle in postion B. The position B is out of antenna area. Summary : 1. The RFID reader cannot detect and read the ID from RFID tag circle when the tag located out of antenna area. 2. The operation range of RFID reader is decreased with edge side of the RFID tag circle.

36

Easy RFID Education kit documentation


(3.14) Place the RFID tag card over the RFID reader at antenna side and insert some medium between the tag and RFID reader. Test the operation. The medium includes a piece of papaer, wood with 3mm. thickness and plastic sheet with 3mm. thickness.

RFID tag Front side RFID tag Front side

RFID tag

SOUT GND

idea studio

GRAND

A piece of plastic (3mm. thick)

VCC

SOUT GND

idea studio

VCC

SOUT GND

/ENABLE

/ENABLE

GRAND

A piece of wood (3mm. thick)

idea studio

VCC

GRAND

A piece of paper

RFID tag Front side RFID tag Front side

/ENABLE

RFID tag Front side RFID tag Front side

RFID tag a piece of paper

RFID tag wood (3mm.)

2 to 3cm.

plastic (3mm.)

2 to 3cm.

2 to 3cm.

Antenna side

Antenna side

Antenna side

RFID reader

RFID reader

RFID reader

The operation of RFID reader is same. The medium paper, wood and plastic also are not effect the detection if the thickness are not more than the operation range.

Easy RFID Education kit documentation

37


12. RFID logger This example project is about how to use RFID reader and i-Stamp2P to build a simple ID logger system. This project required the database software for collecting the ID data from any RFID tag. We choose AppServ 2.5.10; the free software of Web server to create the data server in the computer and create the control software from Visual BASIC 2010 express to manage the system.

12.1 AppServ software installation AppServ 2.5.10 is free software. Download from http://prdownloads.sourceforge. net/appserv/appserv-win32-2.6.0.exe?download. Install the software following these step : (12.1.1) Double click the setup file; appserv-win32-2.5.10.exe to start the installation. Click on the Next button.

(12.1.2) Choose components and click on the Next button.

38

Easy RFID Education kit documentation


(12.1.3) Put name localhost into the Server Name box and fill the email address into the Administrator Email box. Click on the Next button.

(12.1.4) Set password for ID root. It is ID for server and database administrator. Click on the Install button.

(12.1.5) After installation is completed, select Start Apache and Start MySQL for starting the operation of Web Server and database management software.

Easy RFID Education kit documentation

39


12.2 Database preparation Purpose is making the database table of check-in time and check-out time of employee. (1 2. 2.1 ) O p e n t h e In t e rn e t Exp lo re r. Bro w se t o a d d re ss http://localhost/

phpMyAdmin/ . The authentication window is appeared. Fill the ID or User name with root and fill password such as 1234 or another setting from installation steps.

(12.2.2) The new database is created. Put the name db_employee into Create new database box following click on the Create button.

40

Easy RFID Education kit documentation


(12.2.3) Make the database table following these procedures : (12.2.3.1) Se t the na m e a s tb_in for storing the ID data, date and check-in

time of employee (12.2.3.2) Set the Number of Fields as 3 (12.2.3.3) Click on the Go button

(12.2.4) Set name and parameter of data filed as follows : -id_in field, type is VARCHAR and length is 10 ; choose as Primary -time_in field, type is TIME choose as Primary -date_in field, type is DATE and choose as Primary. Click on the Save button.

Easy RFID Education kit documentation

41


(12.2.5) After the tb_in table is created, the message “Table 'db_employee'.'tb_in' has been created� is appeared in the yellow box. In the SQL quiery box shows all instructions for creating the table of database and structure. At the left menu; it shows the database name and number of data table.

(12.2.6) Click on the db_employee(1). The browser will display the new page for creating the new table. Create the table for storing the ID data, date and check-out time of employee similar the step 12.2.3. Set the name and parameter as follows : (12.2.6.1) Set the name as tb_out (12.2.6.2) Set the Number of Fields as 3 and click on the Go button.

42

Easy RFID Education kit documentation


(12.2.7) Set name and parameter of data filed as follows : - id_out field, type is VARCHAR and length is 10. Choose as Primary.

- time_out field, type is TIME and choose as Primary. - date_out field, type is DATE and choose as Primary. Click on the Save button.

(12.2.8) After the tb_out table is created, the message "Table 'db_employee'.'tb_out' has been created" is appeared in the yellow box. In the SQL quiery box shows all instructions for creating the table of database and structure. At the left menu; it shows the database name and number of data table. Now there are 2 tables.

Easy RFID Education kit documentation

43


12.3 MySQL driver installation Before accessing the database with MySQL, you will need to install MySQL ODBC 3.51 Driver. Download at http://dev.mysql.com/downloads/connector/odbc/3.51.html

(12.3.1) Double click on the installation file; mysql-connector-odbc-3.51.30-winx64.msi. Welcome window is appeared.

(12.3.2) Click on the Next button of each step until the installation is started. After the installation is completed, the database system is prepared already.

44

Easy RFID Education kit documentation


12.4 Database programming with Visual BASIC Express 2010 Next step is creating the software for connecting with database by Visual BASIC Express 2010. (12.4.1) Open the VB Express 2010. Create the New project.

(12.4.2) Set the project name as RFIDLogger. Click on the OK button.

Easy RFID Education kit documentation

45


(12.4.3) Drag and drop all controls and buttons and set the name of any element following the picture below.

 Label1 : Label for displaying the message “Available Com Ports”  cbbCOMPorts : Combobox for choosing the COM port that connect with RFID reader system.  btnConnect : Button for displaying the message “Connect” after open the COM port.  btnDisConnect : Button for displaying the message “Disconnect” after close the COM port..  btnSearch : Button for displaying the message “Search”. It is button for searching the employee code  txtSearch : TextBox for filling the employee ID to searching  btnPrint : Button for displaying the message “Print” after print text in rtxtDataReceived  txtDataReceived : RichTextBox for showing ID data and working time of employee  lblMessage : Label of RFID reader system interfacing status.  txtRFIDData : TextBox for showing the employee data of RFID tag reading.  Printdialog : Printdialog for opening the Printing dialog box.  PrintDocument1 : PrintDocument control for printing out the data to printer.

46

Easy RFID Education kit documentation


(12.4.4) Enter to Form1.vb to write the code by clicking on the View Code button

(12.4.5) Type the code for Class Form1 and subprogram Form1_Load as followings : Imports System.Data.Odbc Imports System.Drawing.Printing Public Class Form1 Dim WithEvents serialPort As New IO.Ports.SerialPort Dim x As String = "" 'save value form serial port Dim command As New OdbcCommand 'command for insertSQL string contains a SQL statement that Dim reader As OdbcDataReader 'for execute command sql Dim MyConString As String 'string value for connect mysql Dim num As Integer 'save row sql execute Dim MyConnection As New OdbcConnection 'MyConnection value connect mysql Dim strsql As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'connect mysql MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=db_employee;" + "UID=root;" + "PASSWORD=1234;" + "OPTION=3;" MyConnection.ConnectionString = MyConString MyConnection.Open() 'check port connect and add value on cbbCOMPorts For i As Integer = 0 To _ My.Computer.Ports.SerialPortNames.Count - 1 cbbCOMPorts.Items.Add(_My.Computer.Ports.SerialPortNames(i)) Next btnDisconnect.Enabled = False End Sub End Class

Easy RFID Education kit documentation

47


The Database connection code below are setting the default database authentification. MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=db_employee;" + "UID=root;" + "PASSWORD=1234;" + "OPTION=3;" MyConnection.ConnectionString = MyConString MyConnection.Open()

Data in the MyConString is default data from installation. It includes : “SERVER=localhost;” : Assign the server name “DATABASE=db_employee;” : Assign the database name “UID=root;” : Assign the database ID “PASSWORD=1234;” : Assign the password (12.4.7) Double click on the btnConnect button to make the code in subprogram btnConnect_Click as follows: Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click If serialPort.IsOpen Then serialPort.Close() End If Try 'set serial port number With serialPort .PortName = cbbCOMPorts.Text .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With serialPort.Open() ' open serialport lblMessage.Text = cbbCOMPorts.Text & " connected." 'change text of label btnConnect.Enabled = False 'btnConnect disable click btnDisconnect.Enabled = True 'btnDisconnect enable click Catch ex As Exception MsgBox(ex.ToString) End Try End Sub

(12.4.8) Double click on the btnDisconnect button to add the code in subprogram btnDisconnect_Click as follows : Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click Try ' close serailport serialPort.Close() lblMessage.Text = serialPort.PortName & " disconnected." ' change text of label btnConnect.Enabled = True ' btnConnect enable click btnDisconnect.Enabled = False ' btnDisconnect disable click Catch ex As Exception MsgBox(ex.ToString) End Try End Sub

48

Easy RFID Education kit documentation


(12.4.9) Add subprogram for receiving the serial data from COM port and show data at TextBox1 : Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived ' update data go to updateTextBox rtxtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub

(12.4.10) After getting the ID from COM port, transfers data to the updateTextBox to compare the ID database in the tb_in table. The data is current date. If found the data, system will find more in the tb_out table. If found; it means this data is completed. No add the data. In the other hand, if there is not data in each table data; system will add the current data in the table. Store in the database and show the reading ID on the TextBox1. The code is as follows : Public Delegate Sub myDelegate() Public Sub updateTextBox() Dim currentSystemTime As DateTime = DateTime.Now 'date and time now x = x + serialPort.ReadExisting 'save data form serialport in x If x.Length >= 10 Then 'check length data >=10 ok x.Substring(0, 10) 'substring 0-10 'select input with database for check in or out strsql = "select * from tb_in where id_in='" + x + "' and date_in='" + currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "'" 'execute sql command command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected If num <= 0 Then ' if no check in insert data in tb_in strsql = "INSERT INTO tb_in VALUES (‘" + x + "‘, ‘" + currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + "‘, ‘" + currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "')" TextBox1.Text = "In " + x + " " + currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + " " + currentSystemTime.Date Else ' if check out select check out strsql = "select * from tb_out where id_out='" + x + "' and date_out='" + currentSystem Time .Yea r.To Stri ng + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "‘" command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected If num <= 0 Then ' insert data in tb_out strsql = “INSERT INTO tb_out VALUES ('" + x + "', ‘" + currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + "', ‘" + currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString +"-" + currentSystemTime.Day.ToString + "')"

Easy RFID Education kit documentation

49


TextBox1.Text = "Out " + x + " " + currentSystemTime. TimeOfDay.ToString.Substring(0, 8) + " " + currentSystemTime.Date Else TextBox1.Text = x & " Cannot add more data" End If End If 'execute sql command command = New OdbcCommand(strsql, MyConnection) command.ExecuteReader() x = "" 'clear value x End If End Sub

(12.4.11) Double click on the btnSearch button. Add the following code into subprogram btnSearch_Click. Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click 'execute sql select value input in db_employee strsql = "SELECT tb_in.id_in as Id ,tb_in.date_in as date ,tb_in.time_in as In_time ,tb_out.time_out as Out_time FROM tb_in,tb_out WHERE tb_in.id_in=’" + txtSearch.Text + "‘ and tb_in.id_in=tb_out.id_out and tb_in.date_in=tb_out.date_out ORDER BY date DESC " command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected ' no value in database If num <= 0 Then rtxtDataReceived.Text = "Can not Search Value Input" ' have value in database Else rtxtDataReceived.Clear() 'clear rich text rtxtDataReceived.AppendText(" ID Date Time_In Time_out" + Environment.NewLine) ‘print value on richtext While (reader.Read()) 'next row rtxtDataReceived.AppendText(reader.GetValue(0).ToString + " " + reader.GetValue(1).ToString.Substring(0, 9) + " " + reader.GetValue(2).ToString + " " + reader.GetValue(3).ToString + Environment.NewLine) End While End If End Sub

To searching data from the txtSearch; use select instruction and select only id, date, time_in and time_out. Search in both table ; tb_in and tb_out by using the same date and same ID. After that, display the searching ID with reader.Read() instruction in row and reader.GetValue(0).ToString to select the message in each column. Includes : id, date, time_in and time_out. (column 0, 1, 2 and 3 respectively)

50

Easy RFID Education kit documentation


(12.4.12) Double click on the btnPrint button to make the addition code in subprogram ; btnPrint_Click as follows : Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click ' Allow the user to choose the page range he or she would like to print. PrintDialog1.AllowSomePages = True 'Show the help button. PrintDialog1.ShowHelp = True ' Set the Document property to the PrintDocument for ' which the PrintPage Event has been handled. To display the ' dialog, either this property or the PrinterSettings property ' must be set PrintDialog1.Document = PrintDocument1 Dim result As DialogResult = PrintDialog1.ShowDialog() 'show dialog print If result = DialogResult.OK Then ‘ If the result is OK then print the document. PrintDocument1.Print() End If End Sub ' The PrintDialog will print the document ' by handling the document’s PrintPage event. Private Sub document_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage ' Insert code to render the page here. ' This code will be called when the control is drawn. ' The following code will render a simple message on the printed document. ' Dim text As String = "In document_PrintPage method." Dim printFont As New System.Drawing.Font(“Arial”, 22, System.Drawing.FontStyle.Regular) ' Draw the content. e.Graphics.DrawString(rtxtDataReceived.Text, printFont, System.Drawing.Brushes.Black, 10, 10) End Sub

(12.4.13) The complete code is shown in the Listing 12-1. Run the code. The main window of this code is shown in the figure 12-1

Figrue 12-1 RFID logger program

Easy RFID Education kit documentation

51


Imports System.Data.Odbc Imports System.Drawing.Printing Public Class Form1 Dim WithEvents serialPort As New IO.Ports.SerialPort Dim x As String = "" ' save value form serial port Dim command As New OdbcCommand ' command for insertSQL string contains a SQL statement that Dim reader As OdbcDataReader ' for execute command sql Dim MyConString As String ' string value for connect mysql Dim num As Integer ' save row sql execute Dim MyConnection As New OdbcConnection ' MyConnection value connect mysql Dim strsql As String P r i v ate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' connect mysql MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=db_employee;" + "UID=root;" + "PASSWORD=1234;" + "OPTION=3;" MyConnection.ConnectionString = MyConString MyConnection.Open() 'check port connect and add value on cbbCOMPorts For i As Integer = 0 To _ My.Computer.Ports.SerialPortNames.Count - 1 cbbCOMPorts.Items.Add(_My.Computer.Ports.SerialPortNames(i)) Next btnDisconnect.Enabled = False End Sub Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click If serialPort.IsOpen Then serialPort.Close() End If Try 'set value serialport for connect With serialPort .PortName = cbbCOMPorts.Text .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One End With serialPort.Open() ' open serialport lblMessage.Text = cbbCOMPorts.Text & " connected." 'change text of label btnConnect.Enabled = False 'btnConnect disable click btnDisconnect.Enabled = True 'btnDisconnect enable click Catch ex As Exception MsgBox(ex.ToString) End Try End Sub

Listing 12-1 : Source code of the RFID Logger program. This code is written by Visual BASIC Express 2010 (continue)

52

Easy RFID Education kit documentation


Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click Try ' close serailport serialPort.Close() lblMessage.Text = serialPort.PortName & " disconnected." ' change text of label btnConnect.Enabled = True ' btnConnect enable click btnDisconnect.Enabled = False ' btnDisconnect disable click Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click 'execute sql select value input in db_employee strsql = "SELECT tb_in.id_in as Id ,tb_in.date_in as date ,tb_in.time_in as In_time ,tb_out.time_out as Out_time FROM tb_in,tb_out WHERE tb_in.id_in=’" + txtSearch.Text + "‘ and tb_in.id_in=tb_out.id_out and tb_in.date_in=tb_out.date_out ORDER BY date DESC " command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected ' no value in database If num <= 0 Then rtxtDataReceived.Text = "Can not Search Value Input" ' have value in database Else rtxtDataReceived.Clear() 'clear rich text rtxtDataReceived.AppendText(" ID Date Time_In Time_out" + Environment.NewLine) ‘print value on richtext While (reader.Read()) 'next row rtxtDataReceived.AppendText(reader.GetValue(0).ToString + " " + reader.GetValue(1).ToString.Substring(0, 9) + " " + reader.GetValue(2).ToString + " " + reader.GetValue(3).ToString + Environment.NewLine) End While End If End Sub Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click ' Allow the user to choose the page range he or she would like to print. PrintDialog1.AllowSomePages = True 'Show the help button. PrintDialog1.ShowHelp = True ' Set the Document property to the PrintDocument for ' which the PrintPage Event has been handled. To display the ' dialog, either this property or the PrinterSettings property ' must be set PrintDialog1.Document = PrintDocument1 Dim result As DialogResult = PrintDialog1.ShowDialog() 'show dialog print If result = DialogResult.OK Then ‘ If the result is OK then print the document. PrintDocument1.Print() End If End Sub

Listing 12-1 : Source code of the RFID Logger program. This code is written by Visual BASIC Express 2010 (continue)

Easy RFID Education kit documentation

53


' The PrintDialog will print the document ' by handling the document’s PrintPage event. Pr iv ate Sub document_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage ' Insert code to render the page here. ' This code will be called when the control is drawn. ' The following code will render a simple message on the printed document. ' Dim text As String = "In document_PrintPage method." Dim printFont As New System.Drawing.Font(“Arial”, 22, System.Drawing.FontStyle.Regular) ' Draw the content. e.Graphics.DrawString(rtxtDataReceived.Text, printFont, System.Drawing.Brushes.Black, 10, 10) End Sub ' data received go to DataReceived P r i v a t e S u b D a t a R e c e i v e d( B y V a l s e n d e r A s O b j e c t , B y V a l e A s System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived ' update data go to updateTextBox rtxtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {}) End Sub Public Delegate Sub myDelegate() Public Sub updateTextBox() Dim currentSystemTime As DateTime = DateTime.Now ' date and time now x = x + serialPort.ReadExisting ' save data form serialport in x If x.Length >= 10 Then ' check length data >=10 ok x.Substring(0, 10) ' substring 0-10 ' select input with database for check in or out strsql = “select * from tb_in where id_in='" + x + "' and date_in='" + currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "'" ' execute sql command command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected If num <= 0 Then ' if no check in insert data in tb_in strsql = "INSERT INTO tb_in VALUES (‘" + x + "‘, ‘" + currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + "‘, ‘" + currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "')" TextBox1.Text = "In " + x + " " + currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + " " + currentSystemTime.Date Else ' if check out select check out strsql = "select * from tb_out where id_out='" + x + "' and date_out='" + currentSystem Time .Yea r.To Stri ng + "-" + currentSystemTime.Month.ToString + "-" + currentSystemTime.Day.ToString + "‘" command = New OdbcCommand(strsql, MyConnection) reader = command.ExecuteReader() num = reader.RecordsAffected

Listing 12-1 : Source code of the RFID Logger program. This code is written by Visual BASIC Express 2010 (continue)

54

Easy RFID Education kit documentation


If num <= 0 Then ' insert data in tb_out strsql = “INSERT INTO tb_out VALUES ('" + x + "', ‘" currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + "', ‘" currentSystemTime.Year.ToString + "-" + currentSystemTime.Month.ToString +"-" currentSystemTime.Day.ToString + "')" TextBox1.Text = "Out " + x + " " currentSystemTime.TimeOfDay.ToString.Substring(0, 8) + " " currentSystemTime.Date Else TextBox1.Text = x & " Cannot add more data" End If End If ' execute sql command command = New OdbcCommand(strsql, MyConnection) command.ExecuteReader() x = "" ' clear value x End If End Sub End Class

+ + + + +

Listing 12-1 : Source code of the RFID Logger program. This code is written by Visual BASIC Express 2010 (final)

12.5 Microcontroller code Open the BASIC Stamp editor to create the code following the Listing 12-2. Download this to i-Stamp2P microcontroller. Use the circuit and connection diagram same the experiment 3. ' {$STAMP BS2p} ' {$PBASIC 2.5} m VAR Byte (10) LOW 2 main : SERIN 3, 1021, [WAIT($0A),STR m\10] FREQOUT 4,1000,1000 SEROUT 16, 240, [STR m\10] PAUSE 2000 GOTO Main

'output sound on port 4

Listing 12-2 : RFIDreader.bsp; Read the RFID tag to show on the RFID logger software that created by Visual BASIC express 2010

Easy RFID Education kit documentation

55


12.6 Testing (12.6.1) Run the VB express 2010 code and microcontroller code. The RFID logger software window will appear. Select the connected COM port. (12.6.2) Place the RFID tag over the RFID reader. See the operation at the RFID program window. ID of RFID tag is read and show in the program following the figure 12-2. The first reading is Check-in time of the current date. (12.6.3) Read the same RFID tag again. ID of RFID tag is read and show in the program following the figure 12-3. The second reading is Check-out time of the current date.

Figrue 12-2 RFID logger software with check-in RFID tag

56

Figrue 12-3 RFID logger software with check-out RFID tag

Easy RFID Education kit documentation


(12.6.4) Next,try to serach the RFID tag record. Type the ID of the register tag in Search box. Click on the Search button. The database of this tag is shown in the figure 12-4.

Figrue 12-4 RFID logger software with the registered RFID tag data (12.6.5) User can print this data. Click on the Print button to print to the target printer following the figure 12-5. You can add more RFID tags data that you want. The maximum record are depended on the computer memory storage.

Figrue 12-5 RFID logger software with the print window for printing the registered RFID tag data That is the simple application of RFID system. It includes the RFID reader hardware, microcontroller to control the operation and interface with computer. At the computer side, requires the suitable software that includes database management and microcontroller interfacing.

Easy RFID Education kit documentation

57


58

Easy RFID Education kit documentation


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.