String array causing problems

I am trying to figure out if there is something wrong with this statement in a UNO program.

String SMTPCommands[] PROGMEM = { "EHLO" };

The problem is when I add just one more string to the array the program will not work. Either it stalls out, which I have seen before when memory is depleted, or it will not make a TCP connection. In fact, even if the additional strings are not used, the program will not work.

I am not even sure where to look any more. When the program compiles it shows

Binary sketch size: 17,054 bytes (used 53% of a 32,256 byte maximum) (3.08 secs)
Minimum Memory Usage: 973 bytes (48% of a 2048 byte maximum)

.

I have gotten to the point where I can literally add one more string to SMTPCommands and the program will not work. Then, after removing that additional string, it will work.

I want to use the array for a larger purpose. The current work / not work process is for debugging before moving on.

Thanks.

What do you mean by "...the program will not work"? It doesn't compile, it doesn't execute, it doesn't meet your expectations?

You have only shown a code snippet. Snippets are generally frowned upon.

You have used String. String is generally frowned upon in the limited memory environment of an Arduino Uno.

You did not show us how you added "...just one more string to the array..." Usually, if 'A' works and 'B' doesn't. it is a really good idea to show both 'A' and 'B'.

This line compiles for me, but so does

const char * SMTPCommands[] PROGMEM = { "EHLO" };

vaj4088,

Thanks for your reply.

By "not work" I mean that the executable code does not meet my expectations. Specifically, when I change,

String SMTPCommands[] PROGMEM = { "EHLO" };

to,

String SMTPCommands[] PROGMEM = { "EHLO", "auth login" };

the executing code will not make a TCP connection even though the added item has nothing to do with making the TCP connection.

Since my original post I did read at,

https://www.arduino.cc/en/Reference/PROGMEM

that when the reserved word PROGMEN was used it has to be with the const modifier. Further, if the declaration / definition is not global, the static modifier need be included. My declaration is part of a function, not globally defined. So now I have,

const static String SMTPCommands[] PROGMEM = { "EHLO" };

which works, but,

const static String SMTPCommands[] PROGMEM = { "EHLO", "auth login" };

does not work.

You said,

You have used String. String is generally frowned upon in the limited memory environment of an Arduino Uno.

I was not aware of that recommendation. I am using a String since I am using files which I did not write which have functions wherein the parameters are Strings.

I appreciate you taking the time.

vaj4088,

Based on your note concerning using the String class, and a bit more reading, I tried,

const static char * const SMTPCommands[] PROGMEM = { "EHLO", "auth login" };

which did work.

Do I correctly gather that if a statement using PROGMEN is not properly formatted, as I had done originally, that it causes some problems in the UNO?

I'd like to understand this so I don't repeat my mistake.

Thanks.

Do I correctly gather that if a statement using PROGMEN is not properly formatted, as I had done originally, that it causes some problems in the UNO?

No. You have to understand what is, and what is NOT, put in PROGMEM. Putting the String instance (a pointer) in PROGMEM, while the string that it points to is in SRAM was a complete waste of time.

PaulS,

Is there a way to put both the pointer and the string it points to in flash memory?

Is there a way to put both the pointer and the string it points to in flash memory?

While the string is owned by the String object? No. PROGMEM is read-only. The ONLY reason for using String objects is to be able to manipulate, cluelessly, the string that it wraps.