I would like to process a text, that is too long to be saved in a char array.
Is there a possibility to load the text file to the arduino flash memory and read from the text file?
Or what would be the best way to use larger texts in arduino programms (if possible only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)
if the text is too large you should consider external memory like an SD card (file) or EEPROM (sort of array)
Then you can (possibly) process the text in chunks that fit in the memory
Thank you. The text ist too long. I get errors when trying Serial.println(F("This string will be stored in flash memory")); as I get, when I try to put it in a variable. Isn't there a possibility to save the text in a file in the flash memory and read from it?
char largeText[] = "\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
";
void setup()
{
Serial.begin(115200);
Serial.println("Start ");
int idx = 0;
while(largeText[idx] != '\0')
{
Serial.print(largeText[idx]);
idx++;
}
}
void loop()
{
}
(update)
and with PROGMEM
char PROGMEM largeText[] = "\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
";
void setup()
{
Serial.begin(115200);
Serial.println("Start ");
int idx = 0;
while(largeText[idx] != '\0')
{
Serial.print(largeText[idx]);
idx++;
}
}
void loop()
{
}
NORMAL VERSION
Global variables use 601 bytes (29%) of dynamic memory, leaving 1,447 bytes for local variables. Maximum is 2,048 bytes.
PROGMEM VERSION
Global variables use 195 bytes (9%) of dynamic memory, leaving 1,853 bytes for local variables. Maximum is 2,048 bytes.
Thank you very much. But this does not work for my text: it is at least 5 KB...
Does this mean that there is no other chance than using an SD-Card?
So the better way would be for me to read the file from my PC. I will try to find a solution how to read from a raspberry...
I found solutions via Processing- but there must be a way to do this directly via command line (kubuntu or raspbian), i think? If you could recommend some points where to start, I would be glad about some hints...
So I misunderstood your writing about memory above... but nevertheless, if inserting my text or another long text I get an
'Exception in thread "Thread-1298" java.lang.StackOverflowError'....
mikolaskova:
So I misunderstood your writing about memory above... but nevertheless, if inserting my text or another long text I get an
'Exception in thread "Thread-1298" java.lang.StackOverflowError'....
I don't think Rob's PROGMEM code example would work as is (no reference to avr/pgmspace.h) but the problem your getting is the same one I had when trying to use long strings in a sketch and I think the problem is the IDE.
If you cut the strings up into smaller chunks then you will be okay. See attached example.
Indeed my code above does not work, however it puts the large text in FLASH as shown by the compilation output.
thanks for pointing out
update
this version works
#include <avr/pgmspace.h>
char PROGMEM largeText[] = "\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
Hello,\n\
\n\
I would like to process a text, that is too long to be saved in a char array. \n\
Is there a possibility to load the text file to the arduino flash memory and read from the text file?\n\
\n\
Or what would be the best way to use larger texts in arduino programms (if possible\n\
only with the Arduino UNO- without additional SD Card or connenction to a PC- these solution I found)\n\
\n\
Thanks and regard\n\
\n\
Adriana\n\
";
void setup()
{
Serial.begin(115200);
Serial.println("Start...");
int idx = 0;
while((char)pgm_read_byte_near(&largeText[idx]) != '\0')
{
Serial.print((char)pgm_read_byte_near(&largeText[idx]));
idx++;
}
}
void loop()
{
}