Programming Help

The program im trying to upload to an Arduino UNO is as follows,

/**

  • Read a card using a mfrc522 reader on your SPI interface
  • Pin layout should be as follows (on Arduino Uno):
  • MOSI: Pin 11 / ICSP-4
  • MISO: Pin 12 / ICSP-1
  • SCK: Pin 13 / ISCP-3
  • SS: Pin 10
  • RST: Pin 9
  • Script is based on the script of Miguel Balboa.
  • New cardnumber is printed when card has changed. Only a dot is printed
  • if card is the same.
  • @version 0.1
  • @author Henri de Jong
  • @since 06-01-2013
    */

#include <SPI.h>
#include <RFID.h>

#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN, RST_PIN);

int buzzPin = 3;

// Setup variables:
int serNum0;
int serNum1;
int serNum2;
int serNum3;
int serNum4;

void setup()
{
Serial.begin(9600);
SPI.begin();
rfid.init();
}

void loop()
{

if (rfid.isCard()) {
if (rfid.readCardSerial()) {
if (rfid.serNum[0] != serNum0
&& rfid.serNum[1] != serNum1
&& rfid.serNum[2] != serNum2
&& rfid.serNum[3] != serNum3
&& rfid.serNum[4] != serNum4
) {
/* With a new cardnumber, show it. */
Serial.println(" ");
Serial.println("Card found");
serNum0 = rfid.serNum[0];
serNum1 = rfid.serNum[1];
serNum2 = rfid.serNum[2];
serNum3 = rfid.serNum[3];
serNum4 = rfid.serNum[4];

//Serial.println(" ");
Serial.println("Cardnumber:");
Serial.print("Dec: ");
Serial.print(rfid.serNum[0],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[1],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[2],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[3],DEC);
Serial.print(", ");
Serial.print(rfid.serNum[4],DEC);
Serial.println(" ");

Serial.print("Hex: ");
Serial.print(rfid.serNum[0],HEX);
Serial.print(", ");
Serial.print(rfid.serNum[1],HEX);
Serial.print(", ");
Serial.print(rfid.serNum[2],HEX);
Serial.print(", ");
Serial.print(rfid.serNum[3],HEX);
Serial.print(", ");
Serial.print(rfid.serNum[4],HEX);
Serial.println(" ");
//buzzer
analogWrite(3,20);
delay(500);
analogWrite(3,0);
} else {
/* If we have the same ID, just write a dot. */
Serial.print(".");
}
}
}

rfid.halt();
}

Now, when I click verify or upload I get an error. The screenshot of the errror is in the attachment. Any help is appreciated and it would be awesome if someone could fix the program but upload the fixed copy to this thread. Thanks so much :slight_smile:

Ard.PNG

Several things. First, many people here are reluctant to open any file they cannot confirm. To get better responses here, please read Nick Gammon's post at the top of this Forum title how to post to this Forum, especially the use of code tags when presenting code listings. Next, you'd be better off to display the error message than to expect people here to open an unknown file. Finally, see if Ctrl-T on your source code when it's in the IDE makes it easier to read.

Image from Original Post so we don't have to download it. See this Image Guide

ce1cb00f28eb2029b965348b4dfbc8371fe9ab16.png

...R

Where did you install the RFID library?

.

You need to review how you have spelled things. Programming code is case-sensitive.

And, as @econjack has said, it is much better if you post error messages as text.

And please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

...R

http://forum.arduino.cc/index.php?topic=445671.0

Maybe if you keep asking the same question you'll get a different response?

Ok, first off sorry about the things I did wrong with the post (ex. having to download the picture) its my first one. I will address every question in order.

  1. @econjack Sorry about the mistakes I made and when I press CTRL T it says that no changes are necessary for Auto Format.

  2. @LarryD I installed the library on my desktop.

  3. @Robin2 I will post them as text in the future and as far as the modified post, here it is

/**
 * Read a card using a mfrc522 reader on your SPI interface
 * Pin layout should be as follows (on Arduino Uno):
 * MOSI: Pin 11 / ICSP-4
 * MISO: Pin 12 / ICSP-1
 * SCK: Pin 13 / ISCP-3
 * SS: Pin 10
 * RST: Pin 9
 *
 * Script is based on the script of Miguel Balboa. 
 * New cardnumber is printed when card has changed. Only a dot is printed
 * if card is the same.
 *
 * @version 0.1
 * @author Henri de Jong
 * @since 06-01-2013
 */

