RFID Charlie Bear Project Software Snag from MAKEvol28

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

First of all, a sleepy good morning from my garage where I yet again have returned to do battle with this infernal project. If you're unfamiliar with the project listed in the subject, http://makeprojects.com/Project/Charlie ... Bear/1411/, meet my nemesis. Currently he has taken the form of an oversized black lab retriever with stuffing pouring out of his poorly unstitched sides and has a messy necklace of dangling wires, boards, and speakers. However, as far as I can tell, the problem I'm facing is not hardware (and yes, I bought everything on that parts list directly from MakerShed and Jameco- no dodgy 3rd party stuff)...
Last night I successfully got sound in the form of the "daphc.pde" sketch. My RFID reader prints the tags magnificently. However, trying to unite sound and RFID seem to be a bit beyond my grasp. Below is the code for "bear:"

Code: Select all

// An interactive bear for Charlie -- RFID triggered sound responses

#include <FatReader.h>
#include <SdReader.h>
#include "WaveHC.h"
#include "WaveUtil.h"

SdReader memcard;
FatVolume vol;
FatReader root;
FatReader file;
WaveHC wave;

#define ENABLE 7      // Set the pin number for enabling the RFID reader. The Audio Shield uses pins 2-5.
#define NUMTAGS 22

int  val = 0; 
char code[10];
int bytesread = 0; 

char knowntags[NUMTAGS][11] = {"2100DFB002", "2100E0B6ED", "2100DFF660", "2100DFD586", "2100DFB1E5", "2100E0CBAA", "2100E07B21", "2100E0B9D6", "2100D82331", "2100DFA060", "2100DFBC77", "2100DFA69A", "2100D7EFF7", "2100DFE251", "2100E02F09", "2100DFBF83", "2100DFD9EA", "2100E0ABA6", "2100DFDFC4", "2100DFF0DF", "36005B7B50", "36005B7C05"};
char soundfiles[NUMTAGS][9] = {"1000.WAV", "1001.WAV", "1002.WAV", "1003.WAV", "1004.WAV", "1005.WAV", "1006.WAV", "1007.WAV", "1008.WAV", "1009.WAV", "1010.WAV", "1011.WAV", "1012.WAV", "1013.WAV", "1014.WAV", "1015.WAV", "1016.WAV", "1017.WAV", "1018.WAV", "1019.WAV", "1020.WAV", "1021.WAV"};
char filename[1][13];

void setup() { 
  //////// Set up RFID reader to collect tag information /////////////////////
  Serial.begin(2400);         // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
  pinMode(ENABLE,OUTPUT);     // Set digital pin 7 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(ENABLE, LOW);  // Activate the RFID reader
  
  //////// Set the pins to output for driving the Audio Shield
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  
  ////////// Set up the Audio Shield by initializing the memory card for reading ////////
  if (!memcard.init()) {
    // If something went wrong sdErrorCheck prints out the error check
    putstring_nl("Card init. failed!"); 
    cardErrorCheck();
    return;
  }
  
  //This will optimize the reading of the memory card -- remove it if it times out
  memcard.partialBlockRead(true);
  
  // Find a FAT formatted partition by looking in teh first five slots. Remember your memory card should be FAT16 or FAT32 formatted
  uint8_t partition;
  for (partition = 0; partition < 5; partition++) {
    if (vol.init(memcard, partition))
      break;
  }
  if (partition == 5)
  {
    putstring_nl("No valid FAT partition");
    cardErrorCheck();
    while(1); // This is a point of no return. Format your memory card properly and try again.
  }

  // Open the root directory for reading the files
  if (!root.openRoot(vol))
  {
    putstring_nl("Can't open root directory");
    while(1); // Something went wrong here so investigate the file system on your memory card.
  }
  
  // If you got this far then the card is ready to read
  putstring_nl("Ready to go");
}

// If we find an error, check what the error is and show it on the serial terminal
void cardErrorCheck(void)
{
  if(!memcard.errorCode()) return;
  putstring("\n\rSD I/O error:");
  Serial.print(memcard.errorCode());
  putstring(", ");
  Serial.print(memcard.errorData());
  while(1); // Stick here if there is an error
}

