-1

I am creating a game using the Mifare tags embedded in 8 different playing pieces. I will be using an Arduino NANO with the MFRC522 (library https://github.com/miguelbalboa/rfid) to do the actual reading of the tags, and am using an ER301 reader/writer (with eReader software) to assign playing piece numbers to them. I will be creating multiples of each piece to head off any issues I would have with loss due to breakage or theft (due to these being rather unique playing pieces). Since there will be 8 different pieces, and 4 copies of each piece, that would be 32 UIDs to keep up with. I would rather assign a different number to each of pieces, and the same number of each piece to its duplicates - so only 8 numbers to keep up with.

My question is - how do I read a certain block and sector with the MFRC522?

Specifically, sector 2, block 8 - because this is where the Hex equivalent of the playing piece number shows up (when it is assigned as a Product Name with the eReader software and the ER301 writer). I understand using the library for the MFRC522 to read the UID, but this is a bit more in-depth than my understanding.

I have written several Sketches for the Arduino, but this is my foray into the world of RFID, and is quite a bit more extensive than my previous Arduino projects. Once I can read the specific sector & block, the Arduino NANO will output a binary representation (on 4 of the digital I/Os) of which playing piece was placed.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
JMortonSalt
  • 1
  • 1
  • 2
  • I'll be using this library: https://github.com/miguelbalboa/rfid I haven't tried anything yet as I'm still collecting parts. Everything I've found so far points me to reading the UID - but I just want to read a specific sector (Sector2 Block8). I already have a writer (ER301 and eReader software) that I can write my info to this sector & block, and have verified this. Once the info is read by the MFRC & NANO, I'll have the NANO output the binary equivalent of the number on 4 digital I/Os. – JMortonSalt Jun 19 '16 at 15:58
  • This game will involve 4 identical setups of Arduino NANOs and MFRC522 readers. As each one reads the playing piece, it will output the binary equivalent (of pieces 1 through 8) on 4 of the digital I/Os. These 16 total outputs will be fed into 16 digital I/Os of an Arduino MEGA, which will keep track of which playing pieces are in the 4 'positions' (the 4 NANO setups). – JMortonSalt Jun 19 '16 at 16:06

1 Answers1

0

The library you are using provides dedicated methods to perform read and write operations on MIFARE tags:

StatusCode MIFARE_Read(byte blockAddr, byte *buffer, byte *bufferSize);
StatusCode MIFARE_Write(byte blockAddr, byte *buffer, byte bufferSize);

Since your description (sector 2, block 8) suggests that you are using MIFARE Classic tags, you would also need to authenticate to the tag in order to perform read/write operations. Thus, you would also need the authentication method:

StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);

Just as you would use the library to read the UID

if (mfrc522.PICC_ReadCardSerial()) {
    Serial.print(F("Card UID:"));
    dump_bytes(mfrc522.uid.uidByte, mfrc522.uid.size);
}

you could also access these read/write methods:

MFRC522::StatusCode status;
MFRC522::MIFARE_Key key;
byte buffer[18];
byte size = sizeof(buffer);
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; ++i) {
    key.keyByte[i] = 0xFF;
}

if (mfrc522.PICC_ReadCardSerial()) {
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 8, &key, &(mfrc522.uid));
    if (status == MFRC522::STATUS_OK) {
        status = mfrc522.MIFARE_Read(8, buffer, &size);
        if (status == MFRC522::STATUS_OK) {
            Serial.print(F("Data (block = 8): "));
            dump_bytes(buffer, 16);
        }
    }
}

Note that I assume block 8 (= sector 2, block 0) to be readbale using key A and that key A is set to the default transport key FF FF FF FF FF FF. If your other reader changed those values, you need to adapt the code accordingly. Moreover I used the pseudo-method dump_bytes(array, length) to indicate that the interesting value is the first length bytes of array. An implementation that actually prints those values is up to you.

Btw. a full example on how to use the library for read/write operations actually ships together with the library!. So you could just take a look at ReadAndWrite.ino on how to use that library.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • Thanks Michael! As I said, all of this is new to me and any help is greatly appreciated. You are totally correct in saying that I'm using the Mifare Classic tags, and that the default transport key is FF FF FF FF FF FF. – JMortonSalt Jun 24 '16 at 14:24
  • I won't actually be printing the value, but actually assigning the value read into the integer pieceNum. I've observed that assigning a piece number of "1" to the tag results in "3100000000000000" being written to block 8, & piece number of "2" results in "3200000000000000". How would I convert these to simply "1" or "2" stored in pieceNum? Apologies for newbie questions. – JMortonSalt Jun 24 '16 at 14:38