NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

Dear all,
I've posted this before on the Arduino forum and got a helpful answer, but I am still unsure. I am new to this kind of electronics and have two projects coming up. One, that I am doing right now, involves the Wave Shield. What I want to have are have six big red buttons wired to the arduino / wave shield able to play certain sounds when being hit. Sounds simple enough, eh? It also fits one of the examples from the Wave Shield Use it! guide. But I have no idea how to wire it up, which resistors to put where. At a later stage the same setup is supposed to be extended by a wifi shield for remote control, but this is far away if I already fail when deciding on wiring up the buttons.
I tried to create a sketch with fritzing but failed to test it.
Thanks for any help

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

The tutorial for the 6-button example is here: http://www.ladyada.net/make/waveshield/ ... play6.html
Lesson 5 of the Arduino tutorials tells you all you need to know about wiring up buttons: http://www.ladyada.net/learn/arduino/

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

Hey, I successfully built my kit and now have six nice buttons creating sounds. No, I didn't take this long, but as a side project I can't put too much time into it, sadly.
Now, I have two problems: The sounds is very distorted, there is almost no sound audible on lower volumes, just on maximum volume and then very distorted. The second problem: The sixth sounds plays all the time (input 12), even without pressing the button.
Did I mess up the soldering somwhere?
Edit: Could it be my mistake that I used Digital I/O 11 and 12, which according to the manual are reserved for the SD card?

Here is the code I am using:

Code: Select all

#include "WaveUtil.h"
#include "WaveHC.h"
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.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[] = {6, 7, 8, 9, 11, 12};
// 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 (justpressed[0]) {
    justpressed[0] = 0;
    playfile("micpay.wav");
  }
  else if (justpressed[1]) {
      justpressed[1] = 0;
      playfile("sale.wav");
  }
  else if (justpressed[2]) {
      justpressed[2] = 0;
      playfile("monsal.wav");
  }
  else if (justpressed[3]) {
      justpressed[3] = 0;
      playfile("appla.wav");
  } 
  else if (justpressed[4]) {
      justpressed[4] = 0;
      playfile("biers.wav");
  } 
  else if (justpressed[5]) {
      justpressed[5] = 0;
      playfile("spapp.wav");
  }
}
// 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();
}
Thanks for any heads up :)

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

If you post photos we can check for any assembly problems. Using those pins would definitely be a problem though...

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

I took some pics and uploaded them here. I desoldered the cables leading to 11 & 12, also took those buttons out of the code.
The distortion is still there.
The GND of all buttons is connected to one cable and runs to the GND directly
Attachments
image003.jpg
image003.jpg (144.62 KiB) Viewed 3207 times
image002.jpg
image002.jpg (91.23 KiB) Viewed 3207 times
image001.jpg
image001.jpg (139.84 KiB) Viewed 3207 times

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

I don't see any obvious assembly problems with the shield. What kind of speaker do you have connected?

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

I tried out several: High class headphones, in-ears, active speakers - all the same kind of distortion.
I tried another demo sketch, also the same distortion and sound only on the highest volume.

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

Have you tried the sample sound files in the download section? It could be that the signal level in your wav files is too low.

Also keep in mind that this is not designed to audiophile standards and it is sitting atop a small digital computer, so some noise is expected. And running at maximum gain will amplify the noise as well as the signal.

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

I tried the hello world file from the page, same problems. It is not that i expect audiophile sound, it really is barely audible, very faint, very low in sound and distorted as like only the top frequencies are heard.

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

I tried the hello world file from the page, same problems
Well that narrows the problem down to somewhere the analog section.

You might want to try the "cheap headphone trick" to see what kind of signal you have coming out of the DAC.

Also, if by any chance you have access to a scope, it would simplify the diagnosis.

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

Hey,
I tried the cheap headphone trick and got a clean signal on the one side of R7, on the leg towards the headphone jack, the other side had a lot of static but still audible sound. It ain't loud, but clear.
So that is one step further :)

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

OK. What do you hear on pin 3 of the op-amp? How about Pin 1?

These are downstream from the volume pot, so try it at several different levels.

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

PIN 3 outputs a nice signal, change in volume with the pot, at maximum volume it's about as loud as directly on R7 - PIN 1 & 2 output the distortion i get over the headphone jack / speaker connection

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

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by adafruit_support_bill »

So it's down to the op-amp. Re-touch the solder joints on the op-amp and C9.

User avatar
gymnae
 
Posts: 21
Joined: Fri Apr 01, 2011 10:40 am

Re: NOOB: Create a soundboard with six buttons (Wave Shield & UNO)

Post by gymnae »

Thanks for this hint, I took a away a lot of excess solder, tried re-solder it nicer but still, the problem still persists. I use a temp. controlled iron at 300°C - did this maybe fry the op-amp?

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

Return to “Arduino Shields from Adafruit”