Author Topic: sound from Digix  (Read 10647 times)

temmink

  • Newbie
  • *
  • Posts: 22
sound from Digix
« on: November 30, 2013, 02:24:48 pm »
I'm trying to get some sound from the Digix by playing an wav from the SD-card.
I have connected some headphone to the stereo jacked, but i'm not able to hear anything.

Is my sketch not correct for the DigiX?

/*

 Demonstrates the use of the Audio library for the Arduino Due

 Hardware required :
 *Arduino shield with a SD card on CS 4 (the Ethernet sheild will work)
 *Speaker attched to ground and DAC0

 Original by Massimo Banzi September 20, 2012
 Modified by Scott Fitzgerald October 19, 2012

*/

#include <SD.h>
#include <SPI.h>
#include <Audio.h>

void setup()
{
  // debug output at 9600 baud
  Serial.begin(9600);
 
  //DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
  while(!Serial.available()){
    Serial.println("Enter any key to begin");
    delay(1000);
  }

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    return;
  }
  Serial.println(" done.");
  // hi-speed SPI transfers
  SPI.setClockDivider(4);

  // 44100 Hz stereo => 88200 sample rate
  // 100 mSec of prebuffering.
  Audio.begin(88200, 100);
}

void loop()
{
  int count=0;

  // open wave file from sdcard
  File myFile = SD.open("test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

  const int S=1024; // Number of samples to read in block
  short buffer;

  Serial.print("Playing");
  // until the file is not finished
  while (myFile.available()) {
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

    // Prepare samples
    int volume = 1023;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();

  Serial.println("End of file. Thank you for listening!");
  while (true) ;
}
 

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #1 on: December 01, 2013, 02:48:09 am »
Do you hear anything at all?

It could be the format of your wav file if you only hear a pop or something like that.

What do you see of serial debug?

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #2 on: December 01, 2013, 01:52:07 pm »
No, I don't hear anything at all.

I have checked my wav. file and it's 44100hz,16 bit stereo and playing fine on the computer.

I will check the serial, but it only says playing and nothing more.

« Last Edit: December 01, 2013, 02:35:56 pm by temmink »

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #3 on: December 01, 2013, 02:04:45 pm »
just double checked, When I enter a keystroke on the serial monitor.

Enter any key to begin
Initializing SD card... done.
Playing

just before Playing I hear a small tik or pop. That's all.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #4 on: December 02, 2013, 02:57:22 am »
Does it ever show "End of file. Thank you for listening!" on the serial?

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #5 on: December 02, 2013, 06:37:26 am »
Nope, it does not.

just a pop, and that's it.



temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #6 on: December 02, 2013, 07:02:23 am »
I was trying to upload the testfile to this forum, but it's to big (3.5 mbyte).

So if anyone wants to have it for check/test let me know and i'm happy to send the file to you.


digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #7 on: December 02, 2013, 01:15:53 pm »
My test file attached

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #8 on: December 02, 2013, 01:56:16 pm »
@digistump,

Thanks for sharing your file.

I have tried with your provided wav file. But I have still the same situation.

Maybe my sketch is wrong, because it doesn't say anything after mentioning Playing.

« Last Edit: December 02, 2013, 01:58:34 pm by temmink »

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #9 on: December 03, 2013, 08:49:42 am »
Does anyone has a sketch which works 100% with the arduino digiX, and is willing to share it with me?
Because I don't see at this moment why my sketch it doesn't work, and I want to make sure the digiX is 100% right.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #10 on: December 05, 2013, 03:28:02 pm »
The Audio example Examples->Audio->SimpleAudioPlayer is what works for me with the file I uploaded.

Two things worth trying:

Another set of headphones

A different SD card

Also make sure the SD card is formatted per these notes: http://arduino.cc/en/Reference/SDCardNotes

Let me know if any of that helps.

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #11 on: December 07, 2013, 06:18:23 am »
I have tried the SimpleAudioPlayter also, with other set of headphones.

just included the digiX trick for serial output

//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
  while(!Serial.available()){
    Serial.println("Enter any key to begin");
    delay(1000);
  }

right after Serial.begin(9600).


I'm wondering if the dac is not working correctly.

plop, and still no sound.

:-(

how can I easily check if the DAC is working?




digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #12 on: December 07, 2013, 01:55:38 pm »
If you have a multimeter you could read the voltage output on the DAC0 (A12) and DAC1 (A13) header pins - the following would test DAC (A12) showing 0, half, and full output.
Code: [Select]
void loop(){
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  // change the PWM resolution to 12 bits
  // the full 12 bit resolution is only supported
  // on the Due
    analogWriteResolution(12);
//show 0 volts for 3 seconds
  analogWrite(12, 0));
//show about 1.65 volts for 3 seconds
    delay(3000);
  analogWrite(12, 2047));
//show about 3.3v for 3 seconds
    delay(3000);
  analogWrite(12, 4095));
    delay(3000);
}


If you don't have a multimeter let me know and I'll write some code to check it with the DigiX and a wire.

temmink

  • Newbie
  • *
  • Posts: 22
Re: sound from Digix
« Reply #13 on: December 07, 2013, 02:50:55 pm »
Ok, There's something wrong.

first I have entered your code (without the extra ')')

before I run the code I had on the DAC0  0.4 mVolt. On DAC1 there was 3.2 Volt.

Then I run the code :

both DAC's have a voltage readout of 0.2mV till 0.6 mVolt. And are not getting near the value's you describing.

Also after running the code, my computer doesn't see the DigiX anymore (serial port is gone).

I only can get Serial port again by:

1. pressing the erase button on the Digif.
2. Detach and attach the cable again.

I have to press the erase button otherwise it will not work.

So i'm afraid that i'm having a faulty unit. Is that possible?


BTW: I have a Imac 27" and a macbookpro both have the same problem with the serial port.
I don't have a problem with the other sketches including wifi.


« Last Edit: December 08, 2013, 03:21:25 am by temmink »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: sound from Digix
« Reply #14 on: December 10, 2013, 11:09:03 pm »
The DAC could be faulty or could have been blown out been blown out - if you hadn't hooked anything to it before then it was likely faulty. The DAC pins are only capable of a few ma.

If you think it was a faulty board we'd be happy to exchange it - send us an email - support@digistump.com