Introduction
It is quite easy to read IDs of RFID tags, using Parallax’s
serial or USB RFID card reader. If you have two RFID cards at least, and of course Parallax RFID reader, you can set up, without hassle, the below described project. This blog contains several articles that show how easy it is, to control and communicate with electronic devices with
Processing.
Objectives
Read RFID cards, using serial communications of Processing and Parallax RFID Card Reader, and show useful information on-screen with user interaction.
Pre-Requirements
Installed Processing environment,
RFID Card Reader USB #28340 from Parallax, at least 2 RFID Cards, and a USB cable for connecting between RFID Card Reader and PC.
The Experimental Set
Connecting to PC
The RFID Card Reader when correctly installed will be shown as a serial device. Check the port number where the RFID reader is connected in Control Panel - > System – >Hardware tab -> Device Manager button -> Ports (COM and LPT). In this experiment the serial port was COM4. After cheking the port number you just need to take note of it to be introduced into next Processing sketch.
The Processing Sketch
Start a new sketch in Processing, and save it as rfid.pde.
The code for rfid.pde:
01 | // Sketch code based on the one found in "Reading RFID Tags in Processing" chapter |
02 | // of the book Making Things Talk published by O'Reilly |
04 | import processing.serial.*; |
11 | myPort = new Serial(this, "COM4", 2400); |
14 | PFont myFont = createFont(PFont.list()[2], 24); |
20 | text(tagID, width/4 + 12, height/2 - 24); |
23 | void serialEvent(Serial myPort) { |
24 | tagID = trim(myPort.readString()); |
Make the adequate COM port changes in your sketch line 8 myPort = new Serial(this, “COM4″, 2400);
to your PC’s installed RFID Card COM port number. Run the sketch and check the TagIDs of both cards. In this case the codes obtained were 34009EA5AF and 0F00296C9FF. The former was chosen as valid card for next sketch. In your case it will be another number.
We will next produce our final sketch. Start a new Sketch in Processing and save it asrfid1.pde
TTS library is required to add voice to the project.
TTSLib from GuruBlog is used. Install the unzipped file into your
libraries folder of
Processing. The library will be imported by Processing. Add image (in this case 100×100 tayeb.jpg is used) to your Processing projects folder, usually found under my Documents\Processing.
Our folder here will be rfid1.
So here is the code for our final rfid1.pde sketch:
01 | // Sketch code based on the one found in "Reading RFID Tags in Processing" chapter |
02 | // of the book Making Things Talk published by O'Reilly |
05 | import processing.serial.*; |
14 | myPort = new Serial(this, "COM4", 2400); |
17 | PFont myFont = createFont(PFont.list()[2], 24); |
27 | if (tagID.equals("34009EA5AF")) { |
29 | b = loadImage("tayeb.jpg"); |
31 | text(tagID, width/2 - 6, height/2 - 24); |
32 | text("TAYEB", width/2 - 6, height/2); |
35 | text(tagID, width/4 + 6, height/2 + 12); |
38 | void serialEvent(Serial myPort) { |
39 | tagID = trim(myPort.readString()); |
40 | if (tagID.equals("34009EA5AF")) { |
42 | tts.speak("Hi! Welcome Tayeb!"); |
46 | tts.speak("Invalid Card!"); |
Make the adequate changes as shown below in following images:
Port number of installed RFID reader
Other required changes
Now run the sketch. If you read the cards you will hear voice. In this case “Invalid card!” or “Hi Welcome Tayeb!”., or whatever name you have chosen. In our project with sketch code as above, the follow results were drawn on the PC’s screen:
Valid card
Invalid card
In fact any other RFID card, besides the chosen one, will be considered invalid.
Conclusions
Though this actual project is quite simple and the code is not neat, bub it can ve improved. As something extra and quite simple one could add a
serial controlled relay or another micrcontroller controlled device.
Of course projects with Visual C#, and other programming languages, can be made to talk to RFID cards, and be quite sophisticated. Some useful RFID projects can be attendance control, stock control, livestock identification, etc.
RFIDs are here to stay, and are everywhere these days. It is quite important to learn to work with them.
Acknowledgements
A special thanks is due to Tom Igoe, author of O’Reilly’s book
“Making Things Talk” for the code with Processing.
0 comments:
Post a Comment