none
Arduino sketch for RFID Reader RRS feed

  • Question

  • hello

    I am connecting Arduino port to visual studio c#and I reading tags from RFID Reader to my program. Arduino code is initialized with hex tag FF FF FF FF and when I scan my item over RFID Reader first it displays the hex id to the GUI, I want to remove it and immediately scan my tag id. Is there a way?

    #include <SPI.h>
    #include <MFRC522.h>
    
    #define SS_PIN 10
    #define RST_PIN 9
     
    MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
    
    MFRC522::MIFARE_Key key; 
    
    // Init array that will store new NUID 
    byte nuidPICC[10];
    
    void setup() 
    { 
      Serial.begin(9600);
      SPI.begin(); // Init SPI bus
      rfid.PCD_Init(); // Init MFRC522 
      for (byte i = 0; i < 6; i++) 
      {
        key.keyByte[i] = 0xFF;
      }
      printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
      Serial.println();
    }
     
    void loop() 
    {
    
      if ( ! rfid.PICC_IsNewCardPresent())
        return;
      if ( ! rfid.PICC_ReadCardSerial())
        return;
    
        //  Serial.print(F("PICC type: "));
       MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
       //  Serial.println(rfid.PICC_GetTypeName(piccType));
    
      // Check is the PICC of Classic MIFARE type
      if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) 
          {
            Serial.println(F("Your tag is not of type MIFARE Classic."));
            return;
          }
        // Store NUID into nuidPICC array
        for (byte i = 0; i < 4; i++) 
        {
          nuidPICC[i] = rfid.uid.uidByte[i];
        }
       
        printHex(rfid.uid.uidByte, rfid.uid.size);
        Serial.println();
      // Halt PICC
      rfid.PICC_HaltA();
    
      // Stop encryption on PCD
      rfid.PCD_StopCrypto1();
    }
    
    
    void printHex(byte *buffer, byte bufferSize)
    {
      for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
      }
    }

    Thanks in advance


    heba ayass

    Saturday, June 30, 2018 7:35 AM

Answers