Long string in arduino uno fail to compile

Hi guys, I need to store a long char array (something like 2 thousands letters). when i try to compile it using arduino IDE i get endless amount of errors

at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777) at java.util.regex.Pattern$Branch.match(Pattern.java:4604) at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658) at java.util.regex.Pattern$Loop.match(Pattern.java:4785) at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717) at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568) at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777) at java.util.regex.Pattern$Branch.match(Pattern.java:4604) at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658) at java.util.regex.Pattern$Loop.match(Pattern.java:4785) at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717) at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568) at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777) at java.util.regex.Pattern$Branch.match(Pattern.java:4604) at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658) at java.util.regex.Pattern$Loop.match(Pattern.java:4785) at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717) at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568) at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777) at java.util.regex.Pattern$Branch.match(Pattern.java:4604) at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658) at java.util.regex.Pattern$Loop.match(Pattern.java:4785)

I'm trying to use :

const static char bla[] PROGMEM = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890012345678901234567890123456789012345678"; static char* blabla = F("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890012345678901234567890123456789012345678");

void setup() { // put your setup code here, to run once:

}

void loop() { // put your main code here, to run repeatedly:

}

None of this methods work, the maximum I can store is 919 letters.

I thought i have 32kb of space.

Please assist

Those Java errors usually mean that there is a typo somewhere that gets the parser confused. (Poor error checking by the IDE authors).

...R

The C language allows double-quoted string literals to be "concatenated" at compile time. There is only one NUL-terminator and the end of all the strings. A small example:

 Serial.
     println
       (
          "Hello "
             "world!"
       );

Your example would turn into something like this:

const static char bla[] PROGMEM = 
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
;

There is a limit in AVR-GCC, IIRC.

Cheers, /dev

Robin2: Those Java errors usually mean that there is a typo somewhere that gets the parser confused. (Poor error checking by the IDE authors).

...R

If you delete one number from the string it will compile. it is just a long string.

/dev Thanks, I'll try

Hi dev,

I did what you suggested, and it works.
but when i try to use :
Serial.write(bla, lengthofbla);

I get jibbrish

What are you trying to do? It seems extremely odd to have to put repetitive strings of 01234567890.... in progmem. I'm 99.9% sure there is a better way but without knowing what you're up to, it's impossible to know what it is.

Even if the numbers are just a demo, there's probably a better way.

tautau123: I get jibbrish

The macro to move the data from flash to RAM is missing.

tautau123: when i try to use :

    Serial.write(bla, lengthofbla);

I get jibbrish

THat's because you put the array in PROGMEM. The Harvard Architecture of an 8-bit AVR requires accessing the array with special CPU instructions, via the pgmspace.h, or with Print methods that use them.

In this case,

   Serial.print( (const __FlashStringHelper *) bla );

See Print.H and Print.CPP in the Arduino installation directory, under hardware/arduino/avr/cores/arduino or the hardware/arduino/cores/arduino subdirectory, depending on what version you have.

Cheers, /dev

tautau123:

(Poor error checking by the IDE authors).

If you delete one number from the string it will compile. it is just a long string.

Q.E.D

...R

aarg: What are you trying to do? It seems extremely odd to have to put repetitive strings of 01234567890.... in progmem. I'm 99.9% sure there is a better way but without knowing what you're up to, it's impossible to know what it is.

Even if the numbers are just a demo, there's probably a better way.

Of course I don't really have a repetitive strings of 01234567890, Actually I have a webpage that i try to show to the client by sending it through serial to the esp8266. It worked on small strings, but after I changed it to long one it stopped working.

/dev Thanks again, So lets say i don't want to print all the string but just the first 255 bytes. Can i do :

char buffer[256]; memcpy(buffer, (const __FlashStringHelper *) bla, 255); buffer[255] = 0; Serial.print(buffer);

Eventually I want to print it by chunks (for debug purposes) because later I'll send it to the esp8266 by chucks through SerialSoftware.

Thanks

I thought so. Why is it imperative that you send it all as one chunk? The http protocol is extremely forgiving in regard to delays in transmission. Wouldn't it be a lot simpler, and easier to maintain, if you send it in sections (paragraphs)?

aarg:
I thought so. Why is it imperative that you send it all as one chunk? The http protocol is extremely forgiving in regard to delays in transmission. Wouldn’t it be a lot simpler, and easier to maintain, if you send it in sections (paragraphs)?

I tried,
The esp8266 returned an error and said too long.

The esp8266 returned an error and said too long.

The code you didn't post? How do you expect us to help you with no code, and no idea what the error message was?

tautau123: I thought i have 32kb of space.

yes, you have 32KB.

But when initializing a string==> First double quote is begin of string and second double quote is end of string. And all the bullshit following after the end of the string like "static char* blabla = ..

is just bullshit following after a defined string.

PaulS: The code you didn't post? How do you expect us to help you with no code, and no idea what the error message was?

I didn't expect you the help with the code i didn't post. Only with the code i did.

And /Dev did help. So everything is great

Generally when someone asks a question it is not polite to post all the code and say "i have problem, where it is". The right thing to do is find where exactly the problem and post only the relevant piece. And for me the relevant piece was to read from the char[] correctly.

tautau123: I didn't expect you the help with the code i didn't post. Only with the code i did.

And /Dev did help. So everything is great

Generally when someone asks a question it is not polite to post all the code and say "i have problem, where it is". The right thing to do is find where exactly the problem and post only the relevant piece. And for me the relevant piece was to read from the char[] correctly.

If you hang around the forum longer, you will see that the error is at least as often in the code that people don't post, as the code that they do. Nothing personal, its a numbers thing.

tautau123:
So lets say i don’t want to print all the string but just the first 255 bytes. Can i do :

char buffer[256];

memcpy(buffer, (const __FlashStringHelper *) bla, 255);
buffer[255] = 0;
Serial.print(buffer);



Eventually I want to print it by chunks (for debug purposes)

No, don’t do that. Using a big RAM buffer kinda defeats the purpose of putting it in PROGMEM. Either declare and print it in chunks:

const char chunk1[] PROGMEM = "1111..."
  "11111...."
  "111111...";

const char chunk2[] PROGMEM = "222..."
  "2222...."
  "22222..";

void foo()
{
  Serial.print( chunk1 );
  Serial.print( chunk2 );

… or do like Print( const __FlashStringHelper *ifsh ) does:

const char allOfIt[] PROGMEM = "0123456..."
int totalPrinted = 0;

void foo()
{
  const char PROGMEM *p = (const char PROGMEM *) &allOfIt[ totalPrinted ];
  int i;

  for (i = 0; i<256; i++) {
    unsigned char c = pgm_read_byte(p++);
    if (c == 0) break;
    write(c);
  }
  totalPrinted += i;
}

Did you look at Print.CPP?

because later I’ll send it to the esp8266 by chucks through SerialSoftware.

Then I’ll also suggest NeoSWSerial. It’s much more efficient than SoftwareSerial, and it can transmit and receive at the same time. It only works at bauds 9600, 19200 and 38400, though.

If pins 8 & 9 are available, AltSoftSerial would be even better.

Cheers,
/dev

aarg: If you hang around the forum longer, you will see that the error is at least as often in the code that people don't post, as the code that they do.

Truth.