New library for PWM playback from SD cards: SimpleSDAudio

Tuttut:
Hi,
@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.

OK, I've now had time to test it and I can report that it works perfectly 'out of the box'. Many thanks for adding those mods to the definitions as it will save re-applying them in future.

I've also tested the Autoworker mode and that also works fine on the 1284P. It has been tested with a 3 minute music file of 27Mb size and it played perfectly in 8 bit stereo full rate, sounding good through a set of hacked active PC speakers.

At the moment this is just running with a 100R in series with each channel. I want to use this now with a little 3W stereo amplifier as an onboard solution. - http://www.technobase.jp/eclib/OTHER/DATASHEET/pam8403.pdf

Any thoughts on input filtering/control prior to the amp? At the moment I'm thinking of a .1uF capacitor in series and a 10k trimmer to control the input level, as per attached schematic. I don't need to be able to adjust volume by the user, just set it and leave it.

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.

I've added the additional cap pads to my design but I can always jumper them out for testing on the prototype boards.

One thing I am doing is setting a 28 pin DIL socket inside my 40 pin one, with some approrpiate 328P pins joined through to 1284pins. This lets me use a 328P on the same board if I don't need all the peripherals or FLASH/SRAM of the 1284P/644P.

On the 1284P the 2 pins used for Channel 1 & 2 (8 Bit Stereo Full Rate) don't clash with anything else. On the 328P Channel 2 is Pin 10, clashing with SPI hardware SS.

I saw the wiring.c patch for the timers, saying that pin 6 & 5 can be used to get 16 bit stereo at half rate. What I would like to do, is use 6 & 5 instead of 9 & 10 for the default 8 bit stereo. Is this possible? I tried making a few changes to the defs file but realised it needs some of the hardware timer definitions altering too if it is possible to make it work.

If possible then It would be ideal if there was a setup parameter to use the alternate pins IF the patch is applied. I'm sure this would be useful for 328 users who want 8 bit stereo but use Ethernet shields or other SPI devices.

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.

Hi,

Does this also work with Arduino with ATMEGA168 only?

Hi, I am sorry, I think the minimum requirement is ATmega368 ATmega328P. The ATmega168 is to low on RAM.7

How about ATMEGA 328.
Sorry. I don't know which is which.

Additional: I tried converting a .wav file but no file appears on the "converted" folder I created.
Is there any requirement for the format of the wav file?
How do I choose the appropriate batch file?
A real newbie in here, hope you understand.

@Tuttut - sorry, I didn't realise that section was there. I'll give that alternativ section a try and report back on whether it works ok. Many thanks again, it's very much appreciated.

meowth08:
How about ATMEGA 328.
Sorry. I don't know which is which.

Additional: I tried converting a .wav file but no file appears on the "converted" folder I created.
Is there any requirement for the format of the wav file?
How do I choose the appropriate batch file?
A real newbie in here, hope you understand.

It works fine in both the 328 and the 328P.

You need to choose the batch file for the playback rate and type you want. I have used 8 bit Mono Fullrate and 8 bit Stereo Fullrate and find the quality very good with a set of PC 2.1 active speakers.

If you are struggling for cycles (a processor intensive sketch) then you may want to try the Halfrate variants.

I've not found any problems with any Wav files at all. I've used downloaded movie/TV sound effects and also used freeware converters to convert a music track MP3 to Wav and then drop on a batch file to convert to 8 bit Stereo Fullrate .asm file, that then played very nicely in SimpleSDAudio

Hi,

What free converter did you use?
What are the settings like encoding etc?
This is killing me for quite a while now :stuck_out_tongue:

I have a .wav file.
attributes: 64000 Hz, 8-bits, mono.
format: PCM uncompressed

On the command prompt, it says:
A subdirectory or file converted already exists.
Press any key to continue . . .

Hi,
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...

I'm not at home to check what file converter I used.

The command line message you got, about a subdiretory or file already converted, is normal. Once you already have a 'converted' folder then that message always appears, but you should find your newly converted file inside that folder.

I'm ok now.
I redownloaded the zip file.
Maybe an error on the first zip file downloaded was the cause.

Question:
What pins are to be connected to the SD card.
This is my arduino: http://www.e-gizmo.com/KIT/Gizduino.html

meowth08:
Question:
What pins are to be connected to the SD card.

D4 - SS or CS
D11 - MOSI
D12 - MISO
D13 - SCK

Tuttut:
First, hardware SS is often only an issue when SPI is used as slave, which is often not the case.

Yes, on the 328P it was working OK on 9 & 10 with SD Card used on SPI and with D4 as SS. On my new PCB's I could also be using radio and ethernet modules on SPI (I know they work together), as well as SimpleSDAudio, although any sounds would only be played when those devices aren't being used. I thought it would be cleaner if I could use 6 & 5 instead.

Tuttut:
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.

Patches all made and audio works perfectly now switched to Pins 6 & 5. Tested in 8 bit Stereo Fullrate. Many thanks again. :slight_smile:

Forgive me for asking this, I'm just recently learning about SPI and I2C. But can I use an I2C device (specifically an accelerometer e.g. ADXL345) together with this library? My plan is to play a sound based on the accelerometer's inputs.

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.

Hi,

I used arduino with atmega324.
Connected sck of sd card to sck of arduino.
miso of sdcard to miso of arduino.
mosi of sd card to mosi of arduino.

I connected cs of sd card at pin4 of arduino.
and tried to get audio output at pin 9 and then at pin 10 but no luck.
I tried the examples at simplesdaudio.

My speaker is 8 ohms 1 watt.
What could be the problem?

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.

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.

It is sold here. http://www.e-gizmo.com/KIT/gizduino+%20164,324,644.html

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.

It has 3.3V. No need for level shifters.

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.

Did that already.

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.

It failed the first test. And I am not certain where to connect the cs pin. Digging the datasheet of 328 and 324 does not help. I am having a hard time understanding both.

Do you think this board will work for this library?

http://www.e-gizmo.com/KIT/Gizduino.html