void loop() { 

  if(Serial.available() > 0) {          // if data available from reader  
    if((val = Serial.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( Serial.available() > 0) { 
          val = Serial.read(); 
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 
      if(bytesread == 10) {              // if 10 digit read is complete 
        playsound(code);
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code 
        Serial.flush();                  // Flush the serial buffer before trying to read a new code
      } 
      bytesread = 0; 
    }
  }

} 

void playsound(char codetoplay[]) {
  for(int i = 0; i<8; i++) {    // Make a filename from the first 8 characters of the RFID tag number
    filename[0][i]=codetoplay[i];
  }
  filename[0][8]='.';
  filename[0][9]='w';
  filename[0][10]='a';
  filename[0][11]='v';
  silence(); //shut down anything that is currently playing and close that file
  playfile(filename[0]);
  
}

void playfile(char *name) {
  if (!file.open(root, name)) {
      putstring_nl("Couldn't open file"); 
      return;
   }
   if (!wave.create(file)) {
     putstring_nl("Not a valid WAV"); 
     return;
   }
  wave.play();
}

void silence() {
  if(wave.isplaying) {
    wave.stop();
  }
}
So what does Serial Monitor say when I put a RFID tag near the reader?

Code: Select all

€Ready to go
Couldn't open file
TAG code is: 3D001ED8B7
Near as I can tell, that means that I'm facing a software issue of not being able to summon the right file name. My .wav file is properly encoded/ect for the waveshield and named "3D001ED8.wav", as demanded by the project code. I'm kind of lost at this point and need all the help getting this infernal christmas gift done by tomorrow!

Thanks in advance for your help!

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

named "3D001ED8.wav"
Are those "oh's" or "zeros"?

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

They are both zero. (On the Serial Monitor, they have a line through them, indicative of zero.)

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

Try changing the ".wav" to ".WAV"?

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

Just tried .WAV, but changing it made no difference. :(

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

Check the output of daphc. It should print out the named of the files exactly as read from the card. Make sure that your file name matches exactly. Also - this sketch expects the file to be found at the root level. Make sure you don't have it in a nested folder.

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

This is what I get back from daphc:
Image

The sound file is at root level.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

What is "Wbdir: 502"?
You also have a lot of garbage in the output. If I recall, the Charlie Bear project has other connections to the serial pins that might be messing that up.

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

To be honest, I have no earthly clue. I just ran the sketch I found under Files>>Sketchbook>>libraries>>WaveHC>>daphc and opened up the serial monitor.
As for the garbage, what can I do about that?

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

Looking at the code, 'Wbdir: 502" looks like slightly corrupted output from these statements:

Code: Select all

    if (file.isDir()) {                    // check if we opened a new directory
      putstring("Subdir: ");
      printName(dirBuf);
      dirLevel += 2;                       // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;    
    }
which would tend to indicate that your file is not at the root level.
As for the garbage, what can I do about that?
Try disconnecting any wires from pins 0 and 1.

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

This is in only file and it's on the root.
Image

As far as pins 0 and 1, there was a wire (goes from pin 0 to RFID scanner). However, after I removed it, I tried daphc again and I'm still getting garbage in the serial monitor.
Meanwhile the "bear" is singing out that .wav file on loop. (It's supposed to read it twice normally, twice frighteningly slow, and then repeat, right?)

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

This is in only file and it's on the root.
Could be that '502' is an empty root-level folder and the wav file is at root level too. Macs create some 'invisible' files and folders that can confuse a simple file system as used by WaveHC.

Not sure what else would be causing the junk in the serial output. You can double-check that the baud-rate in your serial monitor matches what you have in the code. But if that were the problem, I wouldn't expect any of the output to be readable.
Meanwhile the "bear" is singing out that .wav file on loop. (It's supposed to read it twice normally, twice frighteningly slow, and then repeat, right?)
Not sure about the Charlie Bear sketch, but dapHC just plays it in a loop.

User avatar
jonathanray17
 
Posts: 7
Joined: Tue Dec 13, 2011 8:44 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by jonathanray17 »

Right- I can't get a sound out of the waveshield when I run the CharlieBear sketch but it won't shut up while running dapHC.
Near as I can tell, my primary issue here is confusion in the CharlieBear sketch where there's a software disconnect between reading the RFID tag, truncating the first 8 characters, and summoning the corresponding .wav file. :?

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by adafruit_support_bill »

You could try printing out the file name in the 'playfile' function of the sketch (as in the snippet below) & verify that it is exactly the same as the file name on disk. You could also look at the contents of the card on a windows machine and delete everything but your .wav files.

Code: Select all

    void playfile(char *name) {
      putstring_nl(name);
      if (!file.open(root, name)) {
          putstring_nl("Couldn't open file");
          return;
       }
       if (!wave.create(file)) {
         putstring_nl("Not a valid WAV");
         return;
       }
      wave.play();
    }

User avatar
sdfine
 
Posts: 1
Joined: Sat Mar 31, 2012 9:09 pm

Re: RFID Charlie Bear Project Software Snag from MAKEvol28

Post by sdfine »

I completed the build. This is my first Arduino project and the first circuit board I ever soldered but the build was successful. The only issue I had were software issues. The serial port speed (throuigh the Arduino software) had to be lowered in order to read the RFID feed. The Arduino sketch is not compatible with the current version of the Arduino environment. I had to load an older version in order for it to run. The Wave Shield required sketch libraries to be installed from http://code.google.com/p/wavehc/downloads/list also.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”