0

Wave Shield and Arduino Mega: how-to
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Wave Shield and Arduino Mega: how-to

by abritinthebay on Fri Dec 11, 2009 9:45 pm

That sounds pretty neat!

Would that make things faster IO wise too? Or is that mostly SD Card bound?

abritinthebay
 
Posts: 32
Joined: Wed Dec 02, 2009 5:00 pm

Re: Wave Shield and Arduino Mega: how-to

by fat16lib on Fri Dec 11, 2009 10:15 pm

The DAC takes most of the CPU time. I have a macro version like ladyada mentioned that reduces the time to send 12-bits to the DAC to 8 us + interrupt overhead. It uses macros like Paul's to handle pin defs.

The SD causes problems due to random latency. These occur in part due to reading the file allocation table. If you use two 512 byte buffers instead of the current 256 byte buffers you can do 16-bit WAV at 44.1 k. Most file are contiguous so I have considered an optimization based on that.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

by adafruit on Fri Dec 11, 2009 10:52 pm

ya. ugh. need to put in an option to have it use full-sector buffers. we had to have this run on '168 arduinos which meant we were stuck with 2x256 byte buffers, and 22khz but with 512 things get a lot easier since you can just shove a sector in ram and then take a break.

adafruit
 
Posts: 12149
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Wave Shield and Arduino Mega: how-to

by abritinthebay on Fri Dec 11, 2009 11:27 pm

Can't there be a check in there like for the pins? Use 512 if we can and fall back to 256 if we can't?

Seems silly to hold everything else back because of the least functional chip...

abritinthebay
 
Posts: 32
Joined: Wed Dec 02, 2009 5:00 pm

Re: Wave Shield and Arduino Mega: how-to

by adafruit on Sat Dec 12, 2009 12:31 am

its a time thing. we recently used up our Time Credit to writing up a half dozen examples for the new wave shield lib and revising the hardware to v1.1 and updating the dox. :(
IN THEORY if you set the #define to 512 instead of 256 it should 'just work' :)

adafruit
 
Posts: 12149
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Wave Shield and Arduino Mega: how-to

by abritinthebay on Sat Dec 12, 2009 5:03 pm

Gotcha. Well I'll try that out and let you know if it seems to work :)

What file would it be in? I can't find it in SDReader.cpp or .h or sdInfo either

abritinthebay
 
Posts: 32
Joined: Wed Dec 02, 2009 5:00 pm

Re: Wave Shield and Arduino Mega: how-to

by adafruit on Sat Dec 12, 2009 5:17 pm

cant remember. but you'll know it when you see it, its probably called BUFFSIZ or something

adafruit
 
Posts: 12149
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Wave Shield and Arduino Mega: how-to

by fat16lib on Sat Dec 12, 2009 5:38 pm

If you are using WaveHC it is at about line 22 of WaveHC.cpp
Code: Select all | TOGGLE FULL SIZE
#define PLAYBUFFLEN 256UL

It seems to work if you change it to
Code: Select all | TOGGLE FULL SIZE
#define PLAYBUFFLEN 512UL


It may not be able to play 16-bit 44.1k files until I do the DAC upgrade.

To try such files you need to edit/remove this around line 343 or it will not allow playing them.
Code: Select all | TOGGLE FULL SIZE
  uint8_t tooFast = 0; // flag
  if (dwSamplesPerSec > 22050) {
    // ie 44khz
    if ((BitsPerSample > 8) || (Channels > 1))
      tooFast = 1;
  } else if (dwSamplesPerSec > 16000) {
    // ie 22khz. can only do 16-bit mono or 8-bit stereo
    if ((BitsPerSample > 8) && (Channels > 1))
      tooFast = 1;
  }
//  putstring_nl("");
  if (tooFast) {
    putstring_nl("Sample rate too high!");
    return 0;
  }
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

by abritinthebay on Sat Dec 12, 2009 6:25 pm

Ok - that's, that's really helpful.

Hilarious consequence however - it plays the 44.1 file at half speed. Which is funny as hell, but not exactly right ;) I'm sure this is basically a simple(ish) fix (I'm sure there are other assumptions in the code about the rate being 22hz).

It doesn't matter specifically for me right now to get 44.1 working, but in principle... IT WORKS! :)

Which is great news and potentially a great selling point actually (it basically makes it twice as good for audio, yay!).

abritinthebay
 
Posts: 32
Joined: Wed Dec 02, 2009 5:00 pm

Re: Wave Shield and Arduino Mega: how-to

by fat16lib on Sat Dec 12, 2009 6:35 pm

I think half speed is due to missing every other timer interrupt in the DAC ISR. I guess I will dust off the optimized DAC program I did in July and see if I can fit it in.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

by abritinthebay on Sat Dec 12, 2009 6:49 pm

Cool, thanks for all the help and feedback too. It's really helped me understand whats going on in the Wave Shield a LOT more.

I'm not a C/C++ programmer (I do more python and similar web-stuff languages) but the code is really well documented (if a little confusingly spread out over files when I was reading through it) and it's nice and easy to work out what is going on (for the most part).

