Skip to main content
added 30 characters in body
Source Link
SoreDakeNoKoto
  • 2.4k
  • 2
  • 14
  • 23

Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation, which is especially bad on a chip like the ATmega328 with little RAM and subsequently, cause weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop().

You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation on a chip like the ATmega328 with little RAM and subsequently, weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop().

You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation, which is especially bad on a chip like the ATmega328 with little RAM and subsequently cause weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop().

You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

added 215 characters in body
Source Link
SoreDakeNoKoto
  • 2.4k
  • 2
  • 14
  • 23

Since you haven't provided all of your code, I don't knowcan't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation on a chip like the ATmega328 with little RAM and subsequently, weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop(). 

You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

Since you haven't provided all of your code, I don't know exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation on a chip like the ATmega328 with little RAM and subsequently, weird issues like you're getting. You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation on a chip like the ATmega328 with little RAM and subsequently, weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop(). 

You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

Source Link
SoreDakeNoKoto
  • 2.4k
  • 2
  • 14
  • 23

Since you haven't provided all of your code, I don't know exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation on a chip like the ATmega328 with little RAM and subsequently, weird issues like you're getting. You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.