Need help this fix arduino the error code please ?

im still beginner in arduino and i dont have any tutor to ask for ,i put the spi and mfrc522 library already ,please help me fix this error

The copy error messages
Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Uno"

sketch_sep10a_teqj:10: error: 'MIFARE_Key' in 'class MFRC522' does not name a type

MFRC522::MIFARE_Key key;

          ^

sketch_sep10a_teqj:13: error: array must be initialized with a brace-enclosed initializer

byte keyA[6] = (0x38,0xf5,0x86,0x03,0x3c,0x2a);  //KeyA

                                              ^

sketch_sep10a_teqj:21: error: 'mfrc522' does not name a type

mfrc522.PCD_Init()://Init MFRC522 card

^

C:\Users\Muhammad Adli\Documents\Arduino\sketch_sep10a_teqj\sketch_sep10a_teqj.ino: In function 'void loop()':

sketch_sep10a_teqj:27: error: invalid use of member function (did you forget the '()' ?)

   Serial.begin = "*";

                ^

sketch_sep10a_teqj:28: error: 'class MFRC522' has no member named 'PICC_IsNewCardPresent'

   if ( ! mfrc522.PICC_IsNewCardPresent()) {

                  ^

sketch_sep10a_teqj:35: error: 'class MFRC522' has no member named 'PICC_ReadCardSerial'

   if (! mfrc522.PICC_ReadCardSerial()

                 ^

sketch_sep10a_teqj:36: error: expected ')' before '}' token

}{

^

sketch_sep10a_teqj:36: error: expected primary-expression before '}' token

C:\Users\Muhammad Adli\Documents\Arduino\sketch_sep10a_teqj\sketch_sep10a_teqj.ino: At global scope:

sketch_sep10a_teqj:36: error: expected unqualified-id before '{' token

}{

  ^

sketch_sep10a_teqj:48: error: 'Serial' does not name a type

Serial.printIn();

^

sketch_sep10a_teqj:49: error: 'Serial' does not name a type

Serial.print(PROGMEM(*Card UID: *));

^

sketch_sep10a_teqj:50: error: expected constructor, destructor, or type conversion before '(' token

printHEX(mfrc522.uid.uidByte, mfrc522.uid.size);

         ^

sketch_sep10a_teqj:52: error: 'Serial' does not name a type

Serial.printIn();

^

sketch_sep10a_teqj:53: error: 'Serial' does not name a type

Serial.print(PROGMEM("PICC type: *"));

^

sketch_sep10a_teqj:54: error: 'PICC_Type' in 'class MFRC522' does not name a type

MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);

          ^

sketch_sep10a_teqj:55: error: 'Serial' does not name a type

Serial.printIn(mfrc522.PICC_GetTypeName(piccType));

^

sketch_sep10a_teqj:58: error: expected unqualified-id before 'if'

if (    piccType != MFRC522::PICC_TYPE_MIFARE_MINI

^

sketch_sep10a_teqj:64: error: expected unqualified-id before 'return'

             return;

             ^

sketch_sep10a_teqj:68: error: 'StatusCode' in 'class MFRC522' does not name a type

MFRC522::StatusCode status;

          ^

sketch_sep10a_teqj:72: error: expected unqualified-id before 'for'

             for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)

             ^

sketch_sep10a_teqj:72: error: 'i' does not name a type

             for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)

                              ^

sketch_sep10a_teqj:72: error: 'i' does not name a type

             for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)

                                                        ^

sketch_sep10a_teqj:78: error: 'Serial' does not name a type

