6 button wave shield not working
Moderators: adafruit_support_bill, adafruit

6 button wave shield not working

by tiny on Mon Feb 17, 2014 11:09 am

Hi,
I've been able to play the daphc example using both the voice example from ladyada as well as using my own sound files (formatted to mono using audacity). However, once I move on to the 6 button examples I can't get any sounds (other than static) to be heard and played through the wave shield. I am using an arduino uno with a wave shield v1.1. Here is the sample code I am using from ladyada tutorial:

Code: Select all | TOGGLE FULL SIZE
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"


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 filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 5  // button debouncer

// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19};
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'pressed' (the current state
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  byte i;
 
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with ");
  Serial.print(NUMBUTTONS, DEC);
  putstring_nl("buttons");
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  // Make input & enable pull-up resistors on switch pins
  for (i=0; i< NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);
  }
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
 
  TCCR2A = 0;
  TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;

  //Timer2 Overflow Interrupt Enable
  TIMSK2 |= 1<<TOIE2;


}

SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

void check_switches()
{
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  byte index;

  for (index = 0; index < NUMBUTTONS; index++) {
    currentstate[index] = digitalRead(buttons[index]);   // read the button
   
    /*     
    Serial.print(index, DEC);
    Serial.print(": cstate=");
    Serial.print(currentstate[index], DEC);
    Serial.print(", pstate=");
    Serial.print(previousstate[index], DEC);
    Serial.print(", press=");
    */
   
    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
          // just pressed
          justpressed[index] = 1;
      }
      else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
          // just released
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  // remember, digital HIGH means NOT pressed
    }
    //Serial.println(pressed[index], DEC);
    previousstate[index] = currentstate[index];   // keep a running tally of the buttons
  }
}


void loop() {
  byte i;
 
  if (pressed[0]) {
      playcomplete("DO.WAV");
  }
  else if (pressed[1]) {
      playcomplete("RE.WAV");
  }
  else if (pressed[2]) {
      playcomplete("MI.WAV");
  }
  else if (pressed[3]) {
      playcomplete("FA.WAV");
  }
  else if (pressed[4]) {
      playcomplete("SO.WAV");
  }
  else if (pressed[5]) {
      playcomplete("LA.WAV");
  }
 
  for (i=0; i<NUMBUTTONS; i++) {
    justpressed[i] = 0;
    justreleased[i] = 0;
  }
}



// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
 
  // ok time to play! start playback
  wave.play();
}

I originally tried using my sound files, but once that failed, I reverted back to the do-re-mi .wav files. Once I have uploaded the sketch to the board there are no errors posted. So is it that I have built the circuit wrong? I am using tactile buttons, one leg of each button going to analog 0-5. Here's a photo.D[img]SC_0156.JPG[/img] I have looked everywhere on arduino tutorials, instructables, and the web in general to see if I am building the circuit properly, but have come up with nothing. So please help if anyone has any idea why things are not working??
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Mon Feb 17, 2014 3:30 pm

Your photo did not show up. Use the "Upload Attachment" tab below the edit window. There is a 1 Meg limit. If you resize to 800x600 you should have no problems.
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: 6 button wave shield not working

by tiny on Tue Feb 18, 2014 5:30 am

Hi,
here is the photo of my circuit (sorry if it is a little messy - and also in the photo the wave shield is not connected to my computer….i am not making that mistake trust me). I basically followed the example in arduino for the push button circuit. I did try in the code to change the byte to pins 0-5 to see if that would work...
Code: Select all | TOGGLE FULL SIZE
/ here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {0, 1, 2, 3, 4,5};

but I still am getting nothing. I believe it must be how i have built the circuit cause I go back to the basic daphc sketch (play all sound files on sd card in loop) and it works.
Thank you and hope you can point me in the right direction.
Attachments
DSC_0001.JPG
DSC_0001.JPG (111.77 KiB) Viewed 130 times
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Tue Feb 18, 2014 7:11 am

it looks like you have those switches wired with pulldown resistors and so that they make connect to 5v when pressed. But the code is expecting the opposite:

