This tutorial explains how to read from Mifare RFID tags from your computer using a Sonmicro SM130 read/write module. The sketch below is written in Processing using my SonmicroReader library. The SM130 has a TTL serial interface that you can connect to a micocontroller, or to a personal computer through a USB-to-serial interface. Using the latter, it’s pretty simple to send serial commands to it and receive the data back. The entire Processing sketch can be downloaded here: rfid_simple_0001.
Sonmicro RFID Reader Library for Processing
Last year, I worked with Timo Arnall and Einar Martinussen and Jørn Knutsen on a Processing library to read and write to Mifare RFID tags using the Sonmicro SM130 read/write module. Here it is, with a few improvements and bug fixes.
To use the library, unzip it and copy the folder to your Processing libraries folder. Then restart Processing. There are two example sketches, a simple reader that seeks new tags, and a full read/write example.
For more details, see the datasheet for the module. Code examples will follow in this blog.
Continue reading “Sonmicro RFID Reader Library for Processing”
Clock
Here’s a quick digital clock in Processing. It also sends the time out a serial port. I use this for testing when I need for a microcontroller or other serial device to receive a string.
/* Clock Draws a digital clock in the center of the screen and sends the string out the serial port. created 7 Oct 2008 by Tom Igoe */ import processing.serial.*; Serial myPort; // instance of the serial library void setup() { // open the applet window: size(300, 200); // initialize the font for text display: PFont myFont = createFont(PFont.list()[0], 24); textFont(myFont); // align all text center: textAlign(CENTER); // open a serial port: myPort = new Serial(this, Serial.list()[0], 9600); } void draw(){ // clear the screen: background(0); // make a string of hour: minute:second. Use nf() // to format the numbers in two digits each: String theTime = nf(hour(), 2) + ":" + nf(minute(), 2) + ":"+ nf(second(), 2); // draw it in the middle of the screen: text(theTime, width/2, height/2); // send it out the serial port: myPort.write(theTime + "\n"); // wait one second before doing it again: delay(1000); }
Sending Mail from Processing
Here’s a piece of code to send mail from Processing. It uses the net library. Warning: your mail server may not use port 25.
/* mail_client by Tom Igoe A simple mail sender client Created 21 January 2006 */ import processing.net.*; Client myClient; int clicks; String reply = null; boolean sent = false; void setup() { // Connect: myClient = new Client(this, "echonyc.com", 25); delay(300); } void draw() { if(!sent) { waitForReply(); myClient.write("HELO echonyc.com\n"); waitForReply(); myClient.write("MAIL FROM:tigoe@echonyc.com\n"); waitForReply(); myClient.write("RCPT TO:tigoe@echonyc.com\n"); waitForReply(); myClient.write("DATA\n"); waitForReply(); myClient.write("Subject:Noodles\n"); myClient.write("From:tigoe@echonyc.com\n"); myClient.write("To:tigoe@tigoe.net\n"); myClient.write("\rHere's the body\n.\n"); waitForReply(); myClient.write("QUIT\n\r"); waitForReply(); } sent = true; } void waitForReply() { int newChar = 0; while (newChar != 10) { if(myClient.available() > 0) { newChar = myClient.read(); reply += (char)newChar; } } println(reply); }
RFID Reader and Image Display
This program reads ID Innovations ID-12 RFID readers and matches the tags against a list of known tags. It’s an illustration of how to use an RFID reader to associate data with a set of tags.
/* RFID Reader and image display Language: Processing This program reads ID Innovations ID-12 RFID readers rom two serial ports. It matches the tags against a list of known tags, and uses the match to associate a name with the tag. It also scans the sketch's data directory to load an image associated with the name. Created 12 Mar 2008 by Tom Igoe and the interaction design class at AHO, Spring 2008 directory reading and image scanning based on an example from Marius Watts */
Reading Multiple Serial Ports in Processing
This program reads multiple serial ports and lets you know when data comes from one port or the other. The two ports in this example are attached to ID Innovations ID-12 RFID readers. The ID-12 readers send a string that ends with a byte whose value is 0x03.
/* Multiple Serial Ports Language: Processing This program reads multiple serial ports and lets you know when data comes from one port or the other. The two ports in this example are attached to ID Innovations ID-12 RFID readers. The ID-12 readers send a string that ends with a byte whose value is 0x03. Created 12 Mar 2008 by Tom Igoe */
Continue reading “Reading Multiple Serial Ports in Processing”
XBee Library graphing and logging application
Here’s a program that uses Rob Faludi and Dan Shiffman’s XBee library for processing to read three analog sensors from multiple remote XBee radios and graph them. It also saves the data to a comma-delimited file. It also makes sounds when the value exceeds a given threshold. For this application, you need two or more XBee series 1 radios. One is attached to the serial port of the computer, and the other is remote, broadcasting three analog values.
This also uses the ControlP5 library by Andreas Schlegel and the Ess library by Krister Olsson.
Continue reading “XBee Library graphing and logging application”
XBee Library graphing application
Here’s a simple program that uses Rob Faludi and Dan Shiffman’s XBee library for processing to read three analog sensors from a remote XBee radio and graph it. For this application, you need two XBee series 1 radios. One is attached to the serial port of the computer, and the other is remote, broadcasting three analog values.
XOR calculation for NMEA checksums (GPS protocol)
If you’ve ever seen the serial output of a GPS reader, you’ve seen a mystery string at the end like this:
That’s the checksum of the whole string. NMEA data structure for Global Positioning (GPS) readers has a checksum on the end of each sentence. The checksum is the XOR of all the bytes between the $ and the * in the sentence. For example, if the sentence is this:
$GPRMC,155123.000,A,4043.8432,N,07359.7653,W,0.15,83.25,200407,,*28
then you run a checksum on this:
GPRMC,155123.000,A,4043.8432,N,07359.7653,W,0.15,83.25,200407,,
Here’s a Processing method to calculate the checksum, given the string between the $ and the *:
Continue reading “XOR calculation for NMEA checksums (GPS protocol)”
Peak finding in Processing
In a previous example, I showed how to detect a peak in a changing analog value on a microcontroller. This example shows how to do it in Processing, assuming the microcontroller is just sending you binary values from 0 to 255. It graphs the incoming bytes, and when a peak is detected, it draws an ellipse and prints a message in the message pane.
Thanks to Matt Young for helping me debug this.
Technorati Tags: pcomp, physical computing, sensors