Announcement

Collapse
No announcement yet.

MicroSD Card Write

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • MicroSD Card Write

    Hello everyone,

    I am an engineering college student trying to create a code for saving gyroscope data to the on-board microSD card. I have had no luck in trying to find any sample code to do this. Can anyone give me some help? What commands do I need to use? Anyone have a sample code?

    Thanks

  • #2
    Hi Chessmaster,

    This appnote might offer a lot of help:

    ViSi Read and Write to microSD
    http://www.4dsystems.com.au/appnote/4D-AN-00077/

    Also you might want to explore the FAT16 functions in the internal functions manual.

    For PICASO: (page 203)
    http://www.4dsystems.com.au/productp...ons_R_6_20.pdf

    For Diablo16: (page 302)
    http://www.4dsystems.com.au/productp...ons_R_1_16.pdf

    Best Regards,

    Comment


    • #3
      Thanks for the reply. One more question. Do you have to have a FAT16 microsd card or can it be FAT32 for writing to? I have a 8gb microsd but it is only FAT32 and I want to know if I can use it.

      Comment


      • #4
        Hi Chessmaster,

        We recommend these kind of SD cards: (You might want ti get similar kinds, SPI Compatibility is important)

        http://www.4dsystems.com.au/product/uSD_4GB_Industrial/

        You might be able to use your 8gb uSD if you partition the first 4gb into FAT16 (max is up to 4gb).

        You could also you the RMPET tool and this appnote for partitoning the uSD card:
        http://www.4dsystems.com.au/download...042_R_1_01.pdf

        Best Regards,

        Comment


        • #5
          Thank you. Alright I have looked at the PICASO list of functions. Can anyone provide more details and some guidance on how to save data captured using gyroscope sensors to the microSD card built in. Any help would be appreciated!

          Comment


          • #6
            When trying to write a string to a file on the microSD card, can you use the file_PutS command? Every time I try to do this I just get an error that says file_PutS is not declared in this scope. Anyone know how to help?

            Comment


            • #7
              Or would you use the file_Write command? Would this work to write to the file on the SD card: file_Write(0x00,0x05,"Hello","mytextfile"); If I wanted to write hello to that file would this work? When I run this command I get an error that says file_Write is not declared in this scope. What do I need to include to get this to work?

              Comment


              • #8
                Try "Display.file_PutS(mytextordata)" I know samples show it without, but somewhere I happened to see it with "Display." in front.

                Comment


                • #9
                  Hey thanks for the response. I just tried the "Dipslay." in front of it. It gives me an error. Here is the piece of my code that uses it:
                  "Display.file_Open("myfile.txt", 'w');
                  Display.file_PutS(1,"myfile.txt");"

                  I get the following error:
                  In function 'void setup()':

                  TestSD:107: error: invalid conversion from 'int' to 'char*' [-fpermissive]

                  Display.file_PutS(1,"myfile.txt");

                  ^
                  Picaso_Serial_4DLib.h:61:8: note: initializing argument 1 of 'word Picaso_Serial_4DLib::file_PutS(char*, word)'

                  word file_PutS(char * StringOut, word Handle);

                  ^

                  TestSD:107: error: invalid conversion from 'const char*' to 'word {aka unsigned int}' [-fpermissive]

                  Display.file_PutS(1,"myfile.txt");

                  ^
                  Picaso_Serial_4DLib.h:61:8: note: initializing argument 2 of 'word Picaso_Serial_4DLib::file_PutS(char*, word)'

                  word file_PutS(char * StringOut, word Handle);

                  ^

                  exit status 1
                  invalid conversion from 'int' to 'char*' [-fpermissive]

                  Completed RC=1


                  I also tried changing the 1 to "1" here: this is the error I get:
                  In function 'void setup()':

                  TestSD:107: error: invalid conversion from 'int' to 'char*' [-fpermissive]

                  Display.file_PutS(1,"myfile.txt");

                  ^

                  In file included from Picaso_Serial_4DLib.h:61:8: note: initializing argument 1 of 'word Picaso_Serial_4DLib::file_PutS(char*, word)'

                  word file_PutS(char * StringOut, word Handle);

                  ^

                  TestSD:107: error: invalid conversion from 'const char*' to 'word {aka unsigned int}' [-fpermissive]

                  Display.file_PutS(1,"myfile.txt");

                  ^

                  In file included from TestSD.ino:19:0:

                  sketch\Picaso_Serial_4DLib.h:61:8: note: initializing argument 2 of 'word Picaso_Serial_4DLib::file_PutS(char*, word)'

                  word file_PutS(char * StringOut, word Handle);

                  ^

                  exit status 1
                  invalid conversion from 'int' to 'char*' [-fpermissive]

                  Completed RC=1

                  Anyone have any ideas how to fix this and get it to save. Right now I am just trying to save the value 1. The end goal is to save data that is being generated from two gyoscope sensors to the microSD so that way the data can be out onto a computer to be analyzed.

                  Thanks!
                  Last edited by Chessmaster; 23rd January 2017, 07:55 AM.

                  Comment


                  • #10
                    Hi Chessmaster,

                    I have attached a simple 4Duino Project that writes "Hello World" on the SD Card. Then reads the text written on the sd card to be displayed on the LCD.

                    Attached, test-sd.zip

                    Here is the App Note related to the sample project:

                    Serial Arduino uSD Card Access FAT16
                    http://www.4dsystems.com.au/appnote/4D-AN-00113/

                    For the 4Duino and Arduino, you could also try something like these:
                    //------------------------
                    handle = Display.file_Open("SAMPLE.txt",'w');
                    Display.putstr("Writing to uSD... \n");
                    Display.putstr("HELLO WORLD to SAMPLE.txt \n");
                    delay(2000);
                    Display.file_Write(11,"HELLO WORLD",handle);
                    Display.file_Close(handle);
                    //-------------------------

                    Hope this helps and Regards,
                    Attached Files
                    Last edited by Joseph Herrera; 23rd January 2017, 01:09 PM.

                    Comment


                    • #11
                      Thanks that works! Now if I wanted to continuously write into the SD card. Can I put this statement into a void loop? When I tried doing that it said that handle is not defined. Here is my code:

                      void loop()
                      {
                      // put your main code here, to run repeatedly:
                      word handle
                      handle = Display.file_Open("AnkleAng.txt",'w');
                      Display.file_Write(10,"DataString",handle);
                      }

                      I get the following errors:
                      error: expected initializer before 'handle'
                      error: 'handle' was not declared in this scope
                      Display.file_Write(10,"DataString",handle);

                      Comment


                      • #12
                        Haha. I found my mistake. I need a ";" after "word handle"

                        Comment


                        • #13
                          Alright, I got it to work. However, it only saves one "DataString" in the file. How can I get it to save it repeatedly? Thanks!

                          void loop()
                          {
                          // put your main code here, to run repeatedly:
                          word handle;
                          handle = Display.file_Open("AnkleAng.txt",'w');
                          Display.file_Write(10,"DataString",handle);
                          Display.file_Close(handle);
                          }

                          Comment


                          • #14
                            On a side note, I have another question maybe someone can help me out with. I have found a code for the ITG-3200 triple axis gyro. The code works and runs in the Arduino IDE software on the 4Duino. But when I copy it over to the 4D Workshop program the code will not run. I get several errors. The two that I am not sure about are the itgRead and itgWrite. They both say that they are not declared in this scope. These two commands are used to read and write a value to the register. Is there a different command I am supposed to use with the 4Duino?

                            Here is where I found the sample code for the gyroscope: https://learn.sparkfun.com/tutorials...0-hookup-guide



                            I will also attach my code to help with figuring this out. Also there are a couple other errors that have to deal with "{". Maybe someone can help me out. I am new to this whole arduino programing thing.
                            Attached Files

                            Comment


                            • #15
                              Hi Chessmaster,

                              Have you tried 'a' for the mode of file_Open(fname, mode)?

                              Mode 'a' is for append and if file already exists, the file pointer is set to the end of the file ready for appending, else the file pointer will be set to the start of the newly created file.

                              On page 309, http://www.4dsystems.com.au/productp...ons_R_1_16.pdf

                              Regards,

                              Comment

                              Working...
                              X