Trying to get arduino to react to data other than tag serial number

Arduino uno v3
Reader: Mfrc522
Tags: Mifare ultralight

I ordered 100 tags only to find out that when scanned they all have the same serial number.

I have figured out how to write data to the rfid tags allowing me to put a different 16 digit code on each tag.
And what I write to each card shows up on the 6th~9th row of data. (4 per row)

Is there a way to have the reader read the written data and trigger based on that instead of the serial id of the tag?

I have spent two days trying to figure this out.
And I'm either going make this work or have to buy 100 more mini rfid tags with all different serial numbers.

Any advice welcome. :confused:

If you can write data to the tag it seems logical that you can also read the data.

Post your program code.

...R

Neb777:
I have figured out how to write data to the rfid tags allowing me to put a different 16 digit code on each tag.
And what I write to each card shows up on the 6th~9th row of data. (4 per row)

Is there a way to have the reader read the written data and trigger based on that instead of the serial id of the tag?

This doesn't make sense.
So you write data to the card. You are apparently confident it's written there - which implies you can read it back, or how do you know the data has actually been written to the card?
Then you ask how to read it so you can act on it. But you can read it already?

Normally you can not write to that part of that sort of tag. Are you sure you are actually reading it correctly?

I'm using three separate codes that I have on three separate arduinos attached to three seperate scanners.

1: One code lets me write to the card.

2: One code just displays all info on the card

3: And the other code is where I'm having the issue.
Which is basically an if this then that code that when a tag is scanned it opens a relay.
T
I know the code is written to the tag because I have written "tree123456789012" on one and "apple12345678901" on the other.

And when I scan them on the second reader (the one that reads all info on the card) I see both cards with the same serial number but on pages 6~9 in hex the are the two different words I wrote.

Obviously my problem is in code 3
Where all it reads is the serial number and thinks every tag is the same. What I can't figure out is how to get it to read the word instead of the serial number. So that if the code sees the word tree123456789012 then the arduino will open the tree relay on pin X but if it see's apple1234678901 it will open the apple relay on pin Y

Once I got that part figured out it should be easy to add more IDs to open more relays on other pins.
FYI: We are also using a code we had that would display info on an lcd which for this project is not necessary but when we removed the code it broke the code so we left it as it didn't seem to hurt.

Attached are the following
Code 1: mini RFID write
Code 2: RFID card dump
Code 3: RFID tester

RFID_TESTER.ino (1.53 KB)

RFID_CARD_DUMP_INFO.ino (2.02 KB)

MiniRFIDWrite.ino (1.87 KB)

Neb777:
I know the code is written to the tag because I have written "tree123456789012" on one and "apple12345678901" on the other.

So, if the numbers can shift based on the number of alphabetic characters that precede them, we can conclude that the numerals and the letters are just ASCII values.

Can you write something like 'extraterrestrial' to the tag?

The third program is using a write() function to send data to the card.

Presumably there is a similar read() function. Have you tried that? Or checked the documentation for the library?

...R

Code for the trouble program 3 (much easier than downloading!):

/*
  RFID   SunFounder Uno
  VCC     3.3V
  RST     2
  GND     GND
  MISO    3
  MOSI    4
  SCK     5
  NSS     6
  IRQ     7
****************************************/

#include"rfid.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RFID rfid; //create a variable type of RFID
#define relayPin 8 //relay module attach to pin8
uchar serNum[5]; // array to store your ID
void setup()
{
  lcd.init(); //initialize lcd
  lcd.backlight(); //turn on the backlight
  Serial.begin(9600);
  rfid.begin(7, 5, 4, 3, 6, 2); //IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN
  delay(100);
  rfid.init(); //initialize the RFID
  pinMode(relayPin, OUTPUT); //set relayPin as OUTPUT
  digitalWrite(relayPin, LOW); //and high level
  delay(2000); //delay 2s
}
void loop()
{
  uchar status;
  uchar str[MAX_LEN];
  // Search card, return card types
  status = rfid.request(PICC_REQIDL, str);
  if (status != MI_OK)
  {
    return;
  }
  // Show card type
  rfid.showCardType(str);
  //Prevent conflict, return the 4 bytes Serial number of the card
  status = rfid.anticoll(str);
  if (status == MI_OK)
  {
    Serial.print("The card's number is: ");
    memcpy(serNum, str, 5);
    rfid.showCardID(serNum); //show the card ID
    Serial.println();
    // Check people associated with card ID
    uchar* id = serNum;
    if (id[8] == 0X45 && id[2] == 0X08 && id[3] == 0X7A && id[4] == 0XFE)
    {
      digitalWrite(relayPin, HIGH);
    }

    else
    {
      digitalWrite(relayPin, LOW);
    }
  }
  rfid.halt(); //command the card into sleep mode
}

A few things of note.

  1. In line 54 you're looking for an id[8] while the array is only 5 characters long.
  2. That are not regular ASCII characters you're looking for. That probably explains why you don't do a strcmp(), but doesn't make sense in relation to your description of what the serial numbers should look like.

The RFID card dump will be all the information on the card including the serial number. Can you post the output of this code for two cards.

Grumpy_Mike:
The RFID card dump will be all the information on the card including the serial number. Can you post the output of this code for two cards.

Here is the dump info for the tree card

Firmware Version: 0x91 = v1.0
Scan PICC to see UID, SAK, type, and data blocks...
Card UID: 04 08 7A 04 04 15 45
Card SAK: 00
PICC type: MIFARE Ultralight or Ultralight C
Page 0 1 2 3
0 04 08 7A FE
1 04 04 15 45
2 50 00 00 00
3 E1 10 12 00
4 01 03 A0 10
5 44 03 00 FE
6 74 72 65 65
7 31 32 33 34
8 35 36 37 38
9 39 30 31 32
10 00 00 00 00
11 00 00 00 00
12 00 00 00 00
13 00 00 00 00
14 00 00 00 00
15 00 00 00 00

