I have trouble creating or writing to files on my pico and rp2040. i am able to start littleFS and read files i uploaded but when i try to create or write to exiting files, it wont work.
my platformio.ini
[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
upload_protocol = picotool
upload_port = D:
lib_archive = no
board_build.filesystem_size = 0.2m
build_flags =
-D USE_TINYUSB
Here is sample code that complies fine and if I have an existing file it reads it fine but it wont work for creating / writing to files. I tried w+ mode, different file names, directories also and same issue.
I get: Problem on create file!
Any ideas?
// LittleFS.remove(F("/testCreate.txt"));
File testFile = LittleFS.open(F("/testCreate.txt"), "w");
if (testFile){
Serial.println("Write file content!");
testFile.print("Here is the test text");
testFile.close();
}else{
Serial.println("Problem on create file!");
}
testFile = LittleFS.open(F("/testCreate.txt"), "r");
if (testFile){
Serial.println("Read file content!");
/**
* File derivate from Stream so you can use all Stream method
* readBytes, findUntil, parseInt, println etc
*/
Serial.println(testFile.readString());
testFile.close();
}else{
Serial.println("Problem on read file!");
}
I also tried this and it fails. I can only get r read mode to work if I upload the file manually through tool
fs = LittleFS.open("/sample.json", "w+");
delay(50); // wait a bit for write to complete
if (fs.print("Hello") > 0)
Serial.println("sample written. now will try to read...");
else
Serial.println("Problem on create file!");
fs.close();
delay(50); // wait .5 sec for write to complete