Pages: [1] 2   Go Down
Author Topic: SD -> Arduino -> DAC?  (Read 1842 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 13, 2011, 03:27:31 pm by Grumpy_Mike » Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So in twi.h I can change this:

Code:
  #ifndef TWI_FREQ
  #define TWI_FREQ 100000L
  #endif

I will look at ladyada.

p.s. what happened to your typing?!?!?! smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Connecticut
Offline Offline
Edison Member
*
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
external

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2   Go Up
Jump to: