New library for PWM playback from SD cards: SimpleSDAudio

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

I think the library has the CS pin default to pin 4 (D4)

but there is a line in sketch that allows you to set it to whatever pin you want..

After connecting the SPI pins on corresponding pins, CS to pin 4, 100 ohm resistor to pin 10 and then the speaker, I tried measuring the 3.3 volt supply from the board and it went up to 4.3 volt. I think it's not normal. What might be the cause?

I thought the default out put was from pin 9?

and the bonus/extra pin that could be used was pin 10?

I also have never used a resistor... but instead a 100uF cap...

No clue on the voltage spike.. where your measuring?..with what?..etc..etc..