Arduino with NFC: Music Not Found

I started working on a small programming project just for fun and I have got stuck. I have been using the following tutorial to make an Amiibo Music Box (without any rotating dancers of course :P)

(A different tutorial of the same idea is here http://imgur.com/a/7BFpu)

Now using the libraries the tutorial suggested, I successfully uploaded the sketch to the device. However when I put an Amiibo or NFC card on top and look at the Serial Monitor, I get lots of garble and no sound.

~~¸ý×ÿòœy_ÿ#À–Yÿ›l° _Yÿ8dÐa4’ÿ’Í�©ÿ›—Lµ›ú’áo°)h@’öþ8‚¤hþ:dÐ S4ê’ÉãÈô›l°É�°ò“ƒc¶ÿ™l±a“ùü8‚´hþ›l°É�´÷“ÅiØð ¶–t=Üý’ÉãÈôâd@àÉ‘ø8‚¤hþ –e¼Õý’ÍÐPÿK¬ÀàÉ�ú8�·i™–e¼Õý8©Pòý’t=Üý“ƒf–ÿü’t=Ø9UY6þ›hX Cú’Í�©ÿ(l„±Ô_ü8‚´hþKìAÀò ý:‚´hþ8lÐaÓ4â’ÌcÈõ›hX Cú“ƒf–ÿKìEÀò ý’ÌiØõ8lÐaâtý“ƒ&–ÿè4@’âþ“ƒ&–ÿš’L²µšý8�·yÿ)l„úÈï’ÉãÈõ(l„±Ô_ü’ÍÙ:dÐ`S4ê2"´žþ)l„úÈï2"ߟÿ›h±ÑªÛÖ’áoÞÿüÒt=Ø‘�&’ÿ�šA’âþ“ƒc¶þ›l±ÑªËÓ’Í�©ÿ8lÐaâtý’ÍÙ ––\5,ÿ’Í�©ÿè4@àâþ8©Pòý–t=Üý:‚´hþ ––t=Üý8‚´hþ8l€a¢tý’ÉãÈõš’L²µšýÜ,þÍ›þëÖÿÜ,þÜ,ÿÜ,ÿYÿ\ÿëòÿÜ,þêëòÿëòÿê4KÖÿ\ÿ]ÓÜ,ÿ~~

I tried the card that comes with the kit and it does not work either. Has anyone got any idea why this has failed?

EDIT: With the original problem solved, there is now a new one. It does not seem to be able to find any Wav files. The code’s error message “Sound not found” constantly appears even though the code has the right file name and the correct file on the SD Card

I have put a link to the libraries and code I am using below.

My Current Code

#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
//#include <MemoryFree.h>

//Loading Strings into PROGMEM to save RAM
#include <avr/pgmspace.h>
//Character Intro File Names
const char string_0[] PROGMEM = "SplatoonSquid.wav";
//Songs
const char string_1[] PROGMEM = "SplatoonSquid.wav";

// Then set up a table to refer to your strings.

const char* const string_table[] PROGMEM =      
{   
  string_0,
  string_1,  };

char buffer[71];

#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
FatReader file; // This object represent the WAV file for a pi digit or period
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
/*
* Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))

//Setup()
uint32_t versiondata;

//My Added Variables
uint32_t lastcard = 0;
uint32_t currentcard = 1;
uint32_t CID = 0;
boolean songplaying = false;

//Loop()
uint32_t cardidentifier = 0;
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)
 
//////////////////////////////////// SETUP

void setup() {
  // set up Serial library at 9600 bps
  Serial.begin(115200);
    
  PgmPrintln("Amiibo Scanner");
  
  if (!card.init()) {
    error("Card init. failed!");
  }
  if (!vol.init(card)) {
    error("No partition!");
  }
  if (!root.openRoot(vol)) {
    error("Couldn't open dir");
  }
  
  PgmPrintln("Files found:");
  root.ls();
  
  // find Adafruit RFID/NFC shield
  nfc.begin();

  versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print(F("Didn't find PN53x board"));
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  //enable timeout waiting for cards
  nfc.setPassiveActivationRetries(50);

}

/////////////////////////////////// LOOP

unsigned digit = 0;

void loop() 
{
  
  //Memory Checker
  
  //Serial.print(F("Memory Available = "));
  //Serial.println(freeMemory());
  
  
  // wait for RFID card to show up!
  Serial.println(F("Waiting for an Amiibo ..."));

    
  // 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);

  cardidentifier = 0;
  CID = 999; 
  if (success) 
  {
    // Found a card!

    Serial.print(F("Amiibo detected #"));
    // turn the four byte UID of a mifare classic into a single variable #
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
    Serial.println(cardidentifier);
    
    //Check the previous card
    
    (lastcard = currentcard);
    (currentcard = cardidentifier);
    
    Serial.print(F("Last Amiibo:    #"));
    Serial.println(lastcard);
    Serial.print(F("Current Card:"));
    Serial.println(currentcard);
    
    // Check Character ID
    
      // Try to read the Character info page (#21)
      uint8_t charID[32];
      success = nfc.mifareultralight_ReadPage (21, charID);
      
    if (success)
    {
        // turn page 21 into a character ID
      CID = charID[6];
      CID <<= 8; CID |= charID[6];
      CID <<= 8; CID |= charID[5];
      CID <<= 8; CID |= charID[4];
      CID <<= 8; CID |= charID[3];
      CID <<= 8; CID |= charID[2];
      CID <<= 8; CID |= charID[1];
      CID <<= 8; CID |= charID[0];
      Serial.println("Character Number: ");
      Serial.println(CID);
    
    
      if (currentcard == lastcard) 
      {
      /*
        If there is no song playing, play a song.
      */
        if (songplaying == false) 
        {
          //Squid Song
          if (CID == 6)      
          {strcpy_P(buffer, (char*)pgm_read_word(&(string_table[1])));
            playfile(buffer);
            if (wave.isplaying) {
              songplaying = true;
            }
          }
        }
        
        if(!wave.isplaying) {
          songplaying = false;
        }  
      }
      /*
        There is no song playing, play the intro sequence!
      */
      else 
      {
        //Squid
        if (CID == 6) 
        {
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0])));
          playcomplete(buffer);
        }
      }
    }
    else 
    {
      //if (currentcard == lastcard) 
      //{
       // Serial.println("CID else");
        wave.stop();
      //}  
      lastcard = 123456;
      currentcard = 654321;
      songplaying = false;
    }
  } 

   //If the Amiibo is gone, stop the song.
  else 
    {
      //if (currentcard == lastcard) 
      //{
        //Serial.println("UID else");
        wave.stop();
      //}  
      lastcard = 321123;
      currentcard = 123321;
      songplaying = false;
    }  
}