this is the dump info for the apple card

Card UID: 04 08 7A 04 04 16 80
Card SAK: 00
PICC type: MIFARE Ultralight or Ultralight C
Page 0 1 2 3
0 04 08 7A FE
1 04 04 16 80
2 96 00 00 00
3 E1 10 12 00
4 01 03 A0 10
5 44 03 00 FE
6 61 70 70 6C
7 65 31 32 33
8 34 35 36 37
9 38 39 30 31
10 00 00 00 00
11 00 00 00 00
12 00 00 00 00
13 00 00 00 00
14 00 00 00 00
15 00 00 00 00

dougp:
So, if the numbers can shift based on the number of alphabetic characters that precede them, we can conclude that the numerals and the letters are just ASCII values.

Can you write something like 'extraterrestrial' to the tag?

From what I understand the word needs to be 16 characters so I filled in the rest with numbers.

So yes I could use extraterrestrial

Card UID: 04 08 7A 04 04 15 45
Card UID: 04 08 7A 04 04 16 80

The UID of these two cards is different!
I can't see your problem.
This uses a 7 byte UID.

Grumpy_Mike:
The UID of these two cards is different!
I can't see your problem.
This uses a 7 byte UID.

MIFARE - Wikipedia

I know the 7 byte UIDs are different but I haven’t had any luck with finding a code or writing a code that can scan for 7 Bytes the one I have scans the first 4 bytes and those are the same on all of my mini rfid tags. So when scanned they all show up as 88 04 08 7A (I have no idea where the 88 is coming from)

I thought if I wrote something specific to to the rfid I could use that to differentiate but if it’s easier to code something to just read the 7 byte UID instead... I’m all ears.

We usually use bigger rfid tags where this code works fine and have only run into this issue with the tiny rfids which we need to use in our current game.

Then obviously you have to look at the card UID data instead of whatever thing you're looking at now. What's the problem in that?

I know the 7 byte UIDs are different

It would have been good to know that before reply #12.

Simply change your code to read all the bits of the UID. It is your code you can change what it does.

Grumpy_Mike:
It would have been good to know that before reply #12.

Simply change your code to read all the bits of the UID. It is your code you can change what it does.

My apologies, I'm quite new at all of this.
Any idea what I need to change?
You make it sound obviously simple but somehow I just can't figure out what to change to get it to look for anything beyond 88 04 08 7A.

What code do I need to change/add to have it look beyond that?

You posted the result of a 'dump' of card data. Is that the same as what you get when just doing a normal read of the card? If not, what does that transmission look like?

In the meantime, you may find the AVR string library interesting reading. It's a collection of functions for doing all sorts of things with/to string arrays.

From your first post

Obviously my problem is in code 3

So look to change that. I can not tell you specifically where because you have posted it as a .ino file. Most mobile devices can not cope with this even though at the end of the day it is just a text file.
That is one reason why we specifically ask you to post code in code tags, it tells you how in the how to use this forum sticky post.

Grumpy_Mike:
That is one reason why we specifically ask you to post code in code tags, it tells you how in the how to use this forum sticky post.

ok cool I looked it up...
so here is the code that is my problem...
it is pretty messy as it's be kinda re appropriated for several of my little projects.

#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Debug.h>
#include <MFRC522Extended.h>
#include <MFRC522Hack.h>
#include <require_cpp11.h>
#include <MFRC522.h>

/* 
 *   RFID-RC522 (SPI connexion)
 *   
 *   CARD RC522      Arduino (UNO)
 *     SDA  -----------  10 (Configurable, see SS_PIN constant)
 *     SCK  -----------  13
 *     MOSI -----------  11
 *     MISO -----------  12
 *     IRQ  -----------  
 *     GND  -----------  GND
 *     RST  -----------  9 (onfigurable, see RST_PIN constant)
 *     3.3V ----------- 3.3V
 *     
 */

  #include <SPI.h>
  #include <MFRC522.h>
  
  
  
  #define SS_PIN          10
  #define RST_PIN         9

  MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
  MFRC522::StatusCode status; //variable to get card status
  
  byte buffer[18];  //data transfer buffer (16+2 bytes data+CRC)
  byte size = sizeof(buffer);

  uint8_t pageAddr = 0x06;  
void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card  
  Serial.println(F("Sketch has been started!"));
  memcpy(buffer,"tree12345678901",16); //Line being written to page six of RFID
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
    return;

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
    return;

  // Write data ***********************************************
  for (int i=0; i < 4; i++) {
    //data is writen in blocks of 4 bytes (4 bytes per page)
    status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(pageAddr+i, &buffer[i*4], 4);
    if (status != MFRC522::STATUS_OK) {
      Serial.print(F("MIFARE_Read() failed: "));
      Serial.println(mfrc522.GetStatusCodeName(status));
      return;
    }
  }
  Serial.println(F("MIFARE_Ultralight_Write() OK "));
  Serial.println();


 

  mfrc522.PICC_HaltA();

}

Neb777:
\Any idea what I need to change?
You make it sound obviously simple but somehow I just can't figure out what to change to get it to look for anything beyond 88 04 08 7A.

What code do I need to change/add to have it look beyond that?

Start with your dump code. Figure out how to reliably read ONLY the 6-byte UID, and place that in a string. Use the string manipulation functions as mentioned above, and carefully check how the data looks like.

If it's a stream of data with a fixed length (this I would expect) you should be able to simply say "bytes x to y is my UID".

After that you can simply compare that UID with your list of UIDs, and take action based on it. It's a 6-character string so you should be able to use the strcmp() function - it shouldn't matter that the characters are non-printable.