#include <SPI.h>
#include <RFID.h>

#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN, RST_PIN); 

int buzzPin = 3;

// Setup variables:
int serNum0;
int serNum1;
int serNum2;
int serNum3;
int serNum4;

void setup()
{ 
  Serial.begin(9600);
  SPI.begin(); 
  rfid.init();
}

void loop()
{

  if (rfid.isCard()) {
    if (rfid.readCardSerial()) {
      if (rfid.serNum[0] != serNum0
        && rfid.serNum[1] != serNum1
        && rfid.serNum[2] != serNum2
        && rfid.serNum[3] != serNum3
        && rfid.serNum[4] != serNum4
        ) {
        /* With a new cardnumber, show it. */
        Serial.println(" ");
        Serial.println("Card found");
        serNum0 = rfid.serNum[0];
        serNum1 = rfid.serNum[1];
        serNum2 = rfid.serNum[2];
        serNum3 = rfid.serNum[3];
        serNum4 = rfid.serNum[4];

        //Serial.println(" ");
        Serial.println("Cardnumber:");
        Serial.print("Dec: ");
        Serial.print(rfid.serNum[0],DEC);
        Serial.print(", ");
        Serial.print(rfid.serNum[1],DEC);
        Serial.print(", ");
        Serial.print(rfid.serNum[2],DEC);
        Serial.print(", ");
        Serial.print(rfid.serNum[3],DEC);
        Serial.print(", ");
        Serial.print(rfid.serNum[4],DEC);
        Serial.println(" ");

        Serial.print("Hex: ");
        Serial.print(rfid.serNum[0],HEX);
        Serial.print(", ");
        Serial.print(rfid.serNum[1],HEX);
        Serial.print(", ");
        Serial.print(rfid.serNum[2],HEX);
        Serial.print(", ");
        Serial.print(rfid.serNum[3],HEX);
        Serial.print(", ");
        Serial.print(rfid.serNum[4],HEX);
        Serial.println(" ");
        //buzzer
        analogWrite(3,20);
        delay(500);
        analogWrite(3,0);
      } 
      else {
        /* If we have the same ID, just write a dot. */
        Serial.print(".");
      }
    }
  }

  rfid.halt();
}

Also, @Robin2 what is spelled/capitalized incorrectly?

@LarryD I installed the library on my desktop.

Read this:

.

Cdaman:

  1. @econjack Sorry about the mistakes I made and when I press CTRL T it says that no changes are necessary for Auto Format.

New people here rarely read the How To sticky, so that's not a problem. Ctrl-T probably wouldn't make any difference on your code as it's pretty-well formatted as it is. However, sometimes even reformatting can catch those "flat forehead" mistakes (you know, where you slam the heel of your hand into your forehead wondering how you could make such a silly mistake) before they happen.

Cdaman:
Also, @Robin2 what is spelled/capitalized incorrectly?

I don't know the answer to that. I just noticed that the error messages have both "RFID" and "rfid" - maybe they are both required.

...R

I don't know the answer to that. I just noticed that the error messages have both "RFID" and "rfid" - maybe they are both required.

Because the class name is RFID and the instance name is rfid.

OP: In your other post, and again in this one, you were told to post ALL of the error messages, not just the snippet that fits in the window. Why haven't you?

I've now imported the library and that has got rid of the previous error messages. Now I am getting a different one... My code has stayed the same but here are the new errors. (These are the verbose output)

RFID\SPI.cpp.o: In function `SPIClass::begin()':

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:24: undefined reference to `SPIClass::pinMode(unsigned char, unsigned char)'

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:25: undefined reference to `SPIClass::pinMode(unsigned char, unsigned char)'

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:26: undefined reference to `SPIClass::pinMode(unsigned char, unsigned char)'

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:28: undefined reference to
`SPIClass::digitalWrite(unsigned char, unsigned char)'

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:29: undefined reference to `SPIClass::digitalWrite(unsigned char, unsigned char)'

C:\Users\Cody\Documents\Arduino\libraries\RFID/SPI.cpp:30: undefined reference to `SPIClass::digitalWrite(unsigned char, unsigned char)'

@PaulS those were all the errors that I got.

I've now imported the library

From where?

@PaulS those were all the errors that I got.

I find it hard to believe that there were no messages about not being able to find RFID.h.

Never mind, I solved the problem. It was a combination of things such as me running a outdated version of Arduino, needing to import the library, and helping the program find some files. Thanks for all your help!