Show Posts
Pages: 1 2 [3] 4 5
31  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: February 16, 2013, 08:33:21 am
1: I don't know if the lib work with ATmega324 and I don't know Arduinos with that processor. The typical processor is ATmega328.

2: Have you use level-shifters or does your Arduino run with 3.3V only? If the Arduino is 5V you need level-shifters or you could broke your SD card. The simplest way to build a level-shifter is using two resistors for every of the four input pins at the SD card. A description can be found in file SimpleSDAudio.h.

3: You have to power the SD card as well - connect GND to pin 3 and 6 of SD-card and connect pin 4 to the 3.3V output of the Arduino.

4: If there is no sound try the example BareMinimumWithDebug first and look at the output from the serial port. This can give you an indication if your wiring is still wrong or if there is something wrong with the filesystem on card or the file. You can post this output here in the forum to get more help.
32  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: February 13, 2013, 12:09:38 pm
The audio lib uses a timer and the hardware SPI. I2C is often a different hardware in uC, so I2C should still work beside the audio lib. For additional SPI devices also software-SPI might be an option and that way it should be possible to run SPI devices on pins not already used by the audio lib as well. So just give it a try.
33  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: February 09, 2013, 06:06:38 pm
maybe you have a Wav-File that contains something that sox is not aware of, try converting it using commandline and verbose mode of sox. Or try a program like Audacity to import and export the file to a proper PCM Wav-file.
Maybe you even look at the wrong path of the converted folder...
34  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: February 09, 2013, 02:12:04 pm
Hi, I am sorry, I think the minimum requirement is ATmega368 ATmega328P. The ATmega168 is to low on RAM.7
35  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: February 09, 2013, 11:20:49 am
First, hardware SS is often only an issue when SPI is used as slave, which is often not the case. Second, to use the pins 6 & 5 on mega328 Arduinos, you have to apply the wiring.c patch as you already figured out and then you have to patch the file SimpleSDAudioDefs.h. Scroll to the end and you find the last big #else part that sets up all the stuff for mega328 Arduino. Below that, there is the same part again but this time for use pin 6 & 5, but it is commented out. Rework the comments that the old #else-part for pins 9 & 10 will become commented out and activate the part below instead. Then audio will use pin 6 & 5, but it requires the wiring.c patch. Beware, I have not tested that thoroughly so please leave a note if it works for you.
36  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 29, 2013, 06:37:05 am
The amplifier's datasheet uses an 0.47uF input capacitor, if this is already there you don't need the additional 100nF one in series. The trimmer is ok, you want it otherwise it will be to loud. If audio output is to noisy try adding a capacitor after the trimmer to GND to do a little low-pass filtering. I don't know a value but experiment in range of 100nF to several uF for best results.
37  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 27, 2013, 06:47:59 pm
Hi g_u_e_s_t,
a warm welcome on the journey of pushing the audio quality from 1-bit (and 2-bit) outputs to new frontiers! Raising audio quality from such limited systems is a challenging task but I am amazed how far we get. Some years ago I also shared the opinion that without an additional DAC it would be hard to get audio out of an AVR that sound far better than telephone.   
I read your writeups about PWM distortion and - at least - tried to understand them. I think you did a very good theoretical work, even I didn't understand everything yet. But I think you did a really great work toward raising audio quality out of such constrained systems and breaking actual known limits. Some time ago I started my journey by coding a high-order delta-sigma-modulator that converts audio-files to pulse-dense-modulated single bit-streams that I played back through the SPI port of the AVR at rates of up to 2 MBit/s. That way I moved most of the quantization noise out of the audible band, but for whatever reason, the quality on real-world hardware was worse than expected and because it is not possible to do mixing easily with pulse-width-modulated data I stopped my efforts. I wanted then to make something that makes good audio quality playback as easy as possible to use and with minimum hardware effort and started SimpleSDAudio.

