Offline
Newbie
Karma: 0
Posts: 3
|
 |
« on: July 12, 2011, 10:50:11 am » |
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
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #1 on: July 12, 2011, 11:11:41 am » |
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
Faraday Member
Karma: 12
Posts: 2857
ruggedcircuits.com
|
 |
« Reply #2 on: July 12, 2011, 07:23:41 pm » |
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
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #3 on: July 13, 2011, 09:27:38 am » |
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
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #4 on: July 13, 2011, 09:38:26 am » |
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
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #5 on: July 13, 2011, 09:45:44 am » |
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 Hack the library and run it at 400KHz
|
|
|
|
|
Logged
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #6 on: July 13, 2011, 10:20:26 am » |
Look at the code and there is a line to uncomment at the beginning. Port B is free It is still connected to the USB / serial chip.
|
|
|
|
|
Logged
|
|
|
|
|
Connecticut
Offline
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #7 on: July 13, 2011, 10:25:22 am » |
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
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #8 on: July 13, 2011, 10:29:19 am » |
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
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #9 on: July 13, 2011, 11:28:33 am » |
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
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #10 on: July 13, 2011, 03:11:40 pm » |
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
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #11 on: July 13, 2011, 03:24:35 pm » |
So in twi.h I can change this: #ifndef TWI_FREQ #define TWI_FREQ 100000L #endif I will look at ladyada. p.s. what happened to your typing?!?!?! 
|
|
|
|
|
Logged
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #12 on: July 13, 2011, 03:30:28 pm » |
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
Edison Member
Karma: 16
Posts: 1214
RTFD (Datasheet in our case)
|
 |
« Reply #13 on: July 13, 2011, 03:32:39 pm » |
external The breakout board has them builtin, but why not the internals?
|
|
|
|
|
Logged
|
I'm not kidding. If I am asking a question whose answer is found within the concerned product's datasheet, shame on me. If I am answering a similar question, shame on you!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 269
Posts: 25381
Solder is electric glue
|
 |
« Reply #14 on: July 13, 2011, 03:35:26 pm » |
Because the are not the right size, they are about 30K and you need something like 4K7
|
|
|
|
|
Logged
|
|
|
|
|
|