earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 boards
GNU Lesser General Public License v2.1
1.92k stars 402 forks source link

LittleFS file not opening on Pico #2143

Closed DawDavis closed 3 months ago

DawDavis commented 3 months ago

Hi, I'm using this program in Arduino IDE against a KB2040 from Adafruit. I cannot for the life of me seem to get the LittleFS file system to initialize a new file this way. Is this expected behavior? or what further information should I provide to help diagnose whatever is happening?

I've retried using a bog-standard RPi Pico board, to the same result.

#include <LittleFS.h>

void setup() {
  delay(500);

  LittleFSConfig cfg;
  cfg.setAutoFormat(true);
  LittleFS.setConfig(cfg);
  LittleFS.begin();

  File f = LittleFS.open("f.txt", "w+");

  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }

  if (f.available() == false) {
    Serial.println("file not available.");
  } else {
    Serial.println("OK");
  }

  f.close();
}

void loop() {
  delay(100);
}

Also, is there a minimal known good example .ino file to test LittleFS against? I'd love to verify it's not just my code.

earlephilhower commented 3 months ago

Set a filesystem size in the Tools->Flash Size menu or you can't use a filesystem. The LittleFS->Speedtest.ino example can be used to verify.

earlephilhower commented 3 months ago

Err, and available() returns the bytes available to read, not if a file exists. Same as Serial or other Streams

DawDavis commented 3 months ago

Thanks! That was my issue is relying on the available and simply not RTFMing it. BTW Great library - really has been making development so easy.