Serial.print (PROGMEM("Authenticating with key A...: )");

^

sketch_sep10a_teqj:79: error: 'status' does not name a type

               status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522 ::

               ^

sketch_sep10a_teqj:81: error: expected unqualified-id before 'if'

if (status != MFRC522::STATUS_OK) {

^

sketch_sep10a_teqj:88: error: expected unqualified-id before 'else'

else

^

sketch_sep10a_teqj:92: error: 'Serial' does not name a type

   Serial.print(PROGMEM("Reading data from block "));

   ^

sketch_sep10a_teqj:93: error: 'Serial' does not name a type

   Serial.printIn(blockNoStaff);

   ^

sketch_sep10a_teqj:94: error: 'status' does not name a type

   status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockNoStaff, buffer, &size);

   ^

sketch_sep10a_teqj:95: error: expected unqualified-id before 'if'

   if (status != MFRC522::STATUS_OK) {

   ^

sketch_sep10a_teqj:100: error: expected unqualified-id before 'for'

for (byte i = 0; i <= 15; i++) {

^

sketch_sep10a_teqj:100: error: 'i' does not name a type

for (byte i = 0; i <= 15; i++) {

                  ^

sketch_sep10a_teqj:100: error: 'i' does not name a type

for (byte i = 0; i <= 15; i++) {

                           ^

sketch_sep10a_teqj:106: error: 'Serial' does not name a type

Serial.print(PROGMEM("Raw Data in block"));

^

sketch_sep10a_teqj:107: error: 'Serial' does not name a type

Serial.print(blockNoStaff);

^

sketch_sep10a_teqj:108: error: 'Serial' does not name a type

Serial.printIn(PROGMEM(":"));

^

sketch_sep10a_teqj:109: error: expected constructor, destructor, or type conversion before '(' token

printHex(buffer, 16);

         ^

sketch_sep10a_teqj:112: error: expected constructor, destructor, or type conversion before '(' token

decode(byte_serial, byte_nostaf, byte_key);

       ^

sketch_sep10a_teqj:113: error: 'Serial' does not name a type

Serial.printIn(" ");

^

sketch_sep10a_teqj:114: error: 'Serial' does not name a type

Serial.printIn("No Staf after decode: ");

^

sketch_sep10a_teqj:115: error: expected constructor, destructor, or type conversion before '(' token

printIn(byte_nostaf, 10);

        ^

sketch_sep10a_teqj:125: error: 'mfrc522' does not name a type

mfrc522.PICC_HaltA();

^

sketch_sep10a_teqj:127: error: 'mfrc522' does not name a type

mfrc522.PCD_StopCryptol();

^

sketch_sep10a_teqj:128: error: expected declaration before '}' token

}

^

exit status 1
'MIFARE_Key' in 'class MFRC522' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.






THIS the code:

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

#define  RST_PIN     9   // MFRC Reset Pin
#define  SS_PIN      10  // MFRC SPI Pin


MFRC522 mfrc522(SS_PIN, RST_PIN); //Create MFRC522 instance.

MFRC522::MIFARE_Key key;

byte blockNoStaf = 10;
byte keyA[6] = (0x38,0xf5,0x86,0x03,0x3c,0x2a);  //KeyA
String nostaf;
String serial;

byte byte_nostaf[16];
byte byte_serial[4];
byte byte_key[4] = {0xb5,0xcf,0x60,0x71};

mfrc522.PCD_Init()://Init MFRC522 card
  Serial.printIn(("Sedia untuk imbas kad staffUSM"));
  // put your setup code here, to run once:


  void loop() {
  Serial.begin = "*";
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    //TODO: RED LED ON indicate error
    //TODO: Display error at LCD Display
    return;
  }

  // 2 Select one of the cards
  if (! mfrc522.PICC_ReadCardSerial()
}{
//TODO: RED LED ON indicate error
//TODO: Display error at LCD Display
return;

//get the card UID
for (byte i = 0; i < mfrc522.uid.size; i++)(
      Serial += String(mfrc522.uid.uidByte[i], HEX);
      byte-Serial[i] = mfrc522.uid.uidByte[i];
  }

// 3 show some detail of the PICC (hat is: the tag /card)
Serial.printIn();
Serial.print(PROGMEM(*Card UID: *));
printHEX(mfrc522.uid.uidByte, mfrc522.uid.size);

Serial.printIn();
Serial.print(PROGMEM("PICC type: *"));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.printIn(mfrc522.PICC_GetTypeName(piccType));

//3.1 Check for compatibility
if (    piccType != MFRC522::PICC_TYPE_MIFARE_MINI
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_IK
        &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) (
            Serial.printIn(PROGMEM("This sample only works with MIFARE Classic cards.*"));
            //TODO: RED LED ON indicate error
            //TODO: Display error at LCD Display
            return;



MFRC522::StatusCode status;
byte buffer[18];
byte size = sizeof(buffer);

            for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
            key.keyByte[i] = keyA[i];


// 4 Authenticate using key A

Serial.print (PROGMEM("Authenticating with key A...: )");
              status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522 ::
                       PICC_CMD_MF_AUTH_KEY_A, blockNoStaff, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print (PROGMEM("PCD_Authenticate() failed: "));
  Serial.printIn(mfrc522.GetStatusCodeName(status));
  //TODO: RED LED for error
  //TODO: Display Error on LCD
  return;
}
else
  Serial.printIn("success");

  //  5 Read data from the block
  Serial.print(PROGMEM("Reading data from block "));
  Serial.printIn(blockNoStaff);
  status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockNoStaff, buffer, &size);
  if (status != MFRC522::STATUS_OK) {
  Serial.print(PROGMEM("MIFARE_Read()"" failed "));
    Serial.printIn(mfrc522.GetStatusCodeName(status));
  }

for (byte i = 0; i <= 15; i++) {
nostaf += String(buffer[i], HEX);
  byte_nostaf[i] = buffer[i];
}


Serial.print(PROGMEM("Raw Data in block"));
Serial.print(blockNoStaff);
Serial.printIn(PROGMEM(":"));
printHex(buffer, 16);

// 5 decode data dalam kad
decode(byte_serial, byte_nostaf, byte_key);
Serial.printIn(" ");
Serial.printIn("No Staf after decode: ");
printIn(byte_nostaf, 10);

// 6 hantar nostaf ke frapi guna ethernet modul

// 7 papar result
// LED Hijau success
// LED Merah failed
// Papar result pada LCD

// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCryptol();
}

void printHex(byte *buffer, byte buffersize)
for (byte i = 0; i < buffersize; i++;) {
Serial.print(buffer[i] < 0 * 10 ? " 0 " : " ");
  Serial.print(buffer[i], HEX);
}
}

void printDec(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++;) {
    //  Serial.print(buffer[i] < 0*10 ? " 0 " : " ");
    Serial.print(buffer[i], DEC);
  }
}

void printBin(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i], BIN); Serial.print(" ");
  }
}
void printIn(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.write(buffer[i]); Serial.print(" ");
  }
}

void decode (byte *serial, byte *nostaf, byte *key) {
  int j = 0;
  for (int i = 0; i <= 15; i++) {
    j = i % 4;
    int a = serial[j] ^ key[j];
    nostaf[i] = a ^ nostaf[i];
  }
}

steveastrouk2 months ago

A real mess. It looks like you have cut and pasted code from multiple sources. (And, apparently, languages)

the KeyA variable is mis-declated.

Your subroutines should be before the code that calls them.

You use printin, not println repeatedly.

I can make it compile.

Where did your item "PROGMEM" come from ? Its not declared here.

iceng2 months ago

Try to debug a "Hello" as a first project...

steveastrouk2 months ago

Post a link to exactly where you got the code from, and perhaps we can see.