Wave Shield and Arduino Mega: how-to

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
gregsadetsky
 
Posts: 2
Joined: Mon May 04, 2009 5:05 pm

Wave Shield and Arduino Mega: how-to

Post by gregsadetsky »

1. Explanation
2. Solution
3. Extra credit

1. Explanation

Hi,

After getting the Wave shield, I've discovered that although the shield's hardware is "generally" compatible with the Mega board (e.g., the shield sits well on top of the Mega, ground and power pins are aligned, etc.), the pins used to communicate between the Mega and the shield must be remapped in software and unfortunately (for the time being) in hardware.

I've found most of the answers I was looking for by comparing the Duemilanove's and the Mega's schematics. There were two problems to solve:

a) the Duemilanove's SPI pins (used for communicating with the SD card) are located on digital pins 10, 11, 12 and 13. The Mega's SPI pins are 50, 51, 52 and 53, on the right side of the board, out of the shield's "reach".

b) The digital pins 2, 3, 4 and 5 used by the Mega board to communicate with the DAC (digital to audio converter) have a different software port mapping from the Duemilanove's.

--------

2. Solution

NOTE: A more elegant (e.g. software-only) solution may be possible (see "3. Extra credit" below). For the time being, this works...

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.

--------

3. Extra credit

I'm a beginner, so be gentle:

