Problems with keypad

Hi

I am having problems with the keypad calling a function, what it should do is when I press the A key on the keypad call ReadFile2
This calls the function ok but dose not seem to call the getValue Function in the ReadFile2 function more than 3 times, If I do another call no data is displayed using the Serial.print

When I call the ReadFile2 function from setup it works ok it displays all text but not when I click the keypad button unless I only call getValue 3 times in the ReadFile2 function

The ReadFile2 function reads a CSV text file from the SD card which works ok, then I call getValue for each value I want out of the CSV file

It seems to work when I reduce the text in the file from "1234,This is a test col,123,123,123,4,4" to "1234,This is a test,123,123,123,4,4"

Any help would be appreciated thanks

void loop() {
   char key = keypad.getKey();
 
}


void keypadEvent(KeypadEvent key){
    switch (keypad.getState()){
    case PRESSED:

  if (key == 'A'){
	
 ReadFile2();

break;
  

  }

  }
}


void ReadFile2() {


char character;
int index = 0;
//AllText = "";

 if (SD.exists("00.txt")) {
 myFile = SD.open("00.txt", O_READ);
 
  while( (character = myFile.read()) != -1) {
   
   AllText[index] = (char)character;
 index +=1;
 
  }

 myFile.close();
 
// This works ok
  getValue(AllText, ',', 0).toCharArray(DMCCode, DMCCodeLen);
 
 getValue(AllText, ',', 1).toCharArray(DMColText, DMColTextLen);

getValue(AllText, ',', 2).toCharArray(CRGBR, CRGBRLen);

////////////////////////////////////////////////////////////////////////

/////// Add in another and it breaks  but works ok calling ReadFile2 from setup
//getValue(AllText, ',', 3).toCharArray(CRGBG, CRGBGLen);

// AllText works 
Serial.print(AllText); // 352,RED,253,156,151,0,3 
Serial.print("   ");
/////////////////////////////////////////////////////////
// Dose not work if more than 3
Serial.print(DMCCode);
Serial.print("  ");
Serial.print(DMColText);
Serial.print("  ");
Serial.print(CRGBR);

//Serial.print("  ");
//Serial.print(CRGBG);


 }else{
 tft.fillScreen(ILI9341_BLACK);
 tft.setTextColor(ILI9341_WHITE); 
  tft.setTextSize(TextSize);
tft.setCursor(0, 0);
tft.println("File Does Not Exists.");
 }


}


String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}


Don’t use keypadEvent, just do your actions in the loop

1 Like

Thanks for the reply

The variables are below, I did as J-M-L said also I added the the variables in the function, they were Global and it worked better plus I only use them in the function, but when I make any of the variables bigger like char AllText[85]; it breaks again seems like the values below are the max I can do.

If I make any of them bigger then it does not display all the text, the below variables Values show
"12345 Moss Red Medium Light Red Blue 234 255 225 12345 99" but if I make the variables bigger I get "12345 234 255 225 12345 99" or if I make the text longer in the file like "Moss Red Medium Light Red Blue Pink" it breaks even thought the variable that holds this data is big enough

char AllText[80];
char DMColText[40];
byte DMColTextLen = 40;
//String DMColText = "";

char DMCCode[6];
byte DMCCodeLen = 6;
char CRGBR[4];
byte CRGBRLen = 4;
char CRGBG[4];
byte CRGBGLen = 4;
char CRGBB[4];
byte CRGBBLen = 4;
char Anchor[8];
byte AnchorLen = 6;
char NumOwned[3];
byte NumOwnedLen = 3;

Sketch uses 24684 bytes (76%) of program storage space. Maximum is 32256 bytes.
Global variables use 1470 bytes (71%) of dynamic memory, leaving 578 bytes for local variables. Maximum is 2048 bytes. I am using the UNO

post the new full code, I'm not sure I get what you are saying

1 Like

Sorry Below is the full New updated code
In the DMCDetailsPage function I am displaying the data to a tft screen But having the problems that I said above, even if I had another tft.setCursor(0, 46); tft.println("Number Owned: "); It breaks
Its like the variables have no data in them.

////#include "Adafruit_GFX.h"
////#include <SPI.h>
#include <Adafruit_ILI9341.h> // With a bit of SC card
#include <Keypad.h>
#include <SD.h>

#define TFT_CS   10
#define TFT_DC   9
#define TFT_RST   8

const int SD_CS = 2;

File myFile;


const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { A1, A2, A3, A4 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 7, 6, 5, 4 }; // Pins connected to R1, R2, R3, R4

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

byte wScreen = 0;
String FileDMCCode = "00";



Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC,TFT_RST);

#define TextSize 2



void setup(void) {

pinMode(TFT_CS, OUTPUT);
digitalWrite(TFT_CS, HIGH);

pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);

 //keypad.addEventListener(keypadEvent); // Add an event listener for this keypad

  ////////////////////////////////////////////////////////////////
  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE); 
  tft.setTextSize(TextSize);
  /////////////////////////////////////////////////////////////////




///////////////////////////////////////////////////////
 Serial.begin(9600);

while (!Serial);

  Serial.print("Initializing SD card...");

 
//////////// IN SETUP() NEED ADD ///////////////////////////////////////////////////////////////////////////
 if (!SD.begin(SD_CS)) {

    Serial.println("No SD Card Found!");
	
	tft.setTextColor(ILI9341_WHITE); 
  tft.setTextSize(TextSize);
  
tft.setCursor(0, 0);
 
tft.println("No SD Card Found!");

    while (1);

  }
  
  ////////////////////////////////////////////////////////////////////////////////////////
  

  Serial.println("initialization done.");
  
  //////////////////////////////////////////////////////////////////////////////////////////
}

void ReadFile(String fDMCCode) {

char AllText[80]; // > 70
char DMColText[40];
byte DMColTextLen = 40;
//String DMColText = "";

char DMCCode[6];
byte DMCCodeLen = 6;
char CRGBR[4];
byte CRGBRLen = 4;
char CRGBG[4];
byte CRGBGLen = 4;
char CRGBB[4];
byte CRGBBLen = 4;
char Anchor[8];
byte AnchorLen = 6;
char NumOwned[3];
byte NumOwnedLen = 3;


char character;
 int index = 0;

  if (SD.exists(fDMCCode + ".txt")) {
    
  myFile = SD.open(fDMCCode + ".txt", FILE_READ);
 char character;
  while( (character = myFile.read()) != -1) {
   
AllText[index] = (char)character;
 index +=1;

  }

  myFile.close();

memset(character, 0, sizeof(character));
index = 0;


getValue(AllText, ',', 0).toCharArray(DMCCode, DMCCodeLen);
//DMColTextLen = getValue(AllText, ',', 1).length();
//DMColText = getValue(AllText, ',', 1);
getValue(AllText, ',', 1).toCharArray(DMColText, DMColTextLen);
getValue(AllText, ',', 2).toCharArray(CRGBR, CRGBRLen);
getValue(AllText, ',', 3).toCharArray(CRGBG, CRGBGLen);
getValue(AllText, ',', 4).toCharArray(CRGBB, CRGBBLen);
getValue(AllText, ',', 5).toCharArray(Anchor, AnchorLen);
getValue(AllText, ',', 6).toCharArray(NumOwned, NumOwnedLen);


DMCDetailsPage(DMCCode,NumOwned, DMColText,CRGBR, CRGBG, CRGBB,Anchor);


memset(character, 0, sizeof(character));
memset(AllText, 0, sizeof(AllText));
memset(DMColText, 0, sizeof(DMColText));
memset(DMCCode, 0, sizeof(DMCCode));
memset(CRGBR, 0, sizeof(CRGBR));
memset(CRGBG, 0, sizeof(CRGBG));
memset(CRGBB, 0, sizeof(CRGBB));
memset(Anchor, 0, sizeof(Anchor));
memset(NumOwned, 0, sizeof(NumOwned));

index = 0;

  }else{
wScreen = 5;
 Serial.println(fDMCCode + " Does Not Exists.");
 
 tft.setTextColor(ILI9341_WHITE); 
  tft.setTextSize(TextSize);
  
tft.setCursor(0, 0);
 
tft.println(fDMCCode + " Does Not Exists.");

tft.setCursor(0, 50);
 
tft.println("Press B for Search");

tft.setCursor(0, 100);
 
tft.println("Press D for Menu");

} 

}

////////////////////////////////////////////////////////////////////////////////////////////////////


void loop() {
  
  char key = keypad.getKey();


   
    
  if (key == 'A'){

 ReadFile(FileDMCCode);


  }
 
}


void DMCDetailsPage(char cDMCCode[6],char cNumOwned[3], char cDMColText[40],String R, char G[4], char B[4],char cAnchor[6]){

if (strstr(cDMCCode, "310"))
{
 tft.fillScreen(0x484848);
 Serial.print("True");
Serial.print("  ");

}else{
 tft.fillScreen(ILI9341_BLACK);
 Serial.print("False");
Serial.print("  ");
}


tft.setTextColor(ILI9341_WHITE); 
  tft.setTextSize(TextSize);

//            X  Y
tft.setCursor(0, 10);
 
tft.println("DMC Code: ");

tft.setCursor(110, 10);
 
tft.println(cDMCCode); // Works if variables are not changed 


tft.setCursor(0, 46);
tft.println("Number Owned: "); // breaks if this is added

//tft.setCursor(150, 46);
//tft.println(cNumOwned);



Serial.print(cDMCCode);

Serial.print("  ");
Serial.print(cDMColText);
Serial.print("  ");
Serial.print(R);

Serial.print("  ");
Serial.print(G);

Serial.print("  ");
Serial.print(B);
Serial.print("  ");
Serial.print(cAnchor);
Serial.print("  ");
Serial.print(cNumOwned);

FileDMCCode = "01";


}




///////////////////////////////////////////////////////////////////////////////
  
String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

////////////////////////////////////////////////////////////////////////////////////////

this is incorrect

    memset(character, 0, sizeof(character));

character is not an array but just a char variable, so you need to pass its address to memset

   memset(&character, 0, sizeof character);

but since it's only 1 byte, it's probably easier to do

character = '\0';

as a side note you also have an issue there

    tft.fillScreen(0x484848);

the fillScreen function only takes an uint16_t for the color (5-6-5 Color definition)


extra side note:

Usually we don't duplicate the 6. either you go

  char DMCCode[6];
  byte DMCCodeLen = 6;
  const byte DMCCodeLen = 6;
  char DMCCode[DMCCodeLen];

or

  char DMCCode[6];
  const byte DMCCodeLen = sizeof DMCCode / sizeof *DMCCode;
1 Like

I will never read that code until it's formatted in a more standard way. The randomly placed parentheses and blank lines just give me a headache.

Please delete the superfluous blank lines, auto format with ctrl-T in the IDE, and re-post in a new message.

1 Like

Thank you J-M-L I will make the changes

Thanks for looking aarg, is the code better formatted


////#include "Adafruit_GFX.h"
////#include <SPI.h>
#include <Adafruit_ILI9341.h>  // With a bit of SC card
#include <Keypad.h>
#include <SD.h>

#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8

const int SD_CS = 2;
File myFile;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { A1, A2, A3, A4 };  // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 7, 6, 5, 4 };      // Pins connected to R1, R2, R3, R4

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

byte wScreen = 0;
String FileDMCCode = "00";
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

#define TextSize 2

void setup(void) {
  pinMode(TFT_CS, OUTPUT);
  digitalWrite(TFT_CS, HIGH);
  pinMode(SD_CS, OUTPUT);
  digitalWrite(SD_CS, HIGH);
  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(TextSize);
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("No SD Card Found!");
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(TextSize);
    tft.setCursor(0, 0);
    tft.println("No SD Card Found!");

    while (1)
      ;
  }

  Serial.println("initialization done.");
}

void ReadFile(String fDMCCode) {

  char AllText[80];  // > 70
  char DMColText[40];
  const byte DMColTextLen = sizeof DMColText / sizeof *DMColText;
  char DMCCode[6];
  const byte DMCCodeLen = sizeof DMCCode / sizeof *DMCCode;
  char CRGBR[4];
  const byte CRGBRLen = sizeof CRGBR / sizeof *CRGBR;
  char CRGBG[4];
  const byte CRGBGLen = sizeof CRGBG / sizeof *CRGBG;
  char CRGBB[4];
  const byte CRGBBLen = sizeof CRGBB / sizeof *CRGBB;
  char Anchor[8];
  const byte AnchorLen = sizeof Anchor / sizeof *Anchor;
  char NumOwned[3];
  const byte NumOwnedLen = sizeof NumOwned / sizeof *NumOwned;
  char character;
  int index = 0;

  if (SD.exists(fDMCCode + ".txt")) {

    myFile = SD.open(fDMCCode + ".txt", FILE_READ);
    char character;
    while ((character = myFile.read()) != -1) {
      AllText[index] = (char)character;
      index += 1;
    }
    myFile.close();
    index = 0;
    getValue(AllText, ',', 0).toCharArray(DMCCode, DMCCodeLen);
    getValue(AllText, ',', 1).toCharArray(DMColText, DMColTextLen);
    getValue(AllText, ',', 2).toCharArray(CRGBR, CRGBRLen);
    getValue(AllText, ',', 3).toCharArray(CRGBG, CRGBGLen);
    getValue(AllText, ',', 4).toCharArray(CRGBB, CRGBBLen);
    getValue(AllText, ',', 5).toCharArray(Anchor, AnchorLen);
    getValue(AllText, ',', 6).toCharArray(NumOwned, NumOwnedLen);

    DMCDetailsPage(DMCCode, NumOwned, DMColText, CRGBR, CRGBG, CRGBB, Anchor);

    character = '\0';
    memset(AllText, 0, sizeof(AllText));
    memset(DMColText, 0, sizeof(DMColText));
    memset(DMCCode, 0, sizeof(DMCCode));
    memset(CRGBR, 0, sizeof(CRGBR));
    memset(CRGBG, 0, sizeof(CRGBG));
    memset(CRGBB, 0, sizeof(CRGBB));
    memset(Anchor, 0, sizeof(Anchor));
    memset(NumOwned, 0, sizeof(NumOwned));

    index = 0;

  } else {
    wScreen = 5;
    Serial.println(fDMCCode + " Does Not Exists.");

    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(TextSize);
    tft.setCursor(0, 0);
    tft.println(fDMCCode + " Does Not Exists.");
    tft.setCursor(0, 50);
    tft.println("Press B for Search");
    tft.setCursor(0, 100);
    tft.println("Press D for Menu");
  }
}

void loop() {
  char key = keypad.getKey();
  if (key == 'A') {
    ReadFile(FileDMCCode);
  }
}

void DMCDetailsPage(char cDMCCode[6], char cNumOwned[3], char cDMColText[40], String R, char G[4], char B[4], char cAnchor[6]) {

  if (strstr(cDMCCode, "310")) {
    tft.fillScreen(0x484848);
    Serial.print("True");
    Serial.print("  ");
  } else {
    tft.fillScreen(ILI9341_BLACK);
    Serial.print("False");
    Serial.print("  ");
  }

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(TextSize);
  //            X  Y
  tft.setCursor(0, 10);
  tft.println("DMC Code: ");
  tft.setCursor(110, 10);
  tft.println(cDMCCode);
  tft.setCursor(0, 46);
  tft.println("Number Owned: ");  // breaks if this is added
  //tft.setCursor(150, 46);
  //tft.println(cNumOwned);
  Serial.print(cDMCCode);
  Serial.print("  ");
  Serial.print(cDMColText);
  Serial.print("  ");
  Serial.print(R);
  Serial.print("  ");
  Serial.print(G);
  Serial.print("  ");
  Serial.print(B);
  Serial.print("  ");
  Serial.print(cAnchor);
  Serial.print("  ");
  Serial.print(cNumOwned);
  FileDMCCode = "01";
}

String getValue(String data, char separator, int index) {
  int found = 0;
  int strIndex[] = { 0, -1 };
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

Your code takes a lot of unnecessary conversion steps when handling input. You probably don't need over half of that code.

Hi Delta_G

Yes thats what I was thinking, I have changed the FileName variable to a char array instead of String so only got one String in the programme now and that's in the getValue function which I found on the web and don't know how to change it to char array.

I will give up with it, if it is the Memory, as I have only written 1/2 the code so not chance of working if I write more.

This is the Updated code which seems to run out of Memory and dose not display all the data


////#include "Adafruit_GFX.h"
////#include <SPI.h>
#include <Adafruit_ILI9341.h>  // With a bit of SC card
#include <Keypad.h>
#include <SD.h>

#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8

const int SD_CS = 2;
File myFile;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

uint8_t colPins[COLS] = { A1, A2, A3, A4 };  // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 7, 6, 5, 4 };      // Pins connected to R1, R2, R3, R4

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

byte wScreen = 0;
char FileDMCCode[11];

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

#define TextSize 2

void setup(void) {
  pinMode(TFT_CS, OUTPUT);
  digitalWrite(TFT_CS, HIGH);
  pinMode(SD_CS, OUTPUT);
  digitalWrite(SD_CS, HIGH);
  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(TextSize);
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("No SD Card Found!");
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(TextSize);
    tft.setCursor(0, 0);
    tft.println("No SD Card Found!");

    while (1)
      ;
  }

  Serial.println("initialization done.");

  strncpy(FileDMCCode, "00.txt", 11);
}

