Quantcast
Viewing all articles
Browse latest Browse all 18089

Re: How to use SD card

Here's another approach to writing & reading to the SD card.  There is an Intel IoT Developer Kit over in Intel's Developer Zone for both Edison and Galileo boards. I downloaded and installed the Developer Kit on my Windows machine. It supports C, C++, JavaScript and Python, but I was mostly interested in writing a just a C program to write & read to the SD card.

 

The Kit uses a modified version of Eclipse as its programming environment.

 

Here's a simple C program I used to write some data to the card, read it back and display it.

 

#include <stdio.h>

#include <stdlib.h>

 

struct Student {

   int id;

   char name[12];

   int percent;

} s1 = { 12345, "Allen", 99 };

 

int main(void) {

    puts("Student test results");

 

    FILE *fp;

    struct Student s2;

 

    //Write to file

    fp = fopen("/media/sdcard/test.txt", "w");

    fwrite(&s1, sizeof(s1), 1, fp);

    fclose(fp);

 

    //Read back from file

    fp = fopen("/media/sdcard/test.txt", "r");

    fread(&s2, sizeof(s2), 1, fp);

    fclose(fp);

 

    //Display results

    printf("\nID : %d", s2.id);

    printf("\nName : %s", s2.name);

    printf("\nPercent : %d", s2.percent);

 

    return (0);

 

}

 

The above program works fine.  However, when I tried to do some other things with file I/O like using fgetc and fputc, I ran into missing #include type problems.  For example, <process.h> and <conio.h> are not included in the C:/iotdk-ide-win/devkit-x86/sysroots/i586-poky-linux/usr/include/ folder. But that's an issue for another day.


Viewing all articles
Browse latest Browse all 18089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>