Go Down

Topic: SD -> Arduino -> DAC? (Read 2065 times) previous topic - next topic

CUSNS

Hey guys,

Basically, i intend to have a sensor that triggers a wav file to play from an SD card, however I'm struggling to understand how to process audio with an arduino.

As I understand it you can't simply use an arduino to output audio as it's processor isn't good enough and likewise it's PWM doesn't pulse fast enough. So you need to use a Digital to analogue converter to return the PWM signal to a smooth wave and then amplify it to audible quality. The programming is something I could work on but hardware wise, I'm stumped. What I'm asking is; Is my reasoning for not being able to use an arduino correct? and what else do I need other than a DAC and arduino?

thanks in advance
CUSNS

Grumpy_Mike

Quote
you need to use a Digital to analogue converter to return the PWM signal to a smooth wave and then amplify it to audible quality.

No PWM has absolutely nothing to do with it.

You need an SD card, D/A converter, low pass filter and audio amplifier.
All these can come together in a wave shield. Look at the one from AdaFruit, it is open source and you can get the schematics and build it yourself if you want to but it is easier to buy it. There is sample software on their site that does almost exactly what you want to do.

RuggedCircuits

Quote
As I understand it you can't simply use an arduino to output audio as it's processor isn't good enough and likewise it's PWM doesn't pulse fast enough.


Sure you can. That's exactly the approach we take with our BeatVox shield. The DAC+filter is the common solution but you can get pretty good results by putting the PWM on the Arduino.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

baum

I'm doing something like this, too. Is an I2C DAC too slow, or would a parallel one be necessary? Also, could the SDfatlib be used, or is that too slow?

Grumpy_Mike

Quote
Is an I2C DAC too slow,

Hack the library and run it at 400KHz
Or get one with an SPI interface.
Parallel ones are not good with the arduino due to lack of a whole port with all the pins free. However it is fine on a Mega.

baum

Quote
Parallel ones are not good with the arduino due to lack of a whole port with all the pins free. However it is fine on a Mega.


Port B is free, just unplug the DAC for uploads.

and how do i

Quote
Hack the library and run it at 400KHz

Grumpy_Mike

Look at the code and there is a line to uncomment at the beginning.

Quote
Port B is free

It is still connected to the USB / serial chip.

baum

So? And why do you need to have the whole port? If we use 22khz samp rate, there is more than enough time, is there not?

Grumpy_Mike

Quote
why do you need to have the whole port?

You don't strictly speaking but outputting gets messy having to split it up as well as preserve the data on the pins you are not using.

baum

Fair enough. I have the I2C DAC mentioned above, and just ordered the parallel one for the purpose of playing wav files. I plan on hooking it up to port B, but could I do the very same with my I2C one? How do I  put it in fast mode? Also, is the SDfatlib fast enough to retrieve the DAC values from the SD card?

Thanks!
baum

Grumpy_Mike

#10
Jul 13, 2011, 10:11 pm Last Edit: Jul 13, 2011, 10:27 pm by Grumpy_Mike Reason: 1
You are better off using direct port access for that sort of thing, it doesn't get any faster. Or did you maen I2C? Just look at the libary codenand you will see the commented out instructions.
Yes an SD card is fast enough to play samples, look at the lady ada wave shield software for an example.

baum

So in twi.h I can change this:

Code: [Select]
  #ifndef TWI_FREQ
  #define TWI_FREQ 100000L
  #endif


I will look at ladyada.

p.s. what happened to your typing?!?!?! :)

Grumpy_Mike

Typing, yes sorry I am on an iPad at the moment and if you don't watch it it is fond of putting an n in place of a space and also auto correcting words. I can't seem to turn that off.

Yes that is what to change, remember you need external pull ups on the I2C line.

baum

Quote
external


The breakout board has them builtin, but why not the internals?

Grumpy_Mike

Because the are not the right size, they are about 30K and you need something like 4K7

Go Up