Using SD Card to save arrays for WS2812B matrix

Im trying to make a 16 by 16 LED matrix using Fast led and a WS2812B matrix.
Im quickly running out of memory with different animation frames as I want to add other features like a clock perhaps. Im wondering if I can store them instead on an SD card rather than in flash memory and then get the Arduino to read them each time.
this is the code that currently does animation. I would name each animation frame on the card as a different file name so the file name would replace "arrayname" in the code below.

void readarray2 (int runtime, int timer, const long arrayname1[], const long arrayname2[]) {

  // Put first frame
  for (int passtime = 0; passtime < runtime; passtime++) { // Display it runtime amounts

    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = pgm_read_dword(&(arrayname1[i]));

    // Put Space invader down frame
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = pgm_read_dword(&(arrayname2[i]));


It is doable and SD has incredible capacity.

OTOH an Uno has 32K flash and that program should use 8K of that leaving 24K;

Suppose you limit the number of colors to 256? Then you store a table of FastLed colors in 768 bytes and the pattern lights take 1 byte each instead of 3.

You compile data into flash with PROGMEM statements. You read it with PROGMEM functions.

Yes, but for a really long animation like the one from my friend.

In this case, the song is on a micro SD card on a drone.

What frame rate do you hope to achieve?

The video isn’t very clear, is he really a friend?

It is highly likely that the “animation” is accomplished computationally, that is the frame pixels contents are calculated by algorithm at some frequency and the result used to refresh the strip contents.

Not required: storage beyond the one strip buffer.

Required: programming, clever or not depending on what visual effects you are trying to do crossed with your own coding abilities.


1 Like

I see the color change every so often too far away for details.
If you only record the changes (data compression), not a killer.

No "Arduino" MP3 player w/SD I have bought let the Arduino get data from a file on it.

You might as well read the music with an MSEQ7 and generate colors.

Yes, the drone belongs to a friend of mine. The idea was his and I wrote the code. The song is located on the micro sd card of the drone as a mono WAV file. Its works on 50 fps as audio level meter with color change on strip with 12 LEDs. No needed MP3 player, song is add later on video.

How do you go about limiting the colours? Im new to FastLed.

The Fastled library should have a big table of named colors.
It also has code for palettes.
It's got code to do a huge list of things.

Me, I would make an array of CRBG objects ( like the leds[] array) ) to hold colors and then copying color from the color array to the leds array.

Yes. A lookup table will be essential.

My back of the envelop cakulations suggest that it will be possible to achieve 50 frames a second, maybe, but there will be little time for anything else.

Pull 256 color number bytes off the SD and get the full color to put in the buffer.

Transfer the buffer to the matrix.

Rinse Increment and repeat.

Now the interesting part is creating the data in the animation files…

I would name each animation frame on the card as a different file name

I missed that, that’s a loser IMO, a file should have all the frames for each different animation. One file, one animation, N frames, N * 256 bytes.

Not even wondering if open and close operations would kill you frame rate.


You seem intent at overdoing. 50 FPS where 25 is enough to be perceived as motion.
For good effect on a moving object try just changing all from one color to the next with an OFF blink in between at 2 to 5 FPS while flying.
If you limit the palette to 16 colors you can pack 2/byte in the pattern.

SD runs at SPI bus speed 512KHz default with card delays especially when writing.
There will also be delays where the data is not continuous on the card but they are short.
SD has a real power cost to your battery.

Your code reads and writes to a 512-byte buffer using DOS calls. You can find the buffer address and with planning use buffer contents as C++ objects without copying to other RAM, process, copy back and store. The data only has to be in one place until the job forces such a need. Don't create one!

You can buy ATmega1284P chip or board, it is an AVR with 128K flash, 16K RAM, 4K EEPROM and 32-IO pins of 40. I have breadboarded them. I have a 1284 board from Slovakia that overclocks to 24MHz. The DIP chip version cost me US$5.50 last time.

Thanks for the suggestions. Im not looking for more than a few fps as Im animating sprites like Pacman! My code seems to fit and run ok without the SD card currently.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.