void ReadFile(char fDMCCode[11]) {

  char AllText[80];  // > 70
  char DMColText[40];
  const byte DMColTextLen = sizeof DMColText / sizeof *DMColText;
  char DMCCode[6];
  const byte DMCCodeLen = sizeof DMCCode / sizeof *DMCCode;
  char CRGBR[4];
  const byte CRGBRLen = sizeof CRGBR / sizeof *CRGBR;
  char CRGBG[4];
  const byte CRGBGLen = sizeof CRGBG / sizeof *CRGBG;
  char CRGBB[4];
  const byte CRGBBLen = sizeof CRGBB / sizeof *CRGBB;
  char Anchor[8];
  const byte AnchorLen = sizeof Anchor / sizeof *Anchor;
  char NumOwned[3];
  const byte NumOwnedLen = sizeof NumOwned / sizeof *NumOwned;
  char character;
  int index = 0;

  if (SD.exists(fDMCCode)) {

    myFile = SD.open(fDMCCode, FILE_READ);
    char character;
    while ((character = myFile.read()) != -1) {
      AllText[index] = (char)character;
      index += 1;
    }
    myFile.close();

    index = 0;

    getValue(AllText, ',', 0).toCharArray(DMCCode, DMCCodeLen);
    getValue(AllText, ',', 1).toCharArray(DMColText, DMColTextLen);
    getValue(AllText, ',', 2).toCharArray(CRGBR, CRGBRLen);
    getValue(AllText, ',', 3).toCharArray(CRGBG, CRGBGLen);
    getValue(AllText, ',', 4).toCharArray(CRGBB, CRGBBLen);
    getValue(AllText, ',', 5).toCharArray(Anchor, AnchorLen);
    getValue(AllText, ',', 6).toCharArray(NumOwned, NumOwnedLen);

    DMCDetailsPage(DMCCode, NumOwned, DMColText, CRGBR, CRGBG, CRGBB, Anchor);

    character = '\0';
    memset(AllText, 0, sizeof(AllText));
    memset(DMColText, 0, sizeof(DMColText));
    memset(DMCCode, 0, sizeof(DMCCode));
    memset(CRGBR, 0, sizeof(CRGBR));
    memset(CRGBG, 0, sizeof(CRGBG));
    memset(CRGBB, 0, sizeof(CRGBB));
    memset(Anchor, 0, sizeof(Anchor));
    memset(NumOwned, 0, sizeof(NumOwned));
    memset(FileDMCCode, 0, sizeof(FileDMCCode));
    index = 0;

  } else {
    tft.fillScreen(ILI9341_BLACK);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(TextSize);
    tft.setCursor(0, 0);
    tft.println("File Does Not Exists.");
    tft.setCursor(0, 50);
    tft.println("Press B for Search");
    tft.setCursor(0, 100);
    tft.println("Press D for Menu");
  }
}

void loop() {
  char key = keypad.getKey();
  if (key == 'A') {
    ReadFile(FileDMCCode);
  }
}

void DMCDetailsPage(char cDMCCode[6], char cNumOwned[3], char cDMColText[40], char R[4], char G[4], char B[4], char cAnchor[6]) {

  if (strstr(cDMCCode, "310")) {
    tft.fillScreen(ILI9341_BLUE);
    Serial.print("True");
    Serial.print("  ");
  } else {
    tft.fillScreen(ILI9341_BLACK);
    Serial.print("False");
    Serial.print("  ");
  }

  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(TextSize);
  //            X  Y
  tft.setCursor(0, 10);
  tft.println("DMC Code: ");
  tft.setCursor(110, 10);
  tft.println(cDMCCode);
  tft.setCursor(0, 56);
  // tft.println("Number Owned: ");  // breaks if this is added seems to run out of Memory
  //tft.setCursor(0, 76);
  //tft.println(cNumOwned);
}

String getValue(String data, char separator, int index) {
  int found = 0;
  int strIndex[] = { 0, -1 };
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

You will struggle, right out of the gate, with TFT and SD libraries in play. Both of those are notorious memory hogs. You really need a more capable processor.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.