With your research results I think we should try to get a step further in quality, but it's time to leave theoretic and try it at the real thing. Let's try if and when phase-correct PWM really sound better than fast PWM. Does it make sense for 2-bit systems to go from 16-bit to 14-bit (or even less) for better results? How about pre-filtering the input audio files to something like PWM-Freq/4? We will loose some high-frequency audio-information but maybe reduce perceived noise also.

You measured -110dB noise floor, I can't believe this really. When SimpleSDAudio stopped at a fixed PWM value, there is really no audible noise, but how about when it is accessing SD card and the AVR has to work harder? I thought the noise is much higher than but maybe I am wrong and that noise is really only from those artifacts you described - I have to try again...

Also interesting that Ti-paper about logic outputs. I wondered why it is so hard to drive speakers at reasonable volume, but with a 74AC14 it should be again worth a try  to drive a speaker as this thing cost only a quarter Euro.

Keep on your good work! I look forward to see what happens if you apply your thoughts to real hardware...

@WilliamK: Interesting thing that AM modulation. BTW: hook up a laser-pointer or a focused LED to the digital audio output pin and receive it over quite a distance using a small solar-panel from garden-light connected to an amplifier - it works great.
38  Using Arduino / Audio / Re: Arduino DAC on: January 23, 2013, 07:23:27 am
I simply you a trimmer as one part of that voltage divider. I trim it just by listening to the sound. Therefore I play a low volume audio part and adjust the trimmer to minimum audible noise. Of course, that DAC never reaches true 16 bit, but there is still a big audible improvement over 8 bit, that is especially audible on lower volume parts or if something fades out. Remember: It is made with simplicity in mind - one resistor and one pot and that's it.
39  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 23, 2013, 07:14:14 am
@tack: have you looked inside the new version? I think I've put your stuff in, but it would be nice if you can try if also autoworker works on your platform as it needs additional stuff in those hardware-settings.

@xl97: You still need the init function that does a lot internally like setting up the file-system and configuring the audio ports. For Button example see the doorbell example that is also new in my library.
40  Using Arduino / Audio / Re: Arduino DAC on: January 22, 2013, 08:06:00 pm
Hi, I did very long research efforts on how to get good audio out of Arduino. It will be at least close to Hifi. This are the three secrets:

1. Use PWM with  only 8-Bit but highest frequency: You can achive sample rates up to 62.500Hz which is very good and often you don't need a low-pass filter anymore. Believe me, even 8-Bit with 31kHz sounds better than 16-Bit with 11kHz.

2. To get high resolution the best way is to use an R-256R network to combine two 8-bit pwm outputs to one 16-bit output.

3. Arduino sounds only as good as its supply voltage. And Ardu's supply is often very noisy due noise from AVR itself and noise coming from USB supply. You can clean noisy PWM signals by running them through a Schmitt-Trigger that has a better filtered supply.

Here is the circuit that I actually use with impressive results:

I think I really should do a video on that for all non-believers...

41  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 22, 2013, 07:31:12 pm
Hi folks, good news from me:  smiley-cool
I've updated the library and now you don't need to call worker() anymore if you provide the SSDA_MODE_AUTOWORKER flag at initialization. I've also added a doorbell (with ding-dong-sound) example, the SD card file access example and edited the examples for autoworker-function. Also there is the fancy AbsoluteMinimum-Example to play the example-audio-file from card that contains just this:
 SimpleSDAudio absolute minimum example, plays file EXAMPLE.AFM from root folder of SD card (CS on pin 4)
 through speaker/amplifier at pin 9 for ATmega328 / pin 44 for ATmega1280/2560.
#include <SimpleSDAudio.h>
void setup()
  // SdPlay.setSDCSPin(10); // Enable if your SD card CS-Pin is not at Pin 4...

