8 Replies Latest reply on Apr 1, 2014 4:07 PM by MarcIII

    Workaround for SD file creation bug.

    Clayton Hofrock

      There is a bug that does not allow you to create new files on an SD card. This can be fixed by using a Linux system command to create an empty file.

       

        // check if the file exists, if it does not,

        // then create an empty file with that name.

        if(!SD.exists("test.txt")){

          Serial.println("test.txt does not exist, creating.");

          system("touch /media/mmcblk0p1/test.txt");

        }

        // open the file. note that only one file can be open at a time,

        // so you have to close this one before opening another.

        myFile = SD.open("test.txt", FILE_WRITE);

        • 1. Re: Workaround for SD file creation bug.
          DAM

          Excellent... I mean super. I was following your other thread where it says it is a known issue and when I searched to get back there happily found this. Any idea when the update will be out? and where did you find the system("touch /media/mmcblk0p1/test.txt"); reference? I'd like to glance at it to see if there are any more useful secrets.

          • 2. Re: Workaround for SD file creation bug.
            Clayton Hofrock

            I have not heard any information about when the next update is due to be released.

             

            The system command I found on this forum, I am not aware of it being documented anywhere else. They were using it to start an ethernet connection. It is just simply a way to execute a Linux command line. So, anything you can do from the Linux command line, you can also do from within your arduino sketch. It gets a little more complex if you want to get information back from your command, like running an ifconfig command to try and get the IP address.

            • 3. Re: Workaround for SD file creation bug.
              Rafael.Gomez

              From your response:

              chofrock wrote:

               

              I have not heard any information about when the next update is due to be released.

               

              The system command I found on this forum, I am not aware of it being documented anywhere else. They were using it to start an ethernet connection. It is just simply a way to execute a Linux command line. So, anything you can do from the Linux command line, you can also do from within your arduino sketch. It gets a little more complex if you want to get information back from your command, like running an ifconfig command to try and get the IP address.

              How complex is it to get the information back from the command?

              Where would one begin? I am interested in getting the IP back to display on an LCD

              • 4. Re: Workaround for SD file creation bug.
                Clayton Hofrock

                For printing out the IP address, there are easy ways of doing that. If you look at the File->Example->Ethernet->DhcpAddressPrinter it shows how to print the IP address to the Serial console. Should be easy to combine that with one of the LCD examples to print the IP address to the LCD instead of the serial console.

                 

                For future information, Here is an example of how to get data back from a linux command:

                Re: How to access the real time clock from Arduino

                • 5. Re: Workaround for SD file creation bug.
                  carlynorama

                  Thanks for this!

                   

                  I've created an SD card testing script if anyone will find it handy: (link to github gist)

                   

                  Use this file to see if writing to the SD card on the Galileo Board works for you.

                  • 6. Re: Workaround for SD file creation bug.
                    BillyCW

                    Thanks Carlynorama, the test code works great.

                     

                    Just a few useful tidbits on using the SD library for the Galileo. The SD.begin() function can be called without specifying the CS pin number; also you do not need to define the pinMode of any other CS pins (i.e. 10 and 4 like you would for other non-Galileo boards). This is because the CS and SPI lines used for the SD card on the Galileo is independent of the Arduino header pins. I've done some tests with the logic analyzer and noticed that, while reading from and writing to the microSD, the ICSP header's SPI lines are not touched by the Galileo board, neither are pins 4 and 10 - even when initializing the SD card with pin 4 or 10 (i.e. SD.begin(4) ). This means that accessing the Galileo microSD via the SD library should not create any Arduino shield conflicts due to CS selection.

                    • 7. Re: Workaround for SD file creation bug.
                      carlynorama

                      Awesome, go you for having the time to throw an analyzer on it.

                       

                      I left the lines in as an abundance of caution, but I've updated the code identifying the pin references as potentially optional with a call out to this thread.

                       

                      I believe you, but I just don't have time to check the code myself and I don't want remove the lines without time to test.  I feel weird about posting code publically that I haven't actually run on the hardware myself.

                       

                      When I get a chance, I'll take the hedging language out... of course in the time I took to write this I could have  walked over to the board and...

                      • 8. Re: Workaround for SD file creation bug.
                        MarcIII

                        SD card access on Galileo does not involve any SPI interface. It uses a fully SDIO 3.0 compliant, independent and dedicated, 50MHz interface exactly like the one on your PC. The code of the SD class in the IDE (which you can tweak/fix yourself any time) is reading and writing the card in the exact same way any other regular Linux software on a Linux PC would browse an SD card or some USB memory. This is nothing like what happens on an Arduino board which does not have an operating system.

                         

                        The bug and the best way to fix it have been already discussed here:

                        SDcard cannot create a new file with Arduino Sketch.