how to ammend this program to read 17 pages of a mifare card

:confused: i am in the process of setting up my Arduino and Adafruit PN532 Sheild to read and rewrite NFC tags and cards for use in my XYZ Da Vinci Junior 3D Printer to avoid using the limiting set up which is imposed by them. My intention is to read and edit the pages 0A, 0B, 8, 14, 15, 16 and 17 to ammend the filament lengt, colour and temperature. This is because i wish to used aftermarket filament but need to be able to read and write NFC tags to use them.

Here is the Program i have so far:

*/
/**************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK (2)
#define PN532_MOSI (3)
#define PN532_SS (4)
#define PN532_MISO (5)

// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines. Use the values below (2, 3) for the shield!
#define PN532_IRQ (2)
#define PN532_RESET (3) // Not connected by default on the NFC Shield

// Uncomment just one line below depending on how your breakout or shield
// is connected to the Arduino:

// Use this line for a breakout with a software SPI connection (recommended):
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

// Use this line for a breakout with a hardware SPI connection. Note that
// the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino’s
// hardware SPI SCK, MOSI, and MISO pins. On an Arduino Uno these are
// SCK = 13, MOSI = 11, MISO = 12. The SS line can be any digital IO pin.
//Adafruit_PN532 nfc(PN532_SS);

// Or use this line for a breakout or shield with an I2C connection:
//Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
// also change #define in Adafruit_PN532.cpp library file
#define Serial SerialUSB
#endif

void setup(void) {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(115200);
Serial.println(“Hello!”);

nfc.begin();

uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print(“Didn’t find PN53x board”);
while (1); // halt
}
// Got ok 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 …”);
}

void loop(void) {
uint8_t success;
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)

// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// ‘uid’ will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

if (success) {
// Display some basic information about the card
Serial.println(“Found an ISO14443A card”);
Serial.print(" UID Length: “);Serial.print(uidLength, DEC);Serial.println(” bytes");
Serial.print(" UID Value: “);
nfc.PrintHex(uid, uidLength);
Serial.println(”");

if (uidLength == 4)
{
// We probably have a Mifare Classic card …
Serial.println(“Seems to be a Mifare Classic card (4 byte UID)”);

// Now we need to try to authenticate it for read/write access
// Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
Serial.println(“Trying to authenticate block 4 with default KEYA value”);
uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

// Start with block 4 (the first block of sector 1) since sector 0
// contains the manufacturer data and it’s probably better just
// to leave it alone unless you know what you’re doing
success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);

if (success)
{
Serial.println(“Sector 1 (Blocks 4…7) has been authenticated”);
uint8_t data[16];

// If you want to write something to block 4 to test with, uncomment
// the following line and this text should be read back in a minute
//memcpy(data, (const uint8_t){ ‘a’, ‘d’, ‘a’, ‘f’, ‘r’, ‘u’, ‘i’, ‘t’, ‘.’, ‘c’, ‘o’, ‘m’, 0, 0, 0, 0 }, sizeof data);
// success = nfc.mifareclassic_WriteDataBlock (4, data);

// Try to read the contents of block 4
success = nfc.mifareclassic_ReadDataBlock(4, data);

if (success)
{
// Data seems to have been read … spit it out
Serial.println(“Reading Block 4:”);
nfc.PrintHexChar(data, 16);
Serial.println("");

// Wait a bit before reading the card again
delay(1000);
}
else
{
Serial.println(“Ooops … unable to read the requested block. Try another key?”);
}
}
else
{
Serial.println(“Ooops … authentication failed: Try another key?”);
}
}

if (uidLength == 7)
{
// We probably have a Mifare Ultralight card …
Serial.println(“Seems to be a Mifare Ultralight tag (7 byte UID)”);

// Try to read the first general-purpose user page (#4)
Serial.println(“Reading page 4”);
uint8_t data[32];
success = nfc.mifareultralight_ReadPage (4, data);
if (success)
{
// Data seems to have been read … spit it out
nfc.PrintHexChar(data, 4);
Serial.println("");

// Wait a bit before reading the card again
delay(1000);
}
else
{
Serial.println(“Ooops … unable to read the requested page!?”);
}
}
}
}

the set up i am using is using arduinos software ‘Arduino.exe’
a standard Arduino Uno connected to my windows PC using the USB connector supplied.
attatched directly to the arduino using the connecting blocks that were provided.

Please post your code in code tags.

I see that you did write a program. But, I don't see any issue/problem mentioned anywhere. How are we supposed to help you if you don't tell us the problem ?

the problem is i didnt write the program and have no experience with software programming, i am a CNC Machine Programmer by trade but i havent a clue about how to write this kind of program, so what i am after is an adaption of the program which will allow me to read all of the NFC Tag's pages (specifically 0A to 17) the cards i am wanting to read/rewrite are Mifare Ultra Lites... my intention is to amend the current card used in my printer.... and to make the eventual program as user friendly as possible. i intend to make the final varient a freeware item for use on the Da Vinci junior Printers.

First of all i would like to clarify i am a complete newbie to programming this kind of device and have limited knowledge of the capabilities of Arduinos.

My intentions are to produce a program which utalises Adafruits PN532 Sheild with a standard Arduino Uno R3

links to the hardware being used:

i am have these components set up so that the sheild is connected to the following pins on the arduino:

IOREF
RESET
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
0->RX
1<-TX
2
3
4
5
6
7
8
9
10
11
12
13
GND
AREF
SDA
SCL

Is this all that is required or have i missed anything?
I am connecting to my PC using the USB Lead

I have Also downloaded Adafruit’s library file for the PN532 Sheild

which has provided me with the following program:

/*! 
    @file     readMifare.pde
    @author   Adafruit Industries
	@license  BSD (see license.txt)

    This example will wait for any ISO14443A card or tag, and
    depending on the size of the UID will attempt to read from it.
   
    If the card has a 4-byte UID it is probably a Mifare
    Classic card, and the following steps are taken:
   
    - Authenticate block 4 (the first block of Sector 1) using
      the default KEYA of 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF
    - If authentication succeeds, we can then read any of the
      4 blocks in that sector (though only block 4 is read here)
	 
    If the card has a 7-byte UID it is probably a Mifare
    Ultralight card, and the 4 byte pages can be read directly.
    Page 4 is read by default since this is the first 'general-
    purpose' page on the tags.


This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout 
  ----> https://www.adafruit.com/products/364
 
Check out the links above for our tutorials and wiring diagrams 
These chips use SPI or I2C to communicate.

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

*/
/**************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (2)
#define PN532_MOSI (3)
#define PN532_SS   (4)
#define PN532_MISO (5)

// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Uncomment just _one_ line below depending on how your breakout or shield
// is connected to the Arduino:

// Use this line for a breakout with a software SPI connection (recommended):
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

// Use this line for a breakout with a hardware SPI connection.  Note that
// the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's
// hardware SPI SCK, MOSI, and MISO pins.  On an Arduino Uno these are
// SCK = 13, MOSI = 11, MISO = 12.  The SS line can be any digital IO pin.
//Adafruit_PN532 nfc(PN532_SS);

// Or use this line for a breakout or shield with an I2C connection:
//Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
// also change #define in Adafruit_PN532.cpp library file
   #define Serial SerialUSB
#endif

void setup(void) {
  #ifndef ESP8266
    while (!Serial); // for Leonardo/Micro/Zero
  #endif
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok 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 ...");
}


void loop(void) {
  uint8_t success;
  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)
    
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    Serial.println("");
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
	  
      // Now we need to try to authenticate it for read/write access
      // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
      Serial.println("Trying to authenticate block 4 with default KEYA value");
      uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
	  
	  // Start with block 4 (the first block of sector 1) since sector 0
	  // contains the manufacturer data and it's probably better just
	  // to leave it alone unless you know what you're doing
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
	  
      if (success)
      {
        Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
        uint8_t data[16];
		
        // If you want to write something to block 4 to test with, uncomment
		// the following line and this text should be read back in a minute
        //memcpy(data, (const uint8_t[]){ 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0 }, sizeof data);
        // success = nfc.mifareclassic_WriteDataBlock (4, data);

        // Try to read the contents of block 4
        success = nfc.mifareclassic_ReadDataBlock(4, data);
		
        if (success)
        {
          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 4:");
          nfc.PrintHexChar(data, 16);
          Serial.println("");
		  
          // Wait a bit before reading the card again
          delay(1000);
        }
        else
        {
          Serial.println("Ooops ... unable to read the requested block.  Try another key?");
        }
      }
      else
      {
        Serial.println("Ooops ... authentication failed: Try another key?");
      }
    }
    
    if (uidLength == 7)
    {
      // We probably have a Mifare Ultralight card ...
      Serial.println("Seems to be a Mifare Ultralight tag (7 byte UID)");
	  
      // Try to read the first general-purpose user page (#8)
      Serial.println("Reading page 4");
      uint8_t data[32];
      success = nfc.mifareultralight_ReadPage (8, data);
      if (success)
      {
        // Data seems to have been read ... spit it out
        nfc.PrintHexChar(data, 8);
        Serial.println("");
		
        // Wait a bit before reading the card again
        delay(1000);
      }
      else
      {
        Serial.println("Ooops ... unable to read the requested page!?");
      }
    }
  }
}

The information i which to access and edit are the pages:

0A
0B
08
14
15
16
17

In the grand Scheme of thigs i am asking:

Have i got the Hardware Set Up Correctly?
Have i got the correct settings in arduino.exe (Arduino Uno & COM4)
What do i need to ammend on the program if i needed to acheive this and how do i do it?
How is best to simplify the reading and Rewriting process once the system works?

(all of the above are to allow adjustment to a 3D printer Filament Spool NFC tag. Hence the need to access specific data on the tags)

any help is greatly appreciated

Is this the same query as http://forum.arduino.cc/index.php?topic=392705.msg2703462

it is yes UK Helibob, i thought that had been closed as i couldnt find it on the forum? i thought it must have timed out