I am an Arduino beginner and I am planning to make a musical instrument with it. I want to add record and playback functionalities into the instrument.
I figure I will have to store lots of data to meet this feature, but the Arduino I'm using (Uno/Nano) probably won't have enough memory to hold lots of songs.
My question is, is using an SD card with an SD shield a good way to expand memory? If not, what should I use to do so?
Thanks
-
1As a beginner this MIGHT be a bit of a big thing to take on. Not that you shouldn't do it, just be aware that trying to write the code that will read and process data from SD is not trivial. Also don't think of this as EXPANDING the memory of the arduino, as the memory you are adding cannot be used for your program.Chad G– Chad G2018年03月14日 22:57:24 +00:00Commented Mar 14, 2018 at 22:57
-
they make hardware audio modules, for example with mp3 playback from sdcards or bluetooth, and that would be mounds eaiser than implementing it all yourself using low-lever hardware and from-scratch software. Checkout adafruit et al.'s offerings in that area before you spend week re-inventing a wheel.dandavis– dandavis2018年03月15日 03:28:19 +00:00Commented Mar 15, 2018 at 3:28
-
By "record and playback" do you mean audio recording, or something more akin to MIDI where you just record the instructions of what notes to play when?Majenko– Majenko2018年03月15日 11:00:20 +00:00Commented Mar 15, 2018 at 11:00
-
@Majenko I would be recording what note/pitch is being played, and playback would just play audio based on this dataDavid Liao– David Liao2018年03月16日 17:01:30 +00:00Commented Mar 16, 2018 at 17:01
-
1So like MIDI then. Sure, you can do that with SD.Majenko– Majenko2018年03月16日 17:06:05 +00:00Commented Mar 16, 2018 at 17:06
2 Answers 2
There are different options:
SD shield: much memory (GB's), however keep in mind that it will take time to retrieve the data from the SD card. Also you can retrieve 512 bytes every time (which also means it costs 512 precious bytes of arduino SRAM).
External SRAM: There are external SRAM ICs, like 23LC1024 or 24K256. These are much faster and offer 128 or 32 KB. There are many others too, these are most 'common'. These are much faster than SD cards, you can get 1, 2 or more bytes per time. But it's not the same as Arduino SRAM, e.g. you cannot really store variables, so you have to copy data to internal SRAM to be used.
So first, check how much you need, and more important: what is the latency you can live with.
-
2SRAM is probably not going to get the OP very far when it comes to audio, although it could be used as a buffer between "disk" and the arduino to improve latency issues.Chad G– Chad G2018年03月14日 22:59:25 +00:00Commented Mar 14, 2018 at 22:59
-
True, I now read playback and record.Michel Keijzers– Michel Keijzers2018年03月14日 23:03:13 +00:00Commented Mar 14, 2018 at 23:03
-
1ESP32 modules have more RAM and 4mb of flash for less money than those ICs ;)dandavis– dandavis2018年03月15日 03:32:40 +00:00Commented Mar 15, 2018 at 3:32
-
For audio processing, you might better use a Raspberry PI.Michel Keijzers– Michel Keijzers2018年03月15日 09:20:18 +00:00Commented Mar 15, 2018 at 9:20
-
Thanks for the response! Based on your description I think an external SRAM would probably be better for the purpose.David Liao– David Liao2018年03月16日 16:55:21 +00:00Commented Mar 16, 2018 at 16:55
Since you are working just with instructions on how to play audio, not the audio itself, you effectively have very small amounts of data (comparatively).
You can store that data in a file on SD card and read it back simply enough (there's plenty of examples for reading from and writing to SD).
You don't need the whole song in memory all the time - you only care about the note you're playing (or recording) at any one instance in time, so you don't need lots of memory.
How you format the data is entirely up to you, but I would suggest following the MIDI standard which will allow you to work with other tools to create and edit the files as well as the Arduino. You can also then export your music simply to other applications, such as MuseScore, Finale, Sibelius, Ardour, etc.
Explore related questions
See similar questions with these tags.