Yun + SD card = Will Not Create File

Ok, I give up. I’ve been messing with this and just can’t seem to get it working.

I have an Arduino Yun. In it I’ve plugged in a 32GB microSD card.

It sees the card. I’ve uploaded web server sketches to it. I have not formatted it with Windows - it is formatted how it came formatted. I created the “arduino” folder on it and I can browse it using a web browser. I can SSH and browse files in /mnt/sd which is also /mnt/sda1.

Today, I tried adding file logging to my sketch. I couldn’t get it to write to a file. No idea why.

I tried the DataLogger example and it doesn’t work either.

I tried the SDfat bench example and it doesn’t work either.

I’ve unplugged and plugged the Yun back in (full reboot).

I’ve removed the SD card and put it back in. I’ve umounted it and put it back in.

If I run the SDfat bench example, this is the output I get:

Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 1121
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X20,0X0

I put together this very simple sketch:

#include <SPI.h>
#include <FileIO.h>

void setup() {
  // Open serial communications and wait for port to open:
  SerialUSB.begin(9600);
  delay(1000);
  
  // Open logfile
  FileSystem.begin();
  delay(1000);
  
  File testFile = FileSystem.open("/mnt/sda1/tmg.txt", FILE_APPEND);
  delay(1000);
  testFile.println("Setup Starting");
  
  SerialUSB.println("File Write Testing");
  SerialUSB.println(testFile);

  testFile.close();
  SerialUSB.println("Done");
}

void loop() {
  // put your main code here, to run repeatedly:

}

I’ve tried it with /mnt/sd/tmg.txt, /mnt/sda1/tmg.txt, tmg.txt and /tmp/tmg.txt and none produce a file anywhere. I’ve tried both FILE_APPEND and FILE_WRITE.

This is what I get for output:

File Write Testing
0
Done

Sometimes I get a “1” response for the testFile value but either way - still no file.

This is what the Yun’s system log shows:

May 23 21:06:29 ARDUINO02 kern.notice kernel: [ 2488.950000] sd 0:0:0:0: [sda] 62333952 512-byte logical blocks: (31.9 GB/29.7 GiB)
May 23 21:06:29 ARDUINO02 kern.err kernel: [ 2488.950000] sd 0:0:0:0: [sda] No Caching mode page present
May 23 21:06:29 ARDUINO02 kern.err kernel: [ 2488.950000] sd 0:0:0:0: [sda] Assuming drive cache: write through
May 23 21:06:29 ARDUINO02 kern.err kernel: [ 2488.960000] sd 0:0:0:0: [sda] No Caching mode page present
May 23 21:06:29 ARDUINO02 kern.err kernel: [ 2488.960000] sd 0:0:0:0: [sda] Assuming drive cache: write through
May 23 21:06:29 ARDUINO02 kern.info kernel: [ 2488.970000]  sda: sda1
May 23 21:06:30 ARDUINO02 kern.warn kernel: [ 2489.710000] busybox: sending ioctl 5310 to a partition!
May 23 21:06:30 ARDUINO02 kern.warn kernel: [ 2489.710000] busybox: sending ioctl 5310 to a partition!
May 23 21:06:30 ARDUINO02 kern.warn kernel: [ 2489.720000] busybox: sending ioctl 5310 to a partition!
May 23 21:06:30 ARDUINO02 kern.warn kernel: [ 2489.720000] busybox: sending ioctl 5310 to a partition!
May 23 21:06:30 ARDUINO02 user.notice automount: /mnt/sda1/arduino folder found: /mnt/sda1 is now available at /mnt/sd
May 23 21:06:30 ARDUINO02 user.notice automount: /mnt/sda1/arduino/www folder found: /mnt/sda1/arduino/www is now available at /www/sd
May 23 21:06:32 ARDUINO02 user.info sysinit: handle umount errors 
May 23 21:06:32 ARDUINO02 user.info sysinit: check umount sda
May 23 21:06:34 ARDUINO02 user.info sysinit: handle umount errors 
May 23 21:06:34 ARDUINO02 user.info sysinit: check umount sda
May 23 21:06:36 ARDUINO02 user.info sysinit: handle umount errors 
May 23 21:06:36 ARDUINO02 user.info sysinit: check umount sda

If I let it just sit… it just fills up with those “handle umount errors” and “check umount sda”.

I can use WinSCP to SCP files to/from it just fine as well.

It is almost like the SD card itself is write-protected or something.

What I don’t get is that I can’t seem to write a file ANYWHERE? Like, not even an SD card problem - I can’t even create a file in /tmp.

Anyone have any suggestions?

Thanks!

I can’t seem to read files either…

I added to my simple sketch to read a 2-line text file:

#include <SPI.h>
#include <FileIO.h>

void setup() {
  // Open serial communications and wait for port to open:
  SerialUSB.begin(9600);
  delay(1000);
  
  // Open logfile
  FileSystem.begin();
  delay(1000);
  
  File testFile = FileSystem.open("/tmp/tmg.txt", FILE_APPEND);
  delay(1000);
  testFile.println("Setup Starting");
  
  SerialUSB.println("File Write Testing");
  SerialUSB.println(testFile);

  testFile.close();
  
  SerialUSB.println("");
  SerialUSB.println("");

  File readFile = FileSystem.open("/mnt/sd/testread.txt", FILE_READ);
  delay(1000);
  SerialUSB.println(readFile);
  char text = "";
  while (readFile.available()) {
    text = text + (char)readFile.read();
  }
  readFile.close();
  SerialUSB.println(text);

  SerialUSB.println("");
  SerialUSB.println("");
  SerialUSB.println("Done");
}

void loop() {
  // put your main code here, to run repeatedly:

}

This is the output that I see:

File Write Testing
0


0
c


Done

It doesn’t appear to be opening the file for reading either. I’ve tried the same file in /tmp and /mnt/sd with the same results.

I finally found it…

I looked and looked but could not find anything and spelled it out for me. I was reading something about the Yun and FileSystem and finally caught it: the Yun accessing the filesystem (SD card or otherwise) through the bridge. That was the piece I was missing, I did not start the bridge.

Once I added that, it worked perfectly.

Here is the simple code for future reference:

#include <FileIO.h>

void setup() {
  // Start Bridge
  Bridge.begin();
  delay(1000);
  
  // Open serial communications and wait for port to open:
  SerialUSB.begin(9600);
  delay(1000);

  // Open logfile
  FileSystem.begin();
  delay(1000);
  
  File testFile = FileSystem.open("/mnt/sd/tmg.txt", FILE_APPEND);
  delay(1000);
  testFile.println("Setup Starting");
  
  SerialUSB.println("File Write Testing");
  SerialUSB.println(testFile);

  testFile.close();
  
  SerialUSB.println("");
  SerialUSB.println("");

  SerialUSB.println("Reading File...");
  File readFile = FileSystem.open("/mnt/sd/testread.txt", FILE_READ);
  delay(1000);
  SerialUSB.println(readFile);
  while (readFile.available()) {
    String text = readFile.readStringUntil('\n');
    SerialUSB.println(text);
  }
  readFile.close();

  SerialUSB.println("");
  SerialUSB.println("");
  SerialUSB.println("Done");
}

void loop() {
  // put your main code here, to run repeatedly:

}