fopen fails, but why? #4
-
Hi all, after reading and trying to understand the examples, I tried to create and write to a file and read from it on the Raspberry Pico. The file system appears to be successfully mounted, but the file does not seem to be created. It's probably just a dumb C++ beginner's error, but after hours of pondering, I can't find the problem. Here's my code (reduced to the relevant parts):
The serial output I get is:
So obviously the command file = fopen("/wave1.dat", "w") did not succeed, but why? As far as I understand, the file should automatically be created if it doesn't exist, right? Any help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The best way to learn is from the working example, such as LittleFS_Test. If your code fails to run, retest the example and compare what are the differences. Then, you will see just a small change, by adding the LittleFS_Mbed_RP2040/examples/LittleFS_Test/LittleFS_Test.ino Lines 303 to 304 in eb1a3a7 I've intentionally delayed to respond to see if you can fix the issue yourself, without surrendering so early. Persistence is always the most demanding and best virtue in programming, which requiring problem-solving continuously.
Don't ever think like that and surrender. Your code shows that you're very good, in researching and implementing, just lacking some the experience to solve the problem methodologically and confidence. I'm sure thru this exercise, you'll be the much better programmer by just removing any doubt that you're Don't be upset, as I can see my similar mistakes in the past and have learnt from them, all my life, and still learning everyday. Code change
Terminal
|
Beta Was this translation helpful? Give feedback.
-
With a little search in the source code, you can see LittleFS_Mbed_RP2040/src/LittleFS_Mbed_RP2040.h Lines 102 to 103 in eb1a3a7 It's actually just a prefix of For example, if in this library I used
then from that time, you have to use prefix as "/your_littlefs" to your filename, such as "/your_littlefs/your_filename", not "/littlefs/your_filename" anymore. So, to hide all the not-interesting details, I have to create that new defininition I suggest next time, if you'd have trouble (nobody won't), try to have a quick look and search the library / core code to understand why they did that way and enrich your knowledge. |
Beta Was this translation helpful? Give feedback.
The best way to learn is from the working example, such as LittleFS_Test. If your code fails to run, retest the example and compare what are the differences.
Then, you will see just a small change, by adding the
MBED_LITTLEFS_FILE_PREFIX
, will fix the issue.LittleFS_Mbed_RP2040/examples/LittleFS_Test/LittleFS_Test.ino
Lines 303 to 304 in eb1a3a7
I've intentionally delayed to respond to see if you can fix the issue yourself, without surrendering so early. Persistence is always the most demanding and best virtue in programming, which requiring probl…