void loop(void) {

42  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 21, 2013, 05:06:30 pm
Hi, error code 1 is a sign that there is something wrong with the SD-Card connection, RAM is no problem. Have you used level-shifters to ensure that the SD-card only get 3.3V? Otherwise you can damage the card. Are you using any kind of shield for the SD-card? You find also info about wiring the SD-card in the file SimpleSDAudio.h, this also explains how to build the level shifters.
43  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 19, 2013, 02:57:38 pm

here an example how to read a file with the very low-level SD-sector-access commands from SimpleSDAudio-Library:

 Simple SD Audio example, prints content of TEST.TXT from SD card.
 This example shows how to use the SimpleSDAudio library embedded low-level file access.
 You need:
 - An Arduino with ATmega368 or better
 - An SD-Card connected to Arduinos SPI port (many shields will do)
   -> copy TEST.TXT on freshly formated SD card into root folder
 See SimpleSDAudio.h or our website for more information:
 created  19 Jan 2013 by Lutz Lisseck
#include <SimpleSDAudio.h>
#include <sd_l2.h>
#include <sd_l1.h>

// Create static buffer (shared for all file access, because mega328 are quite low on RAM!)
#define BIGBUFSIZE (2*512)      // bigger than 2*512 is often only possible on Arduino megas!
uint8_t bigbuf[BIGBUFSIZE];

SD_L2_File_t TxtFileInfo; 

// helper function to determine free ram at runtime
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);

void setup()
  uint8_t retval;
  // Open serial communications and wait for port to open:
  Serial.begin(9600); while (!Serial) {}

  // Setting the buffer manually for more flexibility
  SdPlay.setWorkBuffer(bigbuf, BIGBUFSIZE);

  // Using F("...") to avoid wasting RAM 
  Serial.print(F("\nInitializing SD card...")); 
  // If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
  // SdPlay.setSDCSPin(10);
    Serial.println(F("Initialization failed. Error code:"));

  Serial.print(F("Free Ram: "));

  Serial.print(F("Looking for TEST.TXT... "));
  // Search for file TEST.TXT in Rootdir (=cluster 0), search shortname files only (0x00,0x18)
  retval = SD_L2_SearchFile((uint8_t *)"TEST.TXT", 0UL, 0x00, 0x18, &TxtFileInfo);
  if(retval) {
    Serial.println(F(" not found on card! Error code: "));
  } else {
   Serial.print(F("First sector: "));
   Serial.print(F(" Size: "));

  while(TxtFileInfo.ActBytePos < TxtFileInfo.Size) {
    // read one sector
    retval = SD_L1_ReadBlock(TxtFileInfo.ActSector++, &bigbuf[0]);
    if(!retval) {
      uint16_t cnt = 0;
      // print sector content until 512 bytes or file length is reached
      while((cnt < 512) && (TxtFileInfo.ActBytePos < TxtFileInfo.Size)) {
    } else {
      Serial.println(F("Err read sector. Error code: "));

void loop(void) {

I will include this example in later versions of the lib...
I had to edit this code in a way that the Audio-Lib shares the same buffer as that is used for sector-read because only that way it should fit to ATmega328 that is quite low on RAM.

44  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 13, 2013, 06:57:56 pm
Hi xl97,

even it's off-topic, one of my next project I am working on is an special Arduino board with library for very low power applications. I already got my own bootloader for mega328 with 8 MHz internal clock (but 32kHz crystal-calibration) to work - I placed a boards.txt in a folder under <MySketches>/hardware/<my_arduino_board_name>. Compared to your file, it contains two lines that seems to be important for compilation:
Maybe that info will help you...
45  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 13, 2013, 05:44:21 pm

@xl97: I don't know if my lib works under Version below 1.00, but I think other people tried it as well and got it running, but I am not sure. Maybe you can try, within the last version of my lib I included at least something that picks other Arduino-default libs for versions below 1.0, but I never tested it.

@AllanB: My lib uses a own SD card implementation, but you could use this also to access other files on card. It is based on 3 layers: l0 does the hardware access to sd-card - you only have to change this if you want to use this lib on a different architecture. l1 gives access to sectors (sector read/write), whereas l2 gives access to filesystem. Using SD_L2_SearchFile you can find the first cluster of a file on card. Use then SD_L2_Cluster2Sector to get the appropriate sector that belongs to the file and finally read the sector using  SD_L1_ReadBlock. Analyse the SimpleSDAudio.cpp to see how it works. It's not hard, but very low level...
Pages: 1 2 [3] 4 5