Playing wav via Arduino board

Hi
I need some advice on wav files and Arduino please.
I have a keyestudio mega 2560 r3 with motor attachment KS0509, an mkrvrs pam8302a amp and an mkrvrs ce07926 SD module.
I am wanting to play wavs from the SD through the Arduino into the amp and out to my speaker.
Is it the case that I must use a DAC module?
If so, what would be the best choice?
Also my 2560 seems to be obsolete and I’m not sure of all the pin connections on the 2560. I can’t source this info. How do I connect the amp and SD module to the 2560? And the DAC module if required?
Thanks for any help?
Chris

I followed this tutorial. You can follow the same with your Arduino Mega.

The 2650 may be old, but it is just as functional as it was when it was new. There is plenty of information available about the pinout. For example:
Arduino Mega 2560 Rev3 — Arduino Online Shop

It is possible for the Mega to decode the wave files and create the digital audio waveform, but the result is not very satisfactory - not a lot better than a Christmas card that plays a song when you open it. There is an example here:
Playing Wave File Using Arduino : 5 Steps (with Pictures) - Instructables

The examples show it driving a speaker directly, but you could use any amplifier.

A decoder module is more complex to set up but provides more control and much better quality. See, for instance:
DFPlayer Mini MP3 Player - DFRobot
There is example code here:
DFRobot/DFRobotDFPlayerMini: Arduino library for DFPlayer
This example uses a Nano, not a Mega, but the pins are equivalent.
Best Way to Play Audio on Arduino! DFPlayer mini / MP3-TF-16p Tutorial

Iia262073. Thanks for your reply. The Mega’s pin layout/numbering seems to be quite different. I’m unsure which pins to use for the SD card and amp connections. Also is a DAC needed? Here is a pic of the board.

(attachments)

Jeff105671. Thanks for your reply. I’ve attached a pic of the Mega. To me the pins are very different on this board. Can you advise on the pin connections? Thanks

That board is not an Arduino Mega2560, although it uses the same chip. You will find details for it if you search for ‘Keystudio Mega 2560 Smart’ It is specifically designed for a motorised robot.

I think that most of the ports available on a UNO or Nano are there. D9~D12 are on the motor headers, and may or may not be usable. I can see 2 4 5 6 7 8 13 on the ‘Digital IO port’ - some others may be hidden.

With the exception of the first few analog ports (A0-A5) all the pins on the side rails are additional to those available on a UNO or Nano. However, for all these boards the GPIO pins are generic, and can do most of the functions. For instance, pins A6 to A15 will all function exactly the same as any Ax pin on a UNO or Nano, and 24 to 59 will function mostly the same as any digital pin on a UNO or Nano. (The difference is whether they support hardware PWM or not, which will be documented for the 2560 chip (D44-D46).)

Note that 50/51/52 are brought out to a separate header - these are the SPI pins for the Mega, equivalent to the centre 6-pin SPI header on a UNO. Also I2C (SDA, SCL) are brought out to their own header (A4 A5 on a UNO/Nano).

What is not clear from the Keystudio site is whether or not the pins used for the on board devices (D9~D12) are available for external use. Will those pins still behave as expected?

So given that all of the UNO/Nano GPIO are either available at pins or have substitutes available it would be possible to run most Arduino code on this board. But it would likely require some careful renumbering of the pin usage. Considering the current price of a Nano it seems preferable to dedicate this board to its intended function (which is a lot of functionality) and buy a Nano (or any equivalent small development board) instead.

3 Likes

Thanks Jeff105671 for your detailed reply and your advice.