/////////////////////////////////// HELPERS

/*
* print error message and halt
*/
void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
* print error message and halt if SD I/O error
*/
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
* Play a file and wait for it to complete
*/
void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
  
  // see if an error occurred while playing
  sdErrorCheck();
}
/*
* Open and start playing a WAV file
*/
void playfile(char *name) {
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  if (!file.open(root, name)) {
    PgmPrint("Couldn't open file ");
    Serial.print(name);
    return;
  }
  if (!wave.create(file)) {
    PgmPrintln("Not a valid WAV");
    return;
  }
  // ok time to play!
  wave.play();
}

(https://github.com/ModusPwnin/Interactive-Amiibo-Stand/blob/master/Amiibo%20Stand%20v3)

https://code.google.com/p/wavehc/

I am new to this but I want to understand why this is not working as well. Can anyone help me? I really want this Music Box idea to work :slight_smile:

I have put a link to the libraries and code I am using below.

That's fine for the libraries. Put your code HERE!

Sure but it does not differ from the code I put a link to

#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
//#include <MemoryFree.h>

//Loading Strings into PROGMEM to save RAM
#include <avr/pgmspace.h>
//Character Intro File Names
const char string_0[] PROGMEM = "SplatoonSquid.wav";
//Songs
const char string_1[] PROGMEM = "SplatoonSquid.wav";

// Then set up a table to refer to your strings.

const char* const string_table[] PROGMEM =      
{   
  string_0,
  string_1,  };

char buffer[71];

#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
FatReader file; // This object represent the WAV file for a pi digit or period
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
/*
* Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))

//Setup()
uint32_t versiondata;

//My Added Variables
uint32_t lastcard = 0;
uint32_t currentcard = 1;
uint32_t CID = 0;
boolean songplaying = false;

//Loop()
uint32_t cardidentifier = 0;
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)
 
//////////////////////////////////// SETUP

void setup() {
  // set up Serial library at 9600 bps
  Serial.begin(115200);
    
  PgmPrintln("Amiibo Scanner");
  
  if (!card.init()) {
    error("Card init. failed!");
  }
  if (!vol.init(card)) {
    error("No partition!");
  }
  if (!root.openRoot(vol)) {
    error("Couldn't open dir");
  }
  
  PgmPrintln("Files found:");
  root.ls();
  
  // find Adafruit RFID/NFC shield
  nfc.begin();

  versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print(F("Didn't find PN53x board"));
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
  
  //enable timeout waiting for cards
  nfc.setPassiveActivationRetries(50);

}

/////////////////////////////////// LOOP

unsigned digit = 0;

void loop() 
{
  
  //Memory Checker
  
  //Serial.print(F("Memory Available = "));
  //Serial.println(freeMemory());
  
  
  // wait for RFID card to show up!
  Serial.println(F("Waiting for an Amiibo ..."));

    
  // 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);

  cardidentifier = 0;
  CID = 999; 
  if (success) 
  {
    // Found a card!

    Serial.print(F("Amiibo detected #"));
    // turn the four byte UID of a mifare classic into a single variable #
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
    Serial.println(cardidentifier);
    
    //Check the previous card
    
    (lastcard = currentcard);
    (currentcard = cardidentifier);
    
    Serial.print(F("Last Amiibo:    #"));
    Serial.println(lastcard);
    Serial.print(F("Current Card:"));
    Serial.println(currentcard);
    
    // Check Character ID
    
      // Try to read the Character info page (#21)
      uint8_t charID[32];
      success = nfc.mifareultralight_ReadPage (21, charID);
      
    if (success)
    {
        // turn page 21 into a character ID
      CID = charID[6];
      CID <<= 8; CID |= charID[6];
      CID <<= 8; CID |= charID[5];
      CID <<= 8; CID |= charID[4];
      CID <<= 8; CID |= charID[3];
      CID <<= 8; CID |= charID[2];
      CID <<= 8; CID |= charID[1];
      CID <<= 8; CID |= charID[0];
      Serial.println("Character Number: ");
      Serial.println(CID);
    
    
      if (currentcard == lastcard) 
      {
      /*
        If there is no song playing, play a song.
      */
        if (songplaying == false) 
        {
          //Squid Song
          if (CID == 6)      
          {strcpy_P(buffer, (char*)pgm_read_word(&(string_table[1])));
            playfile(buffer);
            if (wave.isplaying) {
              songplaying = true;
            }
          }
        }
        
        if(!wave.isplaying) {
          songplaying = false;
        }  
      }
      /*
        There is no song playing, play the intro sequence!
      */
      else 
      {
        //Squid
        if (CID == 6) 
        {
          strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0])));
          playcomplete(buffer);
        }
      }
    }
    else 
    {
      //if (currentcard == lastcard) 
      //{
       // Serial.println("CID else");
        wave.stop();
      //}  
      lastcard = 123456;
      currentcard = 654321;
      songplaying = false;
    }
  } 

   //If the Amiibo is gone, stop the song.
  else 
    {
      //if (currentcard == lastcard) 
      //{
        //Serial.println("UID else");
        wave.stop();
      //}  
      lastcard = 321123;
      currentcard = 123321;
      songplaying = false;
    }  
}

