Using Large Text

Hello,

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)

Thanks and regard

Adriana

Store those large strings in flash memory using the F macro.

Serial.println(F("This string will be stored in flash memory"));

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?

Flash memory is read only.
So you can put a text in it compile time but not run time.

yes, compile time would be enough, I don't need to change the text afterwards..but I do not know how to put it there

try this

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.

To put strings in flash memory and read them back have a look at PROGMEM.

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...

FLASH is 32 KB so it can easily hold a 5KB text string. ... just tried 9KB .... when using PROGMEM,

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.

sketch_jul27a_PROGMEM.ino (12.2 KB)

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() 
{
}

note it prints one char at the time

Thank you very much- now it worked. I just had to make the variable, the text is stored in a constant... now it works with very large text.