Why a delay() make trouble to list filse from SD card while OLED is enabled

Hello everybody,

I have a very strange problem since I received my new PCB.

I am going to be clear as much as I can.

My project start and frist it initiate the SD card, then the OLD LCD screen. When it start reading a filed, he can not find it while the files really exist.

I inactivate the OLED and the file can be read. I activate the OLED and the file can not be read.

I also have a function which listthe content of my SD crad.

When I use that function, befor the of the OLED initialized, it list the content of my SD crad. When I use that function after my OLED initiation, it can NOT list the content of my SD card.

Then I debug by calling my function into different place of the OLED initialisation.
This appen at the begining of the setup() function but after Serial.begin(9600) and Wire.begin)

First I observed that when

Si.listingFile(NULL);
delay(200);
Si.listingFile(NULL);

listingFile(NULL) list the conent before and delay, but nor after a delay!!!!!!

Then I remove temprarely my delay, and I observed the same issue with a delay of delay(500).

I removed the delay(500) and the problem was solved.

As I may said befoee, if I unactive the OLED, I do not exepriement that issue.

So now, I may need some advise from you:

  1. When OLED is active why a delay() give issues to list the content of my SD card?
  2. Why when OLED is unactive, I do not experiment that issue?
  3. And finally, is a SD crad issue? a OLED issue? a timing issue????

What is really more anoying, the same code works on the previous version of my PCD!!!!

If you can help ,e to target my issuer, that would be great! And feel free to ask additionnal question as exemple of code (Ido not know what can I provide for now)

Many thank!
Pierre

Is OLED problem? Is a SD card problem?

You need to post your program.

A diagram showing how everything is connected would also be a good idea - a photo of a simple pencil drawing is best. See this Simple Image Guide

...R

I also observed

delay(1000);
Si.listingFile(NULL)

before the OLED is initilized, do not make the trouble. It rellay after the OLED begin

Hello
Let startwith this:

void setup() {
  Serial.begin(9600);
  delay(8000);         // Wait for the terminal IT DOES NOT MAKE TROUBLEE
Serial.println(F("\r\n******************************************")); 
  Serial.print(F("*             SMART IRRIGATION "));

if(!Si.begin()){ // Init SD
    while(1){
      Si.sprintln(F("Error: Si.begin()"),0);
      delay(1000);
    }
  }

  Si.sprintln(F("\r\nSETUP"), 0);
  Si.sprintln(F("==================="), 0);

  Wire.begin();

// THE PROBLEM START HERE

 // Starting OLED
  #if defined(OLED)

    #if defined (WATCHDOG)
      wtime = Watchdog.enable();
      Si.sprint(F("\r\nEnabling Watchdog for "),0);
      Si.sprint(wtime,0);
      Si.sprintln(F("ms"),0);
      Watchdog.reset();
    #endif

    Si.listFiles(NULL);
    
    // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
    //display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
    display.display();                          
    #if defined(DEBUG)
      Si.listFiles(NULL);
      Si.sprintln(F("Wait for Splash"),0);
      Si.listFiles(NULL); //OK
    #endif
    #if defined (WATCHDOG)
      Watchdog.disable();
    #endif
    Serial.println(F("DEBUG. ls2"));
    Si.listFiles(NULL);//KO
    
    //delay(2000); // Give a delay to display the Splash
    for(int f=0; f<8000; f++){
      
    }
    
    Serial.println(F("DEBUG. ls3"));
    Si.listFiles(NULL);//KO
    // Clear the buffer.
    display.clearDisplay();                     // Clear buffer

    display.fillRect(0, 0, display.width(), 10, INVERSE);
    display.display();
    display.setTextColor(BLACK);
    display.setCursor(1,1);
    display.print("Setup");
    display.display();
    display.setTextColor(WHITE);
    display.setCursor(0,16);
    
    int o_y = 10; 

    Serial.println(F("DEBUG. ls4"));
    Si.listFiles(NULL);
    
    Si.sprintln(F("[OK] OLED"),0);
    
    o_y = oledCursorY(o_y); // THAT CAUSE THE PROBLEM BECAUSE THERE IS A DELAY OF 500
    
    Serial.println(F("DEBUG. ls5"));
    Si.listFiles(NULL);
    display.setCursor(0,o_y);
    Serial.println(F("DEBUG. ls6"));
    Si.listFiles(NULL); // SD CONTENT IS LISTED
    display.print("[OK] OLED");
    Serial.println(F("DEBUG. ls7"));
    Si.listFiles(NULL);
    display.display();  // SD CONTENT IS LISTED
    
    Serial.println(F("DEBUG. ls8"));
    Si.listFiles(NULL); // SD CONTENT IS LISTED
    
  #else
    Si.sprintln(F("[NA] OLED"),0);
  #endif
  Si.sprintln(F("[OK] Wire"),0);
  #if defined(OLED)
    o_y = oledCursorY(o_y); // THAT CAUSE THE PROBLEM BECAUSE THERE IS A DELAY(500), THAT I REMOVED FOR NOW
    display.setCursor(0,o_y);
    display.print("[OK] Wire");
    display.display();
  #endif


[..code..]

}

Here is oledCursorY

int oledCursorY(int y)
{
  // delay(500); I temporarely comment is as a delay cause a problem whilelisting the SD content
  switch(y){
    case 0:
      y = 10;
      break;
    case 10:
      y = 20;
      break;
    case 20:
      y = 30;
      break;
    case 30:
      y = 40;
      break;
    case 40:
      y = 50;
      break;
    case 50:
      y =0;
      #if defined(OLED)
        delay(2000); // THAT MAKE AN ISSUE TO LIST THE CONTENT OF SD, I NEE TO COMMENT IT
        display.clearDisplay();
      #endif
      break;
    default:
      y=0;
      break;
  }
  return y;
}

And may this can be interresting. I am using the adafruit library

#if defined(OLED)
  #include <Adafruit_GFX.h>           // OLED
  #include <Adafruit_SSD1306.h>       // OLED
  #define SCREEN_WIDTH 128 // OLED display width, in pixels
  #define SCREEN_HEIGHT 64 // OLED display height, in pixels

  // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  #define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
  
  const int oledDisplayFor = 15000;  // Time to display the LCD  after pressing the button in sleep mode
  int oledDisplayCount = 0;
#endif

but my OLD come from ebay

Please slow down.

Just post one complete program that illustrates the problem and explain in as much detail as you can how the problem manifests itself when you run that program.

...R