ECE 110/Equipment/RFID Module

From PrattWiki
Revision as of 22:00, 18 August 2022 by DukeEgr93 (talk | contribs) (Created page with "== Introduction == The ID-12LA RFID reader will read and report values for RFID tags. The tag information will be delivered to a serial port one byte at a time. Recall that...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The ID-12LA RFID reader will read and report values for RFID tags. The tag information will be delivered to a serial port one byte at a time. Recall that a byte is an 8-bit binary number (which can also be represented with a 2-character hexadecimal number).

For the tags in lab:

  • The first byte will always be 00000010 (dec: 2, hex:0x02) - STX, the "start of text" code in ASCII.
  • The next two bytes will form the chip code. Each of these bytes will represent a hexadecimal value and will thus be the characters 0-9 or A-F (dec: 48-57 or 65-70, hex: 0x30-0x39 or 0x41-0x46).
  • The next ten bytes will form a unique ID. Each of these bytes will also represent a hexadecimal value.
  • The fourteenth byte will always be 00001110 (dec 13, hex: 0x0D) - CR, the "carriage return" code in ASCII.
  • The fifteenth byte will always be 00001100 (dec 10, hex 0x0A) - LF, the "line feed" code in ASCII.
  • The sixteenth and final byte will always be 00000011 (dec 3, hex 0x03) - ETX, the "end of text" in ASCII.

Generally, we will only want to store the 12 bytes comprising the chip code and the unique ID.

Leads

  • VCC: Supply voltage, typically 5 V
  • DATA: Data channel
  • GND: Ground

Operation

Sample Code

// Based on https://www.instructables.com/Reading-RFID-Tags-with-an-Arduino/
// Expanded by Michael R. Gustafson II to include hex / bin / dec values and 
// replace unprintable characters

char val = 0; // variable to store the data from the serial port

void setup() {
  Serial.begin(9600); // connect to the serial port for the monitor
  Serial1.begin(9600); // connect to the serial port for the RFID reader
  Serial.println("");
  Serial.println("Char\tHex\tDec\tBin");
  
}

void loop () {
  if(Serial1.available() > 0) {
  val = Serial1.read();

  // Handle unprintable characters
  switch(val) {
    case 0x2: Serial.print("STX"); break;
    case 0x3: Serial.print("ETX"); break;
    case 0xA: Serial.print("LF");  break;
    case 0xD: Serial.print("CR");  break;
    default:  Serial.print(val);   break;
  }
  Serial.print("\t");
    
  Serial.print(val, HEX); Serial.print("\t");
  Serial.print(val, DEC); Serial.print("\t");
  Serial.print(val, BIN); Serial.println("");
  }
}

Notes

References