RFID

01 Sep 2009 . Edited: 01 Sep 2009

I'm interested in connecting RFID readers and Ethernet to an mbed to form the basis for remote sensing. In theory the main interest is for tracking population movements in my college but as a reasonably keen garden railway enthusiast I'm also thinking about it for train tracking.

Anyway, the simple RFID program from the cookbook refuses to compile, I think, because of the change to using pin names (or rather PinNames) instead of ints to describe the names of the pins used for transmit and receive.

I've rewritten the sample code as follows, including the RFID.h and RFID.cpp files inline, and commented the lines that need changing with // CHANGE FROM:

 

#include "mbed.h"

namespace mbed {
class RFID {
	public:
	    RFID(PinName tx, PinName rx); // CHANGE FROM RFID(int tx, int rx);
	    int readable(void);
	    int read (void);
	private:
	    Serial _rfid;
	   
	};
}

using namespace mbed;
	RFID::RFID(PinName tx, PinName rx) // CHANGE FROM RFID::RFID(int tx, int rx)
	  : _rfid(tx,rx) {}
	
	int RFID::readable(void) {
	  return (_rfid.readable());
	}
	   
	int RFID::read(void) {
	        while(_rfid.getc() != 2);
	        int v = 0;
	        _rfid.getc(); // drop 1st 2
	        _rfid.getc();       
	        for(int i=7; i>=0; i--) {
	            char c = _rfid.getc(); // a ascii hex char
	            int part = c - '0';
	            v |= part << (i * 4);
	        }
	        for(int i=0; i<5; i++) {
	            _rfid.getc();
	        }
	        return v;
	    }
	
RFID rfid (p13,p14); // CHANGE FROM RFID rfid(13, 14);
Serial pc (USBTX,USBRX);
int main() {
  while (1){
    int id = rfid.read();
    pc.printf("Tag ID = %d\n\r",id);
    }
}

Not knowing a great deal about SVN and submitting changes I wonder if someone could make these changes into the RFID code at http://mbed.org/projects/cookbook/svn/RFID/trunk.

Now to get it talking over Ethernet!

John Stout


28 Mar 2011

Hi John, I am new to mbed programming. I assume you must have seen the "Prototyping the Internet of Things Project" ? I am trying to do something similar: Use RFID reader connected to the mbed which can read student ID tags and send an informative Tweet to a Teacher( like attendance). Is it possible to do this using JAVA? I can do the coding, so please be assured I am not asking for that. What I would like to know is if its possible to do the same using JaVA, that is you know somehow make possible for mbed to access the program and then execute the required?

Thank you in advance , your info here is great as well and would use it if doing in C++..