Wave shield - external interrupt!
Moderators: adafruit_support_bill, adafruit

Wave shield - external interrupt!

by lennie on Fri Jan 11, 2013 7:27 am

Hello,

For my project I want to play an Interview after having inplugged in a 3,5mm jack with integrated switch and having stopped and rewind after having unplugged.

I built an external Interrupt using PIN3 (changed PIN3 --> PIN7 which works) which reads the open or closed circuit.

The electric drawing is: 5V (connected to L PIN of jack) / switch(free PIN of jack)/ PIN3/ resistor 1M Ohm / GND

I got it work in the sense of being able to hear the Interview but after having inplugged (which makes an uncomfortable sound?) I have to wait several seconds while hearing a peep sound, until the actual sound starts. Do I have to improve my skech which I added? Is it a software or a hardware problem?

And how can I avoid a disturbing backround noise while hearing the Interview? I there sth i have to be aware of while export the wav. file?

I would appreciate your help!

Code: Select all | TOGGLE FULL SIZE
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
//variablen
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 (wav)

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

#define DEBOUNCE 1  // button debouncer

volatile byte pluggedIn;
volatile byte pluggedInLast = 1;


//functions
// 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(0);
}
void setup() {
  //byte i;
 
  // set up serial port
  Serial.begin(9600);
 
  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(7, OUTPUT);
  //pinMode(4, OUTPUT);
  //pinMode(5, OUTPUT);
 
  // pin3 input
  pinMode(3, INPUT);
 
  //  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(0);                            // then 'halt' - do nothing!
  }
 
 
 
// Now we will look for a FAT partition!--> 1 partition in my case
  if (!vol.init(card, 1)) {
    putstring_nl("no valid FAT partition");
  sdErrorCheck();
  while(0);
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(1, 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(0);                           
  }
 
  putstring_nl("load wave file");
  // look in the root directory and open the file
  if (!f.open(root, "STADTTUR.WAV")) {
    putstring("Couldn't open file STADTTUR.WAV");

  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
 
  //TCCR2A = 0;
  //TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;
 
  //Timer1 Overflow Interrupt Enable
  //TIMSK2 |= 1<<TOIE2;
 
}
//SIGNAL(TIMER1_OVF_vect) {
// putstring_nl("signal ausgerufen");
// pluggedIn = digitalRead (3);
//  if (pluggedIn == 1) {
//    putstring_nl("klinkenstecker in buchse");
//  }
//}
   
void loop() {
  //putstring_nl("loop ausgerufen");
   byte i;
  pluggedIn = digitalRead (3);//Pin auslesen
 
  //beim Wechsel des Signals (von 1 auf 0 oder von 0 auf 1)
  if (pluggedIn != pluggedInLast) {
    pluggedInLast = pluggedIn;//aktueller Wert als letzten Wert speichern
    //bei Wechsel von 1 auf 0
    if (pluggedIn == 0) {
      putstring_nl("signal went from 1 to 0");
      playfile();
    }
    else {
      putstring_nl("signal went from 0 to 1");
      stopfile();
    }
  }
}

void playfile() {
  stopfile();
  // ok time to play! start playback
  putstring_nl("start to play file ");
  wave.play();
}

void stopfile() {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    putstring_nl("wave is playing...stop it");
    wave.stop();
   f.rewind();
   wave.create(f);
  }
}
    // stop it


lennie
Attachments
DSC_0001.jpg
DSC_0001.jpg (195.82 KiB) Viewed 711 times
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by adafruit_support_bill on Fri Jan 11, 2013 9:05 am

I can't really follow all the wires in the photo. Can you post a circuit diagram?
User avatar
adafruit_support_bill
 
Posts: 29081
Joined: Sat Feb 07, 2009 9:11 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 10:20 am

see the scetch attached.

another question which i asked in another comment but belongs to this is that the in ear headphone gets really warm after some seconds playing the file. what could be the problem? and i can only hear on the left side, but would like to hear on both sides...
Attachments
Elektro_Skizze.jpg
Elektro_Skizze.jpg (33.09 KiB) Viewed 687 times
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by adafruit_support_bill on Sat Jan 12, 2013 11:03 am

You have several related threads going here. I believe they all relate to the same problem. Let's keep all the discussion in one place to avoid confusion.

I suspect that the problems you are having are because your wav file has a "DC offset" in the signal. http://musicmasteringonline.com/members ... ew/303/32/

This will cause the "unpleasant noise" when the track starts playing. It would also explain the heating of your headphones. It may also account for some of the disturbing background noise you hear.
User avatar
adafruit_support_bill
 
Posts: 29081
Joined: Sat Feb 07, 2009 9:11 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 11:53 am

sorry. i will mention all in one discussion.

does this mean. the connections/scetch is all right and should work and its a matter of the wav file which is on the sd card and i have to be aware of the center line in my audio program reaper?
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 11:54 am

and the clicking noise when I inplug, is this something related to the dc offset too?
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 11:58 am

there is also a difference concerning the volume.
using the same wav file without the external interrupt the sound is louder and with the interrupt too silent and only on the left to hear not stereo (+ right).
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by adafruit_support_rick on Sat Jan 12, 2013 1:35 pm

I don't understand the "free pin on jack" you refer to. There are no free pins on the jack.
User avatar
adafruit_support_rick
 
Posts: 11568
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 3:23 pm

I add a sheet of the jack. i use the pins 1 (GND) 2(Right) 3(Right) 5(Left) and the Pin i call free pin is pin 3.
Attachments
Klinkenbuchse.jpg
Klinkenbuchse.jpg (125.36 KiB) Viewed 608 times
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by john444 on Sat Jan 12, 2013 3:52 pm

Hi Lennie,

You should only be using pins 1, 2, & 5 on the headphone jack.
Pins 3 & 4 are used when a speaker needs to be connected if the
headphone is not plugged-in.

It is hard to tell from your diagram but, could you be putting +5V
onto the headphone? That would certainly cause them to heat up.

Good Luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 3:58 pm

hi,

i add the scetch again cause i forgot one connection to the 'free pin'.

because of using the switch i need another pin (3) to be able to built the external interrupt.

if i use GND, L and R don't I have to use a forth pin which is able to recognise if its in or unplugged to be able to play the file when its inplugged and stop and rewind it when its unplugged?
Attachments
Elektro_Skizze.jpg
Elektro_Skizze.jpg (33.4 KiB) Viewed 602 times
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 4:01 pm

john, yes 5V is connected to the headphone's Left pin. but at the moment i dont know how to chnage it.
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by adafruit_support_bill on Sat Jan 12, 2013 4:40 pm

As John said, 5v to the headphone would definitely cause the heating. It would explain all the other symptoms you describe too.
User avatar
adafruit_support_bill
 
Posts: 29081
Joined: Sat Feb 07, 2009 9:11 am

Re: Wave shield - external interrupt!

by lennie on Sat Jan 12, 2013 4:47 pm

okay. are there any ideas how to integrate 5v in the scetch or do i have to rethink the whole scetch?
lennie
 
Posts: 24
Joined: Fri Jul 06, 2012 4:32 am

Re: Wave shield - external interrupt!

by john444 on Sat Jan 12, 2013 5:05 pm

Lennie,

Because the switch contacts inside the jack (3 & 4) are intended
to be connected to a speaker, they do not switch pin 3 to ground
(like you might need for triggering a interrupt).

Remove the +5V connection from the wires to the jack and see if
the headphone still gets hot.

John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok