Char array size filling up internal memory or communication error? [Solved]

We have a short program in the spark core and we are using a char array to display it in an lcd display.

char Str[60]

When we increase the size of the array, the core doesnt flash. It looks like there is a communication error and the core doesn´t see it is being flashed (USB). We think it is because of the small size of the internal memory.

I want to store the array variable in the external memory but i don’t know how, does anybody have a basic program showing how to use it please?? thax :smile:

@alic3, it is very difficult to help without seeing your code. :grinning:

// include the library code:

#include "LiquidCrystal.h"
  
  char Str[60]={"¿Como calificaria el servicio?"};
  int posicion = 0;
  LiquidCrystal *lcd;
  int acum=0;
  int letras;
  int busc_p = 0;
  int busc_l = 0; 
//------------------------------------
//Funcion principal
//------------------------------------
 
void setup() {
  lcd = new LiquidCrystal(D0, D1, D2, D3, D4, D5);
  lcd->begin(20,4);         
  letras = posicion;
  lcd->clear();
}
 
void loop() {
do{
    while(posicion < 20 && Str[letras] != '\0'){      
         if(Str[letras] == ' ')
        {
            busc_p = posicion + 1;
            busc_l = letras + 1;
            while(Str[busc_l] != ' '){
                busc_p++;
                busc_l++;
            }
            if (busc_p > 20)
            {
                posicion = 19;
            }
        }
        lcd->cursor();                       
        lcd->setCursor(posicion, acum);
        lcd->print(Str[letras]);           
        delay (100);                        
        posicion++;                     
        letras++; 
    }
  acum++;
  posicion = 0;  
} while(Str[letras] != '?');

 while(1){delay(50);}
}

@alic3, first I would say you should make Str[] 81 bytes in size which is the longest message (20x4) plus one terminator (\0) byte. Second, you don’t have any test for letras exceeding 80 - you should do a range check. Lastly, after your while(Str[letras] != '?'); finishes, you do while(1){delay(50);} which most likely stalls the background process so you will lose cloud connectivity. You should instead have:

while(1){SPARK_WLAN_Loop();}

:smiley:

is it the same if i’m just using usb connectivity?? i think i’m not using cloud connectivity

@alic3 unless you specifically use SYSTEM_MODE MANUAL or SEMI_AUTOMATIC, the Core will attempt to connect to the cloud. If it cannot, the user app will be blocked until it connects. if you don’t allow the background process to run the cloud will disconnect. Thus why I suggested the added code :smile:

I already added the code you told me but still the same problem :confused:

@alic3, I’ll burn your app on a Core and see what the issue might be :smile:

@alic3, I ran your code with the changes I suggested and included some Serial.print() debug messages to make sure the code was running completely. One oddity I found is that the “¿” character at the beginning of your text does NOT agree with the compiler and gets interpreted as 2 garbage chars in the first two positions of the char array! So removing that character, I ran the code with an array size of 81 (max chars + null) and had no problems.

I had no problems with flashing the Core OTA or via USB so I am not sure what you are experiencing. Exactly how are you trying to flash the code via USB?

1 Like

it works! thanks for your help :slight_smile:
we just limited acum variable to 4 which is the same as limiting letras variable to 81

1 Like

If you don’t mind, I’ll mark this as [solved] - OK?

1 Like