File.read() always returns -1 I'm trying to print a txt file from an SD card to a SSD1306 using the u8x8 library.
Here's the current code:
#include &lt;SD.h&gt;

#include &lt;Arduino.h&gt;
#include &lt;U8x8lib.h&gt;

#ifdef U8X8_HAVE_HW_SPI
#include &lt;SPI.h&gt;
#endif
#ifdef U8X8_HAVE_HW_I2C
#include &lt;Wire.h&gt;
#endif

  U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);   

/*
  This example will probably not work with the SSD1606, because of the
  internal buffer swapping
*/
#define maxChar  128
#define rows 8
#define cols 16

File myFile;
int x = 0;
int y = 0;
char c;

void setup()
{
  /*Serial.begin(9600);
  Serial.print(&quot;Initializing SD... &quot;);
  if (!SD.begin(10)) {
    Serial.println(&quot;initialization failed!&quot;);
    while (1);
  }
  Serial.println(&quot;initialization done.&quot;);*/

  u8x8.begin();
  delay(500);
  u8x8.setFont(u8x8_font_amstrad_cpc_extended_f);

  myFile = SD.open(&quot;target.txt&quot;, FILE_READ);
  u8x8.clear();
  u8x8.print(&quot;ciao&quot;);
  u8x8.print(myFile.read());
  delay(2000);
  printNewSet();
}
void loop()
{
  
}

void printNewSet()
{
  u8x8.clear();
  x = 0;
  y = 0;
  while (myFile.available() &amp;&amp; y&lt;rows)
  {
    c = (char) myFile.read();
    if (c == '\n') c = 'a';
    u8x8.print(c);
    stepCoords();
  }
}

void stepCoords()
{
  x++;
  if (x &gt;= cols) newLine();
}
void newLine()
{
  u8x8.print('\n');
  x = 0;
  y++;
}

The function printNewSet() is supposed to print a batch of characters until either the file ends or the display limit is reached.
The file displayed correctly until i switched from while(myFile.available()) u8x8.print( (char) myFile.read()); to printNewSet(), at which point myFile.read() only returns -1 and myFile.available() is always false.
What is going wrong?
EDIT: While debugging i discovered that myFile fails to be initialized. Am I running out of memory?
I had accidentally commented out the SD initialization along with the serial initialization. After uncommenting it it works correctly