Notes About Working with Various Arduino & Netduino Microcontroller Boards

Tuesday, January 22, 2013

Parallax RFID Reader & the Arduino Due

Using the serial version of the Parallax RFID reader (125 kHz) with an Arduino Uno is straight forward. The RFID reader also works with an Arduino Due, too. Because the Parallax RFID reader is 5V, though, a logic level converter is needed to protect the lower voltage pins on the Arduino Due.

Connections:

RFID --> Log Lvl Conv --> Arduino Due
GND  --> GND (HV)     --> GND
SOUT --> RXI / RXO    --> D19 (RX1)
/ENABLE  ---------------> D2
VCC  --> HV           --> 5V
         LV           --> 3V3
         GND (LV)     --> GND

D19 (RX1) on the Arduino Due connects to Serial1. Serial2 (D17 - RX2) or Serial3 (D15 - RX3) could also be used with change to code.
        
Code:

// RFID reader for Arduino 
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan> 
// Modified for Arudino by djmatic
// Slight modification by Brad Berkland

int const ENABLE_PIN = 2;

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

void setup() { 
  Serial.begin(19200);
  Serial1.begin(2400);            // RFID reader SOUT pin connected to D19 on Due (RX1) 
  pinMode(ENABLE_PIN, OUTPUT);    // Set D2 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(ENABLE_PIN, LOW);  // Activate the RFID reader
}  

void loop() { 
  if(Serial1.available() > 0) {          // if data available from reader 
    if((val = Serial1.read()) == 10) {   // check for header 
      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 before 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 
      if(bytesread == 10) {              // if 10 digit read is complete 
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code 
      } 
      bytesread = 0; 
      digitalWrite(ENABLE_PIN, HIGH);    // Stop reader for a moment to avoid flooding
      delay(1500);                       // wait for a bit 
      digitalWrite(ENABLE_PIN, LOW);     // Activate the RFID reader
    } 
  } 


No comments:

Post a Comment