I have a sketch that reads color values from an sdcard then displays these colors on WS2812B LED strip using fastLED library.
I have 350+ files on the sdcard, After reading each file it displays it then closes it then reads the next file, but after reading the first 200 files it starts running slow until it finishes all the files then starts to run fast again.
How can I fix that behavior?
The content of each file is like the following: each row contains the color value(in decimal base) of one LED
My guess is you are out of RAM for the file system. Consider combining several in one file as you read them sequentially anyway. If you can simply use an ASCII character, then you know when a new record is reached. This is a starting point.
Good Luck & Have Fun!
Gil
DrDiettrich:
Avoid the String type, use char arrays instead.
I've tried that but the result is the same.
gilshultz:
My guess is you are out of RAM for the file system. Consider combining several in one file as you read them sequentially anyway. If you can simply use an ASCII character, then you know when a new record is reached. This is a starting point.
Good Luck & Have Fun!
Gil
Does running out of memory makes it run slow?
I close every file after finishing reading it. So it should free up memory space.
It normally makes it not run at all, or have strange faults. I think that comment was based on experience of a different processor architecture where you swap memory between different sorts of memory like an SD card and ram. The basic Arduinos do not run from RAM but from flash memory.
Can you post the code where you replaced the String types so we can see how you did it.
It normally makes it not run at all, or have strange faults. I think that comment was based on experience of a different processor architecture where you swap memory between different sorts of memory like an SD card and ram. The basic Arduinos do not run from RAM but from flash memory.
Can you post the code where you replaced the String types so we can see how you did it.
while(true) in any program worries me. Are you sure you are returning to the correct place? It could be that you are not actually closing the file because you are returning out of the loop function not the while. Even if it is OK it is bad practice.
Grumpy_Mike:
while(true) in any program worries me. Are you sure you are returning to the correct place? It could be that you are not actually closing the file because you are returning out of the loop function not the while. Even if it is OK it is bad practice.
I guess this might be it, because when I've changed the way my code works, it works flawlessly
You do no error handling so why not use binary data files instead of text? You won't have to translate text to binary.
CRGB elements are 3 bytes, 1 each for red, green and blue. Store values, read values and fill the FastLed array then run the show function. That leds[] array is all you want to store anyway.
GoForSmoke:
You do no error handling so why not use binary data files instead of text? You won't have to translate text to binary.
CRGB elements are 3 bytes, 1 each for red, green and blue. Store values, read values and fill the FastLed array then run the show function. That leds[] array is all you want to store anyway.
I'm pretty sure that an Uno could do this.
Actually, I was planning to read these values from .BMP file instead of txt files, but I didn't want to deal with the hassle of reading the BMP file and figuring out how everything fits together. So I have a PHP script that reads the BMP files using ready-to-use-out-of-the-box functions then out put these values in a txt file then read these values using the Arduino.
The reason there's no error handling is that I know the structure and how everything is going to be so everything is running in a controlled environment, Plus I'm still in the prototyping stage so no need to do error handling for now
LehKeda:
Actually, I was planning to read these values from .BMP file instead of txt files, but I didn't want to deal with the hassle of reading the BMP file and figuring out how everything fits together. So I have a PHP script that reads the BMP files using ready-to-use-out-of-the-box functions then out put these values in a txt file then read these values using the Arduino.
The reason there's no error handling is that I know the structure and how everything is going to be so everything is running in a controlled environment, Plus I'm still in the prototyping stage so no need to do error handling for now
Handling involves recovery and that needs structure. If you don't build it in from the start then you end up kludging it in later. I've done the latter often enough to know how it happens.
BMP files are not arcane. They are very step by step, find a good doc on BMP files and it should have a kind of file layout "map". Your read & display speed should jump.
At the very least if you're using text, make it hex values of the binary data and you won't need atoi() to assemble the values into CRGB, 6 bytes per pixel at most will do.