Unsigned Char using RFID MFRC522

Thread Starter

jcordeiro

Joined Nov 27, 2019
1
I am brand new to Arduino programming and am having a difficult time getting my code to compile.

The goal is to create a puzzle with four readers and to compare the UID codes and readers against a known key. In other words, put the tags in the correct order and the puzzle will unlock. I have removed the unneeded PICC information, the LED and relay related code to simplify this but I cannot get past getting the UIDs associated with the variable RFID. I have tried byte, string and byte string. I searched the internet and tired a number of options and looked through the MFRC522 library but it is beyond my skill level.

My plan is to use the string value of RFID against string value Key to toggle the boolean Correct ID. Get it right and the LEDs and relay state change and the puzzle resets after a delay. Get it wrong and the led flashes and the loop continues.

I can get the serial tags to read if I just dump the IDs to serial but I need to have the values associated with a string value to compare to the Key string value.

Here is the error:

Multiple libraries were found for "MFRC522.h"
Used: C:\Users\John Cordeiro\Documents\Arduino\libraries\MFRC522
Not used: C:\Users\John Cordeiro\Documents\Arduino\libraries\arduino_510303
exit status 1
invalid types 'byte {aka unsigned char}[uint8_t {aka unsigned char}]' for array subscript


Any help would be greatly appreciated.


Code is below


#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 6 // Define reset pin
#define SS_1_PIN 2 // Slave Select for Reader 1
#define SS_2_PIN 3 // Slave Select for Reader 2
#define SS_3_PIN 4 // Slave Select for Reader 3
#define SS_4_PIN 5 // Slave Select for Reader 4

#define NR_OF_READERS 4 // define number of RFID readers



#define Key_1 ("19 15 61 B9") //Good Key Reader #1
#define Key_2 ("E9 0B 65 B9") //Good Key Reader #2
#define Key_3 ("69 D6 60 98") //Good Key Reader #3
#define Key_4 ("C9 BE 61 B9") //Good Key Reader #4

boolean CorrectID = false; //sets the dafault state to lock

int Short_Delay = 500; // short delay to prevent RFID timeout

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN}; //Slave select

String Key[] = {Key_1, Key_2, Key_3, Key_4}; // Correct key to open puzzle

String RFID[NR_OF_READERS]; //Not sure if this is how this is done, want a the read values of the RFIDs to be stored in a string


MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.

/**
* Initialize.
*/
void setup() {

Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

SPI.begin(); // Init SPI bus

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader ")); //print reader
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial(); //print version number of RFID reader
delay (Short_Delay);
}
}

/**
* Main loop.
*/
void loop() {

for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) //Cycle through the readers
{

if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) //Look for new card
{
Serial.print(F("Reader ")); //Print Reeader
Serial.print(reader); //Print reader #
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(": Card UID:")); // Print UID



RFID[reader] = dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size [reader]); // set uid to RFID

//command above causes error "**causes the error " invalid types 'byte {aka unsigned char}[uint8_t {aka unsigned char}]' for array subscript"

Serial.println();
//Serial.print(F("PICC type: "));
//MFRC522::pICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
//Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));


// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
}
}
}

/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer < 0x10 ? " 0" : " ");
Serial.print(buffer, HEX);
}
}
 

BobaMosfet

Joined Jul 1, 2009
2,110
You're mis-understanding your error:

This is your error: Multiple libraries were found for "MFRC522.h"

Used: C:\Users\John Cordeiro\Documents\Arduino\libraries\MFRC522
Not used: C:\Users\John Cordeiro\Documents\Arduino\libraries\arduino_510303
exit status 1
This is because of the first error: invalid types 'byte {aka unsigned char}[uint8_t {aka unsigned char}]' for array subscript

You are including a header file, and elsewhere in your compiler you're telling it to link in more than 1 file which that header file could be used for. The compiler can't tell which one, so it's defaulting to either the first or the last one it found, and there is a type mismatch between them.

Figure out which is the correct file to include, or #ifdef a redefinition in your source file after the include. (This is why as a general rule in C/C++, defines are done after includes, so you can override what's in linked in libraries if necessary.
 
Top