One String Array more and nothing works!

I have a problem, that I don´t understand.

My program works fine with 7 string arrays (26 elements).
If I add an 8th string array, nothing works,

My board is an Arduino 2560, the size of the program is 12,4 kB without the 8th array.
The 8th array ist defined exactly in the same mannor as the others.
The problem is the same, if I comment out another array, than it works fine with the new, but it will not work with 8 arrays.
Compilation without problems, data transfer without problems.

Do anyone have an idea, why it works no more with a further array?

Greetings

pjdi2

pjdi2:
I have a problem, that I don´t understand.

My program works fine with 7 string arrays (26 elements).
If I add an 8th string array, nothing works,

You don't want to confuse us with any details about the arrays and the code, don't you?

pjdi2:
Do anyone have an idea, why it works no more with a further array?

Without knowing details about arrays and code, I'd say: It's a code problem.

My board is an Arduino 2560, the size of the program is 12,4 kB without the 8th array.

I'm going to guess that adding another array makes very little difference to the size of the executable. It MIGHT make a huge difference to the amount of SRAM used. Or not.

int useless[0]; // This won't use much SRAM.

Thanks for reading my question!

To PaulS
its a difference between an integer with 2 Byte or an array of char

the statement is

PROGMEM char* Land={
“$gypten, Argentinien, Armenien, Australien”,
“Belgien, Birma, Bosnien, Brasilien, Bulgarien”,
“Chile, China, Costa Rica”,
“D{nemark, Deutschland, Dominikanische Republik”,
“Ecuador, Elfenbeink|ste, El Salvador, Eritrea, Estland”,
“Finnland, Frankreich”,
“Ghana, Griechenland, Grossbritannien”,
“Haiti, Honduras”,
“Indien, Indonesien, Italien, Irak, iran, Irland, Island, Israel”,
“Jordanien, Jamaika, Japan, Jemen”,
“Kamerun, Kanada, Kenia, Kongo, Kroatien, Kuba”,
“Laos, Lichtenstein, Luxemburg, Lybien”,
“Malta, Marokko, Mexiko, Moldawien, Mongolei”,
“Nepal, Neuseeland, Niederlande, Nigeria, Norwegen”,
“Oman, Oesterreich”,
“Pakistan, Panama, Peru, Polen, Portugal”,
“- kein Land mit Q -”,
“Ruanda, Rum{nien, Russland”,
“Sambia, Schweden, Schweiz, Slowakei, Somalia, Spanien, Syrien”,
“Taiwan, Thailand, Tansania, Togo, Tschechien, Tunesien, T|rkei”,
“Uganda, Ukraine, Ungarn, Uruguay”,
“Vatikan, Venezuela, Vietnam”,
“Weissrussland, Westsahara”,
“- kein Land mit X -”,
“- kein Land mit Y -”,
“Zypern”};

All other arrays are similar sized. It makes no difference to do in with “PROGMEM” or without.

The arrays are called like

Land[randNumber] // with ranNumber is randomly a value between 0 and 25

With 7 arrays it works fine. Without changing anything in the program, only defining an 8th array like above, program doesn´t do anything.

Greetings

pjdi

Greetings

Those strings aren't in PROGMEM. Only the pointers to them are being put in PROGMEM. The strings themselves are being copied to SRAM. You're probably running out of that.

pjdi2:
the statement is

PROGMEM char* Land={
"$gypten, Argentinien, Armenien, Australien",
"Belgien, Birma, Bosnien, Brasilien, Bulgarien",
"Chile, China, Costa Rica",
"D{nemark, Deutschland, Dominikanische Republik",
"Ecuador, Elfenbeink|ste, El Salvador, Eritrea, Estland",
"Finnland, Frankreich",
"Ghana, Griechenland, Grossbritannien",
"Haiti, Honduras",
"Indien, Indonesien, Italien, Irak, iran, Irland, Island, Israel",
"Jordanien, Jamaika, Japan, Jemen",
"Kamerun, Kanada, Kenia, Kongo, Kroatien, Kuba",
"Laos, Lichtenstein, Luxemburg, Lybien",
"Malta, Marokko, Mexiko, Moldawien, Mongolei",
"Nepal, Neuseeland, Niederlande, Nigeria, Norwegen",
"Oman, Oesterreich",
"Pakistan, Panama, Peru, Polen, Portugal",
"- kein Land mit Q -",
"Ruanda, Rum{nien, Russland",
"Sambia, Schweden, Schweiz, Slowakei, Somalia, Spanien, Syrien",
"Taiwan, Thailand, Tansania, Togo, Tschechien, Tunesien, T|rkei",
"Uganda, Ukraine, Ungarn, Uruguay",
"Vatikan, Venezuela, Vietnam",
"Weissrussland, Westsahara",
"- kein Land mit X -",
"- kein Land mit Y -",
"Zypern"};

This is just an array of 26 char pointers in PROGMEM!

This means 26 * 2 Bytes = 52 Byte are used in PROGMEM!

All the strings itself will stay in the RAM memory when you declare it that way!

And your program on an Atmega2560 will crash if you try to use more than 8 KB total RAM.

Please read and understand "Data in Program Space"!

At the end of the page there is a chapter "Storing and Retrieving Strings in the Program Space" and you can learn how to put the string contents into PROGMEM and not only the string pointers.

To Delta_G

I have written, that the problem exist with or without PROGMEM.

It has nothing to do with it <<<

Greetings

Pjdi2

Jurs is correct, but I'm not sure moving the arrays to PROGMEM solves the problem. If all the arrays are similar in size, each array consumes about 625 bytes. Even 7 of them chews up 4375 bytes. If I remember correctly, you might not even know they don't all fit, because the PROGMEM pointer "wraps around" when it reaches the end of memory. I'm not sure, but I'd check it before writing the code.

@Delta_G

I have tried your tip and changed the code to

char* Beruf PROGMEM ={"text"};

it changes nothing!

with greetings

pjdi2

Thank you for your help.

I have read some more lines!

Now I have declared it like this

char stringFA PROGMEM = "stringa";
...

char stringFZ PROGMEM = "stringz";

and then declare the field as

PGM_P Fluss PROGMEM = {
stringFA,
...
stringFZ
};

Now Programm work but not for the above array in the form Fluss[randomnumber] - compiler says:
"invalid conversion from ´const prog_char´ to ´char"

How should I call this element now?

with Greetings

pjdi2

Keep reading that link that was provided earlier. It explains how to retrieve your strings. You may have to copy them temporarily into SRAM as you use them. There are several ways to get the job done, but as I know nothing of your project I couldn't begin to tell you which would be best for you.

pjdi2:
compiler says:
"invalid conversion from ´const prog_char´ to ´char"

How should I call this element now?

You always update to the newest compiler version, BETA state and all, but you are not interested at all, what are the features and changes in the new Arduino BETA version?

When using Arduino IDE BETA 1.5.7 and above, there is a new GCC compiler version with it.

This compiler accepts "PROGMEM" only in combination with "const".

So if you want declare PROGMEM strings in Flash memory and the string pointers being in flash memory as well, you finally have to declare a thing like:

const char* const Fluss[] PROGMEM = {...

All together:

const char stringFA[] PROGMEM = "stringa";

const char stringFZ[] PROGMEM = "stringz";


const char* const Fluss[] PROGMEM = {
  stringFA,
  stringFZ
};

void setup(){}
void loop(){}

I think this "const" requirement when using "PROGMEM" will stay in the future, even with Arduino 2.0 and above.

pjdi2:
compiler says:
"invalid conversion from ´const prog_char´ to ´char"

That would take care of the const part, but there's another part to the compaint the compiler has. It doesn't like the converstion of prog_char* into char*. That's why you would normally either have a buffer to read the sting into when you need it or use one of the _P versions of functions like memcpy_P or sprintf_P.

Print has been overloaded so it can take a __FlashStringHelper. If you know how those work you could do it that way with things involving print().

But again, we'd need to know about the rest of the code to get you going there.

Hallo,

many thanks to jurs and all for there help. I think, you helped me understand, how to match that problem.
My program works fine now.
I have here a simple little program for beginners to understand and lern, how to solve such problem. It is much the same as in the link above from jurs. I think, that is a good way to close this thread.

// it is very important, to include pgmspace.h
#include <avr/pgmspace.h>

const unsigned int BAUD_RATE=9600;

// defining some strings in the Programm Space

char string_1 PROGMEM = “String 1”;
char string_2 PROGMEM = “String 2”;
char string_3 PROGMEM = “String 3”;
char string_4 PROGMEM = “String 4”;
char string_5 PROGMEM = “String 5”;

// defining an Array of strings in Programm Space

PGM_P string_table PROGMEM =
{
string_1,
string_2,
string_3,
string_4,
string_5
};

void setup()
{
Serial.begin(BAUD_RATE);
};

void loop()
{
int i;

// defining a buffer long enough for a single string
char buffer[10];

// the test-program retrieve a value from the array

for (i=0; i<5; i++) {
Serial.println(i);

// Serial.println(string_table*); will not work because it adresses in RAM*

  • // so first copy the string to RAM in this case to buffer*
    strcpy_P(buffer, (PGM_P)pgm_read_word(&(string_table*)));
    _
    // then use buffer and get the string*_
    * Serial.println(buffer);*
    * delay(1000);*
    * };*
    };
    Greatings from Germany (excuse my bad english)

There is a mistake in my last posting (I don´t know, why the "" gone wild, but here is the correct part:
for (i=0; i<5; i++) {

  • Serial.println(i);*
    // Serial.println(string_table*); will not work because it adresses in RAM*
    * // so first copy the string to RAM in this case to buffer*
    strcpy_P(buffer, (PGM_P)pgm_read_word(&(string_table*)));
    _ // then use buffer and get the string*
    * Serial.println(buffer);
    delay(1000);
    };*
    Sorry for the wrong text
    pjdi_

Is there a Filter to the messages filtering rectangle brackets and there content.
in the second post, I have the same problem

behind string_table should follow (left bracket) i (right bracket)

Greatings

pjdi2

You don’t need a statement terminator, the semicolon, after the closing brace of a for loop:

or (i=0; i<5; i++) {
    Serial.println(i);
  //  Serial.println(string_table);   will not work because it adresses in RAM
  //  so first copy the string to RAM in this case to buffer
  strcpy_P(buffer, (PGM_P)pgm_read_word(&(string_table)));
  // then use buffer and get the string
  Serial.println(buffer);
  delay(1000);
  };                          // <--- Semicolon NOT needed

Also, you’ve made enough posts here to know how to properly post code. I would strongly suggest you read the two posts by Nick Gammon at the top of this Forum on guidelines for posting here. It will help us help you, and you will likely get more people interested in helping you.