Code: Select all | TOGGLE FULL SIZE
 // Make input & enable pull-up resistors on switch pins
  for (i=0; i< NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);
  }

This section of the code enables the internal pullup resistors on these pins. You do not need to add any external resistors and you should wire the switches to connect to ground instead of to 5v, since the code is looking for the signal to go LOW, not HIGH.

Code: Select all | TOGGLE FULL SIZE
    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
          // just pressed
          justpressed[index] = 1;
      }
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: 6 button wave shield not working

by tiny on Tue Feb 18, 2014 9:19 am

Hi again,
thank you for that information. I understand my mistakes regarding how I built my circuit. And I re-read the sketch making sure I hadn't made any mistakes. However, yet again the sounds aren't being heard (but no errors are being displayed). Here's a couple of photos of the circuit following your instructions to move switches to ground. I've been looking at the tutorials (ladyada lesson 5) regarding the button and LED. I understand that the button is the input to trigger the led, and in the wave shield case the button plays the wav files….I just don't know what I am doing wrong???
Attachments
DSC_0004.JPG
DSC_0004.JPG (102.61 KiB) Viewed 121 times
DSC_0003.JPG
DSC_0003.JPG (76.97 KiB) Viewed 121 times
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by tiny on Tue Feb 18, 2014 9:45 am

what you can't see in the photo is that I have a wire running to ground on the arduino from the negative track of breadboard.
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Tue Feb 18, 2014 1:07 pm

Are the wires from the buttons soldered to the analog pin breakout holes on the shield?

what you can't see in the photo is that I have a wire running to ground on the arduino from the negative track of breadboard.

On some of those breadboards, there is a break in the power and ground buses in the middle of the board. Try shorting one of the analog pins directly to ground with one of your jumper wires.
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: 6 button wave shield not working

by tiny on Sun Feb 23, 2014 5:02 am

Hi again.
So soldered the analog pins and tried shorting the analog pins to ground with not much luck. So started again at the beginning with the simple daphc example from ladyada. However, I have noticed that when I switch to other sketches in the tools menu of arduino the programmer changes automatically. For this code (daphc example)
Code: Select all | TOGGLE FULL SIZE
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

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 filesystem on the card

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

// Function definitions (we define them here, but the code is below)
void lsR(FatReader &d);
void play(FatReader &dir);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
 
  putstring_nl("\nWave test!");  // say we woke up!
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam()); 
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Files found:");
  dirLevel = 0;
  // Print out all of the files in all the directories.
  lsR(root);
}

//////////////////////////////////// LOOP
void loop() {
  root.rewind();
  play(root);
}

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

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

/*
 * print error message and halt if SD I/O error, great for debugging!
 */
void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
 * print dir_t name field. The output is 8.3 format, so like SOUND.WAV or FILENAME.DAT
 */
void printName(dir_t &dir)
{
  for (uint8_t i = 0; i < 11; i++) {     // 8.3 format has 8+3 = 11 letters in it
    if (dir.name[i] == ' ')
        continue;         // dont print any spaces in the name
    if (i == 8)
        Serial.print('.');           // after the 8th letter, place a dot
    Serial.print(dir.name[i]);      // print the n'th digit
  }
  if (DIR_IS_SUBDIR(dir))
    Serial.print('/');       // directories get a / at the end
}
/*
 * list recursively - possible stack overflow if subdirectories too nested
 */
void lsR(FatReader &d)
{
  int8_t r;                     // indicates the level of recursion
 
  while ((r = d.readDir(dirBuf)) > 0) {     // read the next file in the directory
    // skip subdirs . and ..
    if (dirBuf.name[0] == '.')
      continue;
   
    for (uint8_t i = 0; i < dirLevel; i++)
      Serial.print(' ');        // this is for prettyprinting, put spaces in front
    printName(dirBuf);          // print the name of the file we just found
    Serial.println();           // and a new line
   
    if (DIR_IS_SUBDIR(dirBuf)) {   // we will recurse on any direcory
      FatReader s;                 // make a new directory object to hold information
      dirLevel += 2;               // indent 2 spaces for future prints
      if (s.open(vol, dirBuf))
        lsR(s);                    // list all the files in this directory now!
      dirLevel -=2;                // remove the extra indentation
    }
  }
  sdErrorCheck();                  // are we doign OK?
}
/*
 * play recursively - possible stack overflow if subdirectories too nested
 */