abritinthebay
 
Posts: 32
Joined: Wed Dec 02, 2009 5:00 pm

Re: Wave Shield and Arduino Mega: how-to

by ralph on Mon Dec 14, 2009 1:10 pm

Good day all!

First excuse me for my Chargoal English, it is not my native tongue.

I am a little confused now.
Last week I received the Waveshield for my... Arduino Mega.
In the product specs (Adafruit website) I did not read anything about incompatibility with the Arduino Mega.
Thereby I just understand that it is not possible to use the wave- and motor shield at the same time?
So now it seems I have the unparticipated challenge of 'rebuilding' the Waveshield.

I am not a technician (nor hardware or software), but I am very interested in robotics.
Yes I can hold a soldering iron and (re)write some code, that is it.
My question: Do I follow the first solution of our friend Gregsadetsky?
Or, do I have to be patient and wait for another solution?

You have to know that I also like to use a Motorshield, Rainbowduino and some sensors (IR, URM37 V3.2 on servo's) at the same time.
I will appreciate your advice very much!
ralph
 
Posts: 1
Joined: Mon Dec 14, 2009 12:58 pm

Re: Wave Shield and Arduino Mega: how-to

by designfactore on Mon Oct 11, 2010 5:54 pm

Hi,

does anyone know if the SPI pin issues are the same with the new Mega (Mega2560)?

designfactore
 
Posts: 12
Joined: Sun Aug 22, 2010 1:02 pm

Re: Wave Shield and Arduino Mega: how-to

by fat16lib on Mon Oct 11, 2010 9:12 pm

The 1280 and 2560 have the same pin map so the SPI issues are the same.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

by toddah on Tue Oct 12, 2010 4:37 pm

Hello,
New Arduino Mega2650 and WaveShield owner here, just finished soldering up my WaveShield 1.1 lastnight and suprise it did not operate so after rechecking all hardware assembly off to the forum to gather information and after a few hours I found this thread! Glad to see someone has documented this issue.
So just to try and get a line on exactly what all I need to do to get my waveshield 1.1 working with my mega2560 with the WaveHC library.
Sorry but the thread kind of drifted on and off topic and I want to get this right the first time. Could someone who has done this please confirm these are the required steps or did I miss anything.

2.1 Close the Arduino IDE
2.2 Download the two header files attached to this message: "dac.h" and "sd_raw_config.h", place them into arduino/hardware/libraries/AF_Wave/ replacing the original files.
2.3 Delete the ".o" object files sitting in the same directory.
2.4 Using diagonal cutters, clip the header pins connected to digital pins 11, 12 and 13 on the shield. See this picture: http://gregsadetsky.com/_files/ladyada- ... C_0093.JPG

2.5 Unsolder the jumper cable going from the "CCS" hole (next to the shield's reset button) to the digital pin 10 hole.
2.6 Make four 4-inch jumper cables; they should each be soldered on one side at: the "CCS" hole (see step 2.5), and the digital input/output holes 11, 12 and 13 on the shield. The other side of the four cables will connect with four of the Mega's digital pins. You should label the four cables with stickers.

See these pictures:
- http://gregsadetsky.com/_files/ladyada- ... C_0089.JPG
- http://gregsadetsky.com/_files/ladyada- ... C_0091.JPG

The cable going from the "CCS" hole on the shield connects with the digital pin 53 on the Mega.
The cable going from the digital input/output hole 11 on the shield connects with the digital pin 51 on the Mega.
The cable going from the digital input/output hole 12 on the shield connects with the digital pin 50 on the Mega.
The cable going from the digital input/output hole 13 on the shield connects with the digital pin 52 on the Mega.

2.7 You're done! You should be able to physically install the shield over the Mega, compile any example such as "PlayAllLoop", connect the Mega by USB and run it.

#######################################################################################################
If running Fat32 card using WaveHC
#######################################################################################################
If using the WaveHC stuff do I need the dac.h and sd_raw_config_h files from the link or are there counterpart files for the waveHC or is that what the mod listed below does?

You can try changing the SPI defines in SdReader.cpp from

Code: Select all

//SPI pin definitions
/** Slave Select pin for card */
#define SS 10
/** spi master output, slave input pin */
#define MOSI 11
/** spi master input, slave output pin */
#define MISO 12
/** spi serial clock pin */
#define SCK 13

to:


Code: Select all
#if defined(__AVR_ATmega1280__)
#define SS 53
#define MOSI 51
#define MISO 50
#define SCK 52
#else //__AVR_ATmega1280__
#define SS 10
#define MOSI 11
#define MISO 12
#define SCK 13
#endif //__AVR_ATmega1280__

. I deleted the .O files, reloaded pispeak_hc and she began to speak!
Thank you, thank you , now on to the next phase.

#######################################################################################################

Did I get it all ?

THanks for your help.
Toddah
toddah
 
Posts: 4
Joined: Tue Oct 12, 2010 3:54 pm

Please be positive and constructive with your questions and comments.