TFT_eSPI esp8266 Weird problem with displaying 2D array content.

Hi!
The code below IS working right until I uncomment “fillCircle” at the end.
This program loads content from files named f00, f01, etc. File is just a one line with 1200 numbers.
As is (commented) files being loaded one by one into array and printed serially. Everything is good.

Once I uncomment circle drawings it works right only for the first file (f00).
It draws a nice array of colorful circles until it comes to the second file!
From file f01 and on returns “tft.println(F(” file not found"));"
Even more, the program stops seeing files as I modify a single line to the simplest dealing with the TFT:

if (theArray[y][x] == 0) Serial.print ("0"), tft.print("a");

Even morer! :slight_smile:
Enough to place tft.fillScreen(TFT_BLACK); after file.close(); and it stops loading next files too!

Im running mad :frowning:
Thanks for any help.

#include <TFT_eSPI.h>
#include <SPI.h>
#include "SdFat.h"
TFT_eSPI tft = TFT_eSPI();

SdFat sd;
File file;

unsigned int theArray[30][40];
int x, y, filenum = 0;
char fileName[8];

void setup() {
  delay(2000);
  tft.init();
  tft.setTextSize(1);
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);
  Serial.begin(115200);
  sd.begin(D2);
}

void loop() {
  snprintf (fileName, sizeof(fileName), "f%02d", filenum);  //1200 bytes
  Serial.println(fileName);
  file = sd.open(fileName, O_READ);
  if (sd.exists(fileName)) Serial.println ("prsnt");
  if (!sd.exists(fileName)) Serial.println ("absnt");

  if (file) {    ///////////////////////////// load array from file /////////////////////////////
    Serial.println(file.fileSize());
    //  tft.fillScreen(TFT_BLACK);

    for (y = 0; y < 30; y++)  {
      for (x = 0; x < 40; x++) {
        int readd = file.read();
        if (readd == 48) theArray[y][x] = 0;
        if (readd == 49) theArray[y][x] = 1;
        if (readd == 50) theArray[y][x] = 2;
        if (readd == 56) theArray[y][x] = 8;
        if (readd == 52) theArray[y][x] = 4;
        if (readd == 51) theArray[y][x] = 3;
      }
    }
    file.close();
// tft.fillScreen(TFT_BLACK);
  }

  else {
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(100, 15);
    tft.print(fileName);
    tft.println(F(" file not found"));
    delay(3000);
  }
  ////////////////////////////////////// now print array content  /////////////////////////
  for (y = 0; y < 30; y++)  {
    for (x = 0; x < 40; x++) {
      if (theArray[y][x] == 0) Serial.print ("0");//, tft.fillCircle(x * 8, y * 8, 3, TFT_YELLOW);
      if (theArray[y][x] == 1) Serial.print ("1");//, tft.fillCircle(x * 8, y * 8, 3, TFT_CYAN);
      if (theArray[y][x] == 2) Serial.print ("2");//, tft.fillCircle(x * 8, y * 8, 3, TFT_GREEN);
      if (theArray[y][x] == 8) Serial.print ("8");//, tft.fillCircle(x * 8, y * 8, 3, TFT_RED);
      if (theArray[y][x] == 4) Serial.print ("4");//, tft.fillCircle(x * 8, y * 8, 3, TFT_BLUE);
      if (theArray[y][x] == 3) Serial.print ("3");//, tft.fillCircle(x * 8, y * 8, 3, TFT_WHITE);
    }
    Serial.println();
  }
  delay(10000);
  filenum++;
}

Here is much simpler example:

#include <TFT_eSPI.h>
#include <SPI.h>
#include "SdFat.h"
TFT_eSPI tft = TFT_eSPI();

SdFat sd;
File file;

int filenum = 0;

void setup() {
  Serial.begin(115200);
  tft.init();
  tft.fillScreen(TFT_BLACK);
  tft.println("Start! ");
  sd.begin(D2);
}

void loop() {
  if (filenum == 0) file = sd.open("f00", O_READ);
  if (filenum == 1) file = sd.open("f01", O_READ);
  if (filenum == 2) file = sd.open("f02", O_READ);
  if (filenum == 3) file = sd.open("f03", O_READ);
  if (filenum == 4) file = sd.open("f04", O_READ);
  if (filenum == 5) file = sd.open("f05", O_READ);

  if (file) {
    //tft.print("FileOK  ");
    Serial.println("FileOK  ");
  }

  else {
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(100, 15);
    tft.print(filenum);
    tft.println(" file not found");
    delay(1000);
  }
  
  //tft.println(filenum);
  Serial.println(filenum);

  delay(3000);
  filenum++;
}

Works until I uncomment any of commented “tft.print” lines. Just stops load the next file with “file not found” on the TFT :frowning:

Look at the SdFat documentation.
I doubt if it supports six open files.

Design your program. e.g. by putting your brain into gear.

Can you manage with a smaller number of open files?

David.

Sorry, forgot to insert "file.close();" at the end. In the original post above it presents.
Anyway I open files one by one only and the second example just works good "as is" with tft.print commented out.
The problem begins once uncoment any interaction with the TFT only.

THIS opens three files in a row as should:

void loop() {
  if (filenum == 0) file = sd.open("f00", O_READ);
  if (filenum == 1) file = sd.open("f01", O_READ);
  if (filenum == 2) file = sd.open("f02", O_READ);

  if (file) {
    Serial.println("FileOK  ");
  }

  else {
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(100, 15);
    tft.print(filenum);
    tft.println(" file not found");
    delay(1000);
  }

  //tft.println(filenum);
  Serial.println(filenum);

  file.close();
  delay(3000);
  filenum++;
}

And THIS falls after the first file:

void loop() {
  if (filenum == 0) file = sd.open("f00", O_READ);
  if (filenum == 1) file = sd.open("f01", O_READ);
  if (filenum == 2) file = sd.open("f02", O_READ);

  if (file) {
    Serial.println("FileOK  ");
  }

  else {
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(100, 15);
    tft.print(filenum);
    tft.println(" file not found");
    delay(1000);
  }

  tft.println(filenum);
  Serial.println(filenum);

  file.close();
  delay(3000);
  filenum++;
}

tft.println(filenum); is only difference.

Ok, found the problem.

Have to enable "#define SUPPORT_TRANSACTIONS" in User_Setup.h of TFT_eSPI lib.

if you have nothing to say its better to shut up :slight_smile:

Sziklai:
Ok, found the problem.

Have to enable "#define SUPPORT_TRANSACTIONS" in User_Setup.h of TFT_eSPI lib.

if you have nothing to say its better to shut up :slight_smile:

Time for you to finally read General Guidance and How to use the Forum

And practice some politeness!