Monday, March 4, 2013

Using a Parallax Serial RFID Reader with a Maple Mini

The Parallax RFID Reader (Serial Version) provides an easy way to read 125 kHz / EM41000 RFID tags, and it works nicely with the Maple Mini. The following very basic example reads a tag when it is brought near the reader and prints the tag's ID number to the SerialUSB console.

Note that the Parallax RFID reader is a 5v device. I am using USB power and have its VCC connected to the Maple Mini's VIN.  The GPIO pins used are 5-volt tolerant.

Connections:

Parallax RFID   Maple Mini
GND             GND
SOUT            RX1 (Pin 25)
/ENABLE         Pin 2
VCC             VIN

Code:


int ENABLE_PIN = 2;
int  val = 0; 
char code[10]; 
int bytesread = 0; 

void setup() {
  Serial1.begin(2400);  // Reader connects at 2400 baud
  pinMode(ENABLE_PIN, OUTPUT);
  digitalWrite(ENABLE_PIN, LOW);  // Activate RFID reader
}

void loop() {
  if(Serial1.available() > 0) {
    if((val = Serial1.read()) == 10) {     // Check for header char 
      bytesread = 0; 
      while(bytesread < 10) {              // Read 10-digit code 
        if( Serial1.available() > 0) { 
          val = Serial1.read(); 
          if((val == 10)||(val == 13)) {   // If header/stop bytes  
            break;                         // stop reading 
          } 
          code[bytesread] = val;           // Store the digit           
          bytesread++;                     // Ready to read next digit  
        } 
      } 
      if(bytesread == 10) {                // If 10-digit read is complete 
        SerialUSB.print("TAG code is: ");  // possibly a good tag 
        SerialUSB.println(code);           // Print the tag's ID code 
      } 
      bytesread = 0; 
      digitalWrite(ENABLE_PIN, HIGH);      // Pause to avoid flooding
      delay(1500);                         // Wait for a bit 
      digitalWrite(ENABLE_PIN, LOW);       // Activate the RFID reader
    }        
  } 
}


No comments:

Post a Comment