Hi,
I'm pretty new to all this stuff, but basically i built the Adafruit wave shield and it works fine, but now i would like to write a text file tracking the number of times an audio file has been played. I tried copying the sketch here http://arduino.cc/en/Tutorial/ReadWrite , but with no success. Can anyone explain to me what i need to do?
Thank you for your time
Adafruit Wave shield, writing text files to the SD card
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
The example is using pin 4 for CS on the SD card. The Wave shield uses pin 10. In setup, leave pin 10 as an output, and change the parameter for SD.begin:
Code: Select all
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
...
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
Re: Adafruit Wave shield, writing text files to the SD card
I'm having an issue where by just putting the line
#include <SD.h>
the rest of the code does not longer work. I'm using a RFID reader to activate audio files and that uses a 2400 baud rate.
Kind regards,
#include <SD.h>
the rest of the code does not longer work. I'm using a RFID reader to activate audio files and that uses a 2400 baud rate.
Kind regards,
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
Does the example sketch work by itself?
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
Re: Adafruit Wave shield, writing text files to the SD card
Yes the example works alone
Here is my code , the only addition i made is
Here is my code , the only addition i made is
Code: Select all
#include <SD.h>
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Code: Select all
#include <SD.h>
#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 4
int val = 0;
int language=0;
char code[10];
int bytesread = 0;
char knowntags[NUMTAGS][11] = {"00009F13CB","0000B3CD19","3000F8A106","3000F9E50F"};
char filename[1][11];
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
pinMode(10, OUTPUT);
//////// 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;
}
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
// 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
if (code[5]=='9') {
language^=1;
Serial.println(language);
}
else
playsound(code, language);
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
delay(2500);
while(Serial.read() >= 0); // Flush the serial buffer before trying to read a new code
}
bytesread = 0;
}
}
}
void playsound(char codetoplay[], int language) {
filename[0][0]=codetoplay[5];
filename[0][1]='7';
if (language==1)
filename[0][2]='1';
else
filename[0][2]='0';
filename[0][3]='.';
filename[0][4]='w';
filename[0][5]='a';
filename[0][6]='v';
silence(); //shut down anything that is currently playing and close that file
Serial.print("intro");
playfile(filename[0]);
delay(8000);
silence();
filename[0][1]=randomize();
Serial.print("random");
playfile(filename[0]);
}
char randomize(){
int a=random(6);
switch (a){
case 0: return '0'; break;
case 1: return '1'; break;
case 2: return '2'; break;
case 3: return '3'; break;
case 4: return '4'; break;
case 5: return '5'; break;
}
}
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();
}
}
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
SD & WaveHC won't coexist in the same sketch. You should use WaveRP: http://forums.adafruit.com/viewtopic.ph ... 16#p141204
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
Re: Adafruit Wave shield, writing text files to the SD card
Ok, thank you
However i'm having trouble adapting my code for this new library, is there a tutorial or guide on using this somewhere?
Kind regards
However i'm having trouble adapting my code for this new library, is there a tutorial or guide on using this somewhere?
Kind regards
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
You may want to start with the ReadMe.txt file in the library folder. There is also a WaveRP.html which lists all the functions.
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
Re: Adafruit Wave shield, writing text files to the SD card
Sorry to bother again
I'm having trouble with
I try compiling the examples given with WaveRP
i get an error : no matching function for call to 'WaveRP::play(SdFile*)
I see on the html that it needs SdBaseFile, however when i try
it complains that this does not name a type
Again i apologize, i am very new to this
I'm having trouble with
Code: Select all
SdFile file;
i get an error : no matching function for call to 'WaveRP::play(SdFile*)
I see on the html that it needs SdBaseFile, however when i try
Code: Select all
SdBaseFile file;
Again i apologize, i am very new to this
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
Post the full list of compiler errors you see when you compile the sample. (be sure to scroll to the top to get them all).
-
- Posts: 6
- Joined: Wed May 09, 2012 7:21 am
Re: Adafruit Wave shield, writing text files to the SD card
In file included from WaveRecordPlay.cpp:17:
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:26:22: error: WProgram.h: No such file or directory
In file included from WaveRecordPlay.cpp:15:
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFat.h:286: error: conflicting return type specified for 'virtual void SdFile::write(uint8_t)'
C:\Users\Adam\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
In file included from WaveRecordPlay.cpp:16:
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:87: error: ISO C++ forbids declaration of 'SdBaseFile' with no type
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:87: error: expected ';' before '*' token
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:125: error: 'SdBaseFile' has not been declared
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:126: error: 'SdBaseFile' has not been declared
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: error: 'SdBaseFile' has not been declared
In file included from WaveRecordPlay.cpp:17:
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h: In function 'void SerialPrint_P(const prog_char*)':
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:58: error: 'Serial' was not declared in this scope
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h: In function 'void SerialPrintln_P(const prog_char*)':
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:68: error: 'Serial' was not declared in this scope
WaveRecordPlay.cpp: In function 'uint8_t playBegin(char*)':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::play(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:125: note: candidates are: bool WaveRP::play(int*)
WaveRecordPlay.cpp: In function 'void scanRoot()':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::trim(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: note: candidates are: bool WaveRP::trim(int*)
WaveRecordPlay.cpp: In function 'void trackRecord(int16_t, uint8_t)':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::record(SdFile*, int, int, const uint8_t&)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:126: note: candidates are: bool WaveRP::record(int*, uint16_t, uint8_t, uint8_t)
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::trim(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: note: candidates are: bool WaveRP::trim(int*)
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:26:22: error: WProgram.h: No such file or directory
In file included from WaveRecordPlay.cpp:15:
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFat.h:286: error: conflicting return type specified for 'virtual void SdFile::write(uint8_t)'
C:\Users\Adam\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
In file included from WaveRecordPlay.cpp:16:
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:87: error: ISO C++ forbids declaration of 'SdBaseFile' with no type
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:87: error: expected ';' before '*' token
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:125: error: 'SdBaseFile' has not been declared
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:126: error: 'SdBaseFile' has not been declared
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: error: 'SdBaseFile' has not been declared
In file included from WaveRecordPlay.cpp:17:
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h: In function 'void SerialPrint_P(const prog_char*)':
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:58: error: 'Serial' was not declared in this scope
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h: In function 'void SerialPrintln_P(const prog_char*)':
C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:68: error: 'Serial' was not declared in this scope
WaveRecordPlay.cpp: In function 'uint8_t playBegin(char*)':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::play(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:125: note: candidates are: bool WaveRP::play(int*)
WaveRecordPlay.cpp: In function 'void scanRoot()':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::trim(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: note: candidates are: bool WaveRP::trim(int*)
WaveRecordPlay.cpp: In function 'void trackRecord(int16_t, uint8_t)':
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::record(SdFile*, int, int, const uint8_t&)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:126: note: candidates are: bool WaveRP::record(int*, uint16_t, uint8_t, uint8_t)
WaveRecordPlay.pde error: no matching function for call to 'WaveRP::trim(SdFile*)'
C:\Users\Adam\Desktop\arduino-1.0\libraries\WaveRP/WaveRP.h:130: note: candidates are: bool WaveRP::trim(int*)
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Adafruit Wave shield, writing text files to the SD card
The SDFat library you are using has not been updated to be compatible with Arduino 1.0. The latest version can be downloaded here:C:\Users\Adam\Documents\Arduino\libraries\SdFat/SdFatUtil.h:26:22: error: WProgram.h: No such file or directory
http://code.google.com/p/sdfatlib/downloads/list
Please be positive and constructive with your questions and comments.