How to download a file to device in 2018


Every couple of years newbies like me ask the question.

“How do I down load an audio file from the server and store it on an SD Card”

In previous years the answer was “you cannot” but the system has moved on a lot so I am asking again.

  • If SD card is not possible then are there SPI Flash options?


I have a way easier option for you.

You purchase a DFPlayer. That is a tiny MP3 player where you store hundreds of MP3 audio files on a micro SD card. It interfaces easily with Arduino, which is easy to “port” to imp. Uses serial pins. It already has a stereo headphone amp built in, and a mono 8ohm speaker pin.

I guess the question would be … are you trying to play various audio files using the imp, such as a remote kiosk?


There are options - you can use the SPI flash filesystem, for example ( ) or @mlseim’s one of using an integrated MP3 player device for the audio. Kinda depends on what you’re trying to achieve.

You can also stream audio directly from the web to an imp device (ADPCM format). That’s actually pretty easy, and then has no limits on file size etc.

What’s the use case?


Thank you hugo and @mlseim.

My requirement is to play audio from the device. I cannot use streaming because of network quality issues.

I am using DFPlayer and I have a really nice system that plays tracks from the DFPlayer SD card. However the DFPlayer can only play music from its SD Card and this is not writable. I want to be able to download MP3 from the internet and so I have reached a dead-end with the DFPlayer.

My requirement is to download MP3 using the Imp (push from internet) and store it on an SD Card. I will then get an MP3 module to play the MP3 from the SD Card. I have no idea how to actually do this yet but I am proceeding 1 step at a time.

Therefore my requirement is to be able to download a file using the Imp and store it on an SD Card. The Particle forums ;> have lots of use cases for this, both audio and images and people are making a little progress there. I hope it is possible with the Imp.


How big are the files you are wanting to play?

You can use an MP3 player chip which is less integrated - like the VS1053. You can get them on boards like this:

It does have an SD slot, yes, but actually that’s just a separate peripheral on the device. You can talk to the MP3 decoder directly over SPI. It will signal on DREQ when it wants its FIFO filled. We did a board many years back for this but finding the code may be hard this far on.

That’s certainly worth a try. You could also use the SD card (everyone uses them in MMC mode so they’re byte addressable) for storage.


Thanks Hugo. At the moment I am not really sure how big the files are going to be but they are more likely to be small sound effects than long symphonies.

That is definitely a step forwards on the playing front. I can see that I could use the Imp to read content from SD card in MMC mode and pass it to the VS1053 a chunk at a time.

To return to the original question.

*How do I download a file over https and store it on the SD card in MMC mode?

Please excuse my newbie questions. I have 20 years experience of building server-side solutions but only three weeks using micro-controllers. It is both easier and more difficult than I imagined. Easier because of the great libraries and support, more difficult because simple things like downloading and storing a file are not simple.


So, it’s pretty simple on an imp, especially if you’re used to server side programming.

The agent (runs cloud side) can issue an HTTP(S) fetch for any accessible resource. The agent only runs with 1MB of memory though, so to fetch large resources you would use HTTP range headers to chunk the data. Once you have a chunk in the agent, you can then send this (with device.send) down to the device, which can then store it.

Again, the device is memory limited (anywhere from ~85kB on imp001 to ~1.2MB on imp005) so you may need to split it into bite sized pieces - I usually do this ~8kB at a time - on the agent side.

Actually… I’ve been meaning to write this example for a while. Here’s some code which will stream an A-Law encoded WAV directly to an imp (1/2/3/4) from a website:
… it plays the 7:56 song “Anzeal” by “Strange Angel” which was one of the free MP3s posted on back in 1999.

Not exactly what you were looking for, but you can see how you can fetch & chunk files down to the device.


(btw, if you don’t have an audio amp, just use a pair of headphones: a ground wire to the metal of the plug closest to the wire, and touch the tip of the headphones to the DAC pin on an imp breakout)


Thanks Hugo,

I am a weekend warrior on this project so if could write an end-to-end example of downloading an https file to the device and storing it on an SD card you would save me and others, a lot of time bashing our heads against unfamiliar paradigms.

I think that this problem is a wide-spread challenge for new developers as shown by earlier posts in this forum and also on the Particle forum.

You have lots of great posts. Are you an Electric Imp employee, a hobbyist or a freelancer, or perhaps some combination?



Plus, I used to run a BBS back in the 80’s so I’ve been addicted to forums ever since :wink:



My project is going well; my goal is to make a secure inexpensive SoHo (small-office home device) that can sell at high volumes through both B2B (business to business) and retail channels.

I will be starting a small Indiegogo campaign in the next couple of months to do some market testing followed by a big campaign to build a market and fund high volume production.

Would the Electric Imp like to be involved before the campaign begins? This would allow marketing co-ordination around “Security” and would smooth the transition to high volume production.

If you would prefer to contact me privately you can do so at


Thanks for the advice you gave me offline. The streaming solution is very good for lots of use cases but some of my target applications have low bandwidth and I have to cache MP3 files locally.

Reference code to download and store an MP3 on an SD Card or SPI chip would be a great step forwards for me and valued by others new to IoT.


I’m afraid I’m unlikely to be writing that code. You can download to a SPI flash pretty easily. MP3 files - especially snippets - are very small, an SD card is overkill.


No problem, I’m on it this weekend. Thanks,