/////////////////////////////////// HELPERS

/*
* print error message and halt
*/
void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
* print error message and halt if SD I/O error
*/
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
* Play a file and wait for it to complete
*/
void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
  
  // see if an error occurred while playing
  sdErrorCheck();
}
/*
* Open and start playing a WAV file
*/
void playfile(char *name) {
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  if (!file.open(root, name)) {
    PgmPrint("Couldn't open file ");
    Serial.print(name);
    return;
  }
  if (!wave.create(file)) {
    PgmPrintln("Not a valid WAV");
    return;
  }
  // ok time to play!
  wave.play();
}
  Serial.begin(115200);

Is that the same speed that the Serial Monitor is set to?

I think the Serial is set to 9600 Bauds. How can I be sure?

I think the Serial is set to 9600 Bauds. How can I be sure?

That would certainly explain the garbled communications. There is a dropdown field on the serial monitor, at the bottom, IIRC, that is used to set the speed. If it does not show 115200, there will be a failure to communicate.

Nice, someone already had an issue with the same build.

Using Windows Arduino 1.6.5 and latest libs. Running an Arduino UNO with Adafruit Wave and NFC shields. For the NFC shield I am using the deprecated library Adafruit_NFCShield_I2C.h

I first verified the Arduino is working properly with the Example Basic LED blink sketch (worked!).

I then verified the NFC shield is working properly by using the example ReadMifare sketch and it worked.

I then uploaded the below code and opened the serial monitor and the monitor says this:

Amiibo Scanner
Error: Card init. failed!
SD I/O error: 1, FF

On the WAV Shield I am using a 4gb micro SD card formatted as FAT16

C:\Windows\system32>format E: /FS:FAT
Insert new disk for drive E:
and press ENTER when ready...
The type of the file system is FAT32.
The new file system is FAT.
Verifying 3720M
WARNING!  The cluster size for this volume, 64K bytes, may cause
application compatibility problems, particularly with setup applications.
The volume must be less than 2048 MB in size to change this if the
default cluster size is being used.
Proceed with Format using a 64K cluster (Y/N)? Y
Initializing the File Allocation Table (FAT)...
Volume label (11 characters, ENTER for none)?
Format complete.
       3.6 GB total disk space.
       3.6 GB are available.

       65,536 bytes in each allocation unit.
       59,516 allocation units available on disk.

           16 bits in each FAT entry.

Volume Serial Number is 02C3-761E

I attached the code as a plain txt file. For some reason, even using the code tags w/in post it still exceeded the char limit of this post. So please reference the attached code.

Any idea what’s wrong here?

Thank you,
Roy

Amiibo Stand v3_alt.txt (26.6 KB)

On the WAV Shield I am using a 4gb micro SD card formatted as FAT16

Check out the sticky posts at the top of the Storage part of the forum.

Thanks, I am now using SDformatter; however, that did not help. I've posted on the adafruit forums and seeking help there as well: https://forums.adafruit.com/viewtopic.php?f=31&t=79399&p=402292#wrap

-Roy