Shop OBEX P1 Docs P2 Docs Learn Events
Store and read data to SD CARD — Parallax Forums

Store and read data to SD CARD

Peavey5150Peavey5150 Posts: 20
edited 2018-01-06 01:02 in General Discussion
How do I save data to a text file from the propeller activity board itself, and then have the propeller activity board read the data back from the SD card after rebooting the system ?


This Project is for machine learning. Robot learns from each trial and would remember data after shut down.



C lang

activity bot 360
propeller activity board wx

Comments

  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-06 14:56
    I think I got it from the examples
    #include "simpletools.h"                      // Include simpletools header    
    
    int DO = 22, CLK = 23, DI = 24, CS = 25;      // SD card pins on Propeller BOE
    
    int main(void)                                // main function
    {
      sd_mount(DO, CLK, DI, CS);                  // Mount SD card
    
      //FILE* fp = fopen("test.txt", "w");          // Open a file for writing
     int  val ;
    // fwrite(&val,sizeof(val),1,fp);
     //val =-100000;
    // fwrite(&val,sizeof(val),1,fp);
     // fclose(fp);
    
     // looks like I just needed to  modify  this line
     FILE* tp = fopen("test.txt", "r");  
    
     fread(&val,4,1,tp);
     print("val = %d\n" ,val);
     fread(&val,4,1,tp);
     print("val = %d\n",val);
     fclose(tp);
     
     
     
                                  // With a newline at the end
    }
    


    modEdit: code blocks added
  • RS_JimRS_Jim Posts: 1,753
    edited 2018-01-06 14:49
    Nick
    Make your code easier to read. In close it between code tags by selecting the "C" from the header and enclosing code between the tags.
    Jim
  • @RS_Jim
    Thanks
  • Peavey5150,

    What do you want your ActivityBot to "Learn"?

    You will need to create some kind of data format that stores this information and then create code that is able to replay or analyze it.

    Also understand that unless you provide your servos a constant voltage they will move slower as the voltage drops so any distance or time record would be inaccurate.
  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-07 02:54
    @Genetix
    Thanks for the tips.

    I was just missing File*
    to read code after shutdown. I got it now.
Sign In or Register to comment.