Is there an easy / elegant way of running a "software" SPI interface (e.g., not using the Atmel chip's built-in MOSI, MISO, SCK, SS pins), but faking one by driving four arbitrary digital pins high and low, just like with the DAC?

If so, the digital pins 10, 11, 12 and 13 could be used to communicate with the SD card as they do in the case of the Duemilanove, and no hardware modifications would be necessary to use the Mega's SPI pins.
Attachments
sd_raw_config.h
(3.04 KiB) Downloaded 1677 times
dac.h
(1.02 KiB) Downloaded 1452 times

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Wave Shield and Arduino Mega: how-to

Post by adafruit »

software SPI is slower than hardware SPI, and you need it to be FAST in order to stream audio
id stick with hardware SPI

pap
 
Posts: 4
Joined: Tue Apr 21, 2009 5:31 am

Re: Wave Shield and Arduino Mega: how-to

Post by pap »

So from your (great!) research I can conclude that the Waveshield is working 100% with the Arduino Mega? :D

User avatar
westfw
 
Posts: 2006
Joined: Fri Apr 27, 2007 1:01 pm

Re: Wave Shield and Arduino Mega: how-to

Post by westfw »

software SPI is slower than hardware SPI
Are you sure?

I haven't looked at the waveshield spi hardware driver, but it seems to me that lacking anything like full-sector DMA, a hardware driver is either busy-waiting for each byte, or killing itself processing interrupts, and a software driver ought to be able to achieve pretty close to the same bitrate overall, and "easily" enough for audio bitrates.

2x audio bitrate (read from card, write to DAC) might be pushing things. On the other hand, you might be able to overlap the two operations in ways I don't think are possible with HW SPI. (read a bit from card, write a bit to DAC on the same clock edge? Is that possible given the wiring?) (handling the extra card reads/writes to switch sectors makes me nervous, though.)

You wouldn't be able to use the Arduino pin primitives, of course (20x slower than direct port manipulation), but you're already beyond the Arduino primitives using the HW SPI driver anyway.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Wave Shield and Arduino Mega: how-to

Post by adafruit »

i cant recall what i did to verify but i remember i tried both and it was a little bit slower to do software spi because of the shifting
this is NOT true for all avrs. for example on the 'tiny2313 the spi is so annoying its easier to do it software style :)

alejandrina
 
Posts: 1
Joined: Sat Jun 06, 2009 3:35 pm

Re: Wave Shield and Arduino Mega: how-to

Post by alejandrina »

Hi!

I'm a total beginner with programming in general and Arduinos, but I'm trying to learn how to build robots. I'm very thankful that you posted the information about the wave shield and the Mega because I've been using the waveshield with my Arduino duemilanova for a couple of months, no problems... but now I have a mega and it didn't work. It would have taken me forever to figure out the pin solution from looking at the chip schematics...
my question: I downloaded the files, replaced them in the AF library directory. I also erased the .o files. But when I restarted the Arduino, I still got the following errors:
"
fat16.cpp: In function 'fat16_file_struct* fat16_open_file(fat16_fs_struct*, const fat16_dir_entry_struct*)':
fat16.cpp:603: warning: only initialized variables can be placed into program memory area
fat16.cpp:624: warning: only initialized variables can be placed into program memory area
sd_raw.cpp: In function 'uint16_t sd_raw_read_start(uint32_t, uint8_t*, uint16_t)':
sd_raw.cpp:460: warning: only initialized variables can be placed into program memory area
sd_raw.cpp: In function 'uint16_t sd_raw_read_more(uint8_t*, uint16_t)':
sd_raw.cpp:496: warning: only initialized variables can be placed into program memory area
wave.cpp: In function 'uint16_t readwavhack(Wavefile*, uint8_t*, uint16_t)':
wave.cpp:342: warning: only initialized variables can be placed into program memory area
wave.cpp:357: warning: only initialized variables can be placed into program memory area
wave.cpp:378: warning: only initialized variables can be placed into program memory area
wave.cpp: In member function 'uint8_t Wavefile::create(fat16_file_struct*)':
wave.cpp:454: warning: only initialized variables can be placed into program memory area
wave.cpp:501: warning: only initialized variables can be placed into program memory area
wave.cpp:503: warning: only initialized variables can be placed into program memory area



what does this mean?


thanks!
beatriz

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

Post by fat16lib »

These warnings can be ignored. They are most likely bogus.

The compiler, avr-gcc, used by the Arduino IDE has a bug that gives false warnings about the initialization of variables stored in flash memory which is called program space.

This only seems to happen in C++ files, not C.

Here is the bug report http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734

User avatar
farmerj
 
Posts: 5
Joined: Tue Jun 16, 2009 2:42 pm

Re: Wave Shield and Arduino Mega: how-to

Post by farmerj »

What a wonderful post - gregsadetsky!! I have a Wave shield that I am trying to setup on a Mega. I have modified the board according to your well documented directions. The hitch is that I am trying to use a SDHC card and (therefore) the WaveHC library. Do you have any thoughts on software adjustments that may be necessary to make that combination work. I could not find anything in the WaveHC library that resembled sd_raw_config.h. I did swap out the dac.h files. I tried to run pispeak_hc but the card failed to initialize. The card worked well on two different wave shields on a Duemilanove w/ 328 prior to the mod so I am thinking that it is likely some setting that is hanging it up.

Any assistance or recommendations most appreciated!

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield and Arduino Mega: how-to

Post by fat16lib »

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 do not have a wave shield modified for the Mega so I can not test this.

You also need the version of dac.h with the Mega pin defs.

Let me know if it works and I will modify WaveHC so that it supports modified Wave Shields on the Mega.

User avatar
farmerj
 
Posts: 5
Joined: Tue Jun 16, 2009 2:42 pm

Re: Wave Shield and Arduino Mega: how-to

Post by farmerj »

Yep, that's it . . . . on the button. I deleted the .O files, reloaded pispeak_hc and she began to speak!
Thank you, thank you , now on to the next phase.



Wait, that reminds me it's time for dessert, maybe a little ice cream with my pi.

nandadoes
 
Posts: 4
Joined: Fri Jul 17, 2009 8:31 am

Re: Wave Shield and Arduino Mega: how-to

Post by nandadoes »

Hi,

Does it take all PWM pins? What if I need those pins for other devices?
Can the library playback wave files in an order?
Can it be triggered by an external sensor like a button on a keypad.
For example
if press key 1, play sound 1,
if press key 2, play sound 2,
if.........

Tony
 
Posts: 1
Joined: Sun Aug 02, 2009 6:33 pm

Re: Wave Shield and Arduino Mega: how-to

Post by Tony »

gregsadetsky wrote: 2. Solution

NOTE: A more elegant (e.g. software-only) solution may be possible (see "3. Extra credit" below). For the time being, this works...

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.
THANK YOU!! THANK YOU!! THANK YOU!! gregsadetsky

When I bought my Mega1280 and WaveShield form Makershed.com, I had no idea they were not compatible. I did everything the instructions said and it didn't work. Then I did a search and found the above post. I did all your steps (and just those steps), ran their example PlayAllLoop and IT WORKED!!! :D
Someone really needs to change the directions for future WaveShield buyers.
And, while they are changing them, put instructions for both v1.0 and 1.1versions. The WaveShield kit I bought from Makershed.com on July 20, was version 1.0, but the instructions were from v1.1. I had to work out which resister went where from this old v1.0 pictures. After I finished soldering them all in, I found the circlet diagram with the values on it. Oh well.
I just wanted to thank you and tell you, "U Da MAN"

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Wave Shield and Arduino Mega: how-to

Post by adafruit »

the library will be updated for mega shortly
if you need v1.0 instructions, they're linked in the first paragraph of the instructions
http://www.ladyada.net/make/waveshield/solder.html

ndudman
 
Posts: 3
Joined: Tue Oct 13, 2009 7:49 am

Re: Wave Shield and Arduino Mega: how-to

Post by ndudman »

Had the new version compatible for Mega been finished yet ? I've just finished soldering my Wave shield to also realise that it won't run as is on Mega... I missed the warnings I'm sure :)

N

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Wave Shield and Arduino Mega: how-to

Post by adafruit »

unfortunately it seems like there were major changes to the mega that moved the SPI pins. we tried to make this suggestion before the mega was made but now its too late :( so the hack above is probably the best bet right now.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”