Compilation error: expected identifier before numeric constant

I keep getting this error, but not sure why. Can anyone figure it out? I am trying to compare an RFID input to an array of allowed tag IDs, and then reset the sensed ID each iteration. But resetting the uid value seems to be causing the error, but I don't know why. Any thoughts?

// This project is to use an RFID reader (PN532 chipset) with a 16x2 LCD display to control "something"
// What that something is... well that is up to you.
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>

SoftwareSerial SWSerial( 3, 2 ); // RX, TX
 
PN532_SWHSU pn532swhsu( SWSerial );
PN532 nfc( pn532swhsu );
String tagId = "None", dispTag = "None"; // global variable to store tag ID as a string
byte nuidPICC[4]; // global variable to store tag ID as an array of 4 bytes
 
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define authorized tags.  Change the Allowed ID Count based on the number needed, and the code will adapt.  
// If ARRAYSIZE is larger than the permitted number of tags, then the system will be more prone to hacking.
#define ALLOWEDIDCOUNT 2
byte allowedId[ALLOWEDIDCOUNT][4] =
{
  {0xEE, 0xAD, 0xEF, 0xF1},  // 238.173.239.241
  {0xCE, 0x2F, 0xF3, 0xF1},  // 206.47.243.241
};

bool allowed = false;

void setup(void)
{
  Serial.begin(115200);
  Serial.println("Hello Maker!");
  //  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata)
  {
    Serial.print("Didn't Find PN53x Module");
    while (1); // Halt
  }
  // Got valid data, print it out!
  Serial.print("Found chip PN5");
  Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. ");
  Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.'); 
  Serial.println((versiondata >> 8) & 0xFF, DEC);
  // Configure board to read RFID tags
  nfc.SAMConfig();
  //Serial.println("Waiting for an ISO14443A Card ...");

	// initialize the LCD
	lcd.init();
	// Turn on the blacklight and print a message.
	lcd.backlight();
	lcd.setCursor(0,0);
  lcd.print("Hello Ross,");
  lcd.setCursor(0,1);
  lcd.print("Setup Complete.");
  delay(2000);  // 2 second wait
  lcd.noBacklight();
}
 
 
void loop()
{
  // Reset variables in case last iteration read an allowed ID
  nuidPICC = [0x00, 0x00, 0x00, 0x00];

  // Read RFID tag if present
  readNFC();

  // Check to see if read tag (or default value) match an allowed ID
  // Sets global "allowed" boolean. LEFT OFF HERE.  NOT YET WORKING
  checkNFC();

  if (allowed)
    // do something for allowed tag
    Serial.println("Arrays Match");
  else
    // output denial message
    Serial.println("No Match");
  }
}
 
 
void readNFC()
{
  boolean success = false;  //init variable to start the WHILE loop below
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                       // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  while !success {
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
    if (!success)
    {
      Serial.println("Waiting for RFID Tag...");
      delay(500);   // .5 second delay
    }
  }

  // Loop has exited, which means a card was read  
  Serial.print("UID Length: ");
  Serial.print(uidLength, DEC);
  Serial.println(" bytes");
  Serial.print("UID Value: ");
  for (uint8_t i = 0; i < uidLength; i++)
  {
    nuidPICC[i] = uid[i];
    Serial.print(" "); Serial.print(uid[i], DEC);
  }
  Serial.println();
  tagId = tagToString(nuidPICC);
  dispTag = tagId;
  Serial.print(F("tagId is : "));
  Serial.println(tagId);
  Serial.println("");

  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Tag ID: ");
  lcd.setCursor(0,1);
  lcd.print(tagId);
  delay(2000);  // 2 second wait
  lcd.noBacklight();
}

void checkNFC()
{
  allowed = false;
  for (int i = 0; i < ALLOWEDIDCOUNT; i++) {
  Serial.print("Testing Match with allowedID ");
  Serial.println(i);
  if (memcmp(nuidPICC, allowedID[i], 4) == 0)
    Serial.println("Arrays Match");
    allowed = true;
  else
    Serial.println("No Match");
  }
}

String tagToString(byte id[4])
{
  String tagId = "";
  for (byte i = 0; i < 4; i++)
  {
    if (i < 3) tagId += String(id[i]) + ".";
    else tagId += String(id[i]);
  }
  return tagId;
}

Thanks.

have a look at how-to-get-the-best-out-of-this-forum
in File>Preferences click Show Verbose output during compile
then compile the code
then copy and upload the error listing as text

Does NOBODY bother to actually read the error compiler messages? Everyone paraphrases the error message, almost always leaving out virually ALL of the useful information. Little details like the line number, and character position showing PRECISELY where the error actually IS. READ THE MESSSAGE. IF you want help understanding it, POST THE ENTIRE ERROR MESSAGE. That much should be obvious, even to a beginner...

Ooops

@PerryBebbington thanks, yes, I know its that line from the compiling, but I can't figure out the right syntax to do that. Can you point me in the right direction?

Hello pixabits

Take a search engine of your choice and ask the WWW for "nuidPICC".

Have a nice day and enjoy coding in C++.

Oh, google:

About 908 results (0.27 seconds)


Did you mean: nude pic

a7

You can't use an assignment statement to set all elements at once in an array like that. You must use a loop to iterate through one element at a time.

@pixabits

I'm at my desk now so I can give you a better answer.

For an array you correctly declared it with:

The [4] tells the compiler you want an array with 4 elements. Note the brackets are [] (not {} or () or even <> ).
When you first declare an array you can initialise it, for example:

byte nuidPICC[4] = {0x00, 0x00, 0x00, 0x00};

But that only works when you declare it, and note which kinds of brackets are used, and where they are used.

If you want to change the values in each element of the array after that then you have to do them one at a time, for example:

    uint8_t i;
    for (i = 0; i < 4; ++i) {
        nuidPICC[i] = 0x00;
    }

Will do what I think you want.

See https://www.arduino.cc/reference/en/language/variables/data-types/array/ for more information.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.