void play(FatReader &dir)
{
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
    // skip . and .. directories
    if (dirBuf.name[0] == '.')
      continue;
   
    Serial.println();            // clear out a new line
   
    for (uint8_t i = 0; i < dirLevel; i++)
       Serial.print(' ');       // this is for prettyprinting, put spaces in front

    if (!file.open(vol, dirBuf)) {       // open the file in the directory
      Serial.println("file.open failed");  // something went wrong :(
      while(1);                            // halt
    }
   
    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;   
    }
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing "); printName(dirBuf);       // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!
        wave.play();                       // make some noise!
       
        while (wave.isplaying) {           // playing occurs in interrupts, so we print dots in realtime
          putstring(".");
          delay(100);
        }
        sdErrorCheck();                    // everything OK?
//        if (wave.errors)Serial.println(wave.errors);     // wave decoding errors
      }
    }
  }
}

the programmer is AVR ISP, however for the sketch of 6 button wave shield example that I am working on (see previous post) the programmer automatically changes to AVRISP mkll. If I switch the programmer I get the message that I am drawing too much power from my computer. Does this mean anything?
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Sun Feb 23, 2014 7:04 am

I have noticed that when I switch to other sketches in the tools menu of arduino the programmer changes automatically

The programmer is irrelevant in this case. What is important is that the Board Type and Serial Port are correct. Are you getting any errors when uploading code?
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: 6 button wave shield not working

by tiny on Sun Feb 23, 2014 10:53 am

No , unfortunately not.
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Sun Feb 23, 2014 11:51 am

In the check_switches() function, there are some Serial.print statements. Uncomment these and see what is printed to the Serial Monitor when you press the buttons.



Code: Select all | TOGGLE FULL SIZE
    Serial.print(index, DEC);
    Serial.print(": cstate=");
    Serial.print(currentstate[index], DEC);
    Serial.print(", pstate=");
    Serial.print(previousstate[index], DEC);
    Serial.print(", press=");
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: 6 button wave shield not working

by tiny on Mon Feb 24, 2014 3:55 am

HI again,
get the same response :
Binary sketch size: 10,086 bytes (of a 32,256 byte maximum)
but no sound from pressing the buttons.
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by tiny on Mon Feb 24, 2014 4:42 am

Hi,
I've been looking around on the web and found a circuit from tronix.com. In their circuit they are running all buttons to one analog pin. Obviously their code is different but I feel that I am having troubles setting up the circuit. Is this the similar style circuit I should be building? I know that in my case the code enables the internal pull-up resistors
Code: Select all | TOGGLE FULL SIZE
 // Make input & enable pull-up resistors on switch pins
  for (i=0; i< NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);
  }

but perhaps I am style creating the circuit the wrong way. Or if I change the code to read input as LOW? Ultimately I am creating fortune teller origamis (see photo) but they are going to be maps. When the origami is unfolded you find a button which will play the sound of the field recordings I have done at the exact location. However, I am stumped on getting the circuit done despite all your input and help.
Attachments
origami1.jpg
origami1.jpg (3.49 KiB) Viewed 60 times
circuit11from tronix.jpg
circuit11from tronix.jpg (40.01 KiB) Viewed 60 times
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by tiny on Mon Feb 24, 2014 4:56 am

okay no can't change code cause pressed buttons means LOW…..silly me.
tiny
 
Posts: 14
Joined: Wed Dec 02, 2009 10:43 am

Re: 6 button wave shield not working

by adafruit_support_bill on Mon Feb 24, 2014 6:26 am

get the same response :
Binary sketch size: 10,086 bytes (of a 32,256 byte maximum)
but no sound from pressing the buttons.

Please post the output from the serial monitor. Click the icon all the way to the right of the toolbar on the IDE to open the Serial Monitor.
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am