• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoUse SD card Breakout Board on pcDuino
Previous Next

Use SD card Breakout Board on pcDuino

Posted by: admin , March 9, 2014

[vc_row][vc_column][vc_column_text]sd_pcduino_x1

Though pcDuino directly support the memory extending of TF card and the it has a big capacity,

it does’t prevent us to understand and learn how the SD card realize reading and writing on pcDuino.[/vc_column_text][vc_tour][vc_tab title=”Part list” tab_id=”1394155998-1-41″][vc_column_text]1  x  pcDuino v2

1  x  SD Card Breakout Board

several dupont lines[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1394155998-2-39″][vc_column_text]SD Card Breakout Board   CS pin  – >  Arduino  D4 pin

SD Card Breakout Board   SCK pin  – > Arduino  D13 pin

SD Card Breakout Board   MISO  pin  – > Arduino D12 pin、

SD Card Breakout Board   MISO pin  – > Arduino  D11 pin

SD Card Breakout Board   VCC pin  – >  Arduino  +5V

SD Card Breakout Board   GND  pin  – > Arduino   GND[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1394214036911-2-3″][vc_column_text]We can’t use Arduino library directly on pcDuino for the different main control chip between the Arduino and pcDuino, as a result , it will report error if we directly use the SD card in Arduino carried by pcDuino.

Firstly, click the SD which has been downloaded and repaired well and could be used on pcDuino.

Then, to change the unzipped file name to uppercase SD( as the figure the SD card file on the desk, in the libraries is the original own library of IDE)

2014-03-06-090851_1920x1080_scrot

Then we replace the SD library in libraries with our own SD library ( as follows)

2014-03-06-090903_1920x1080_scrot

Choose the ‘ Apply this option to all existing file’, click Overwrite, and the change work will be well done.

At last cover the ”Print.h” in “/usr/share/arduino/hardware/arduino/pcduino/cores/arduino”

 with the supplied file Print .

Then copy the below code into the IDE of pcDuino

#include <core.h>
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;

#define chipSelect 10
void setup()
{
uint32_t volumesize;

SD.begin(chipSelect);

if(!card.init(4, chipSelect))
{
printf(“initialization failed. Things to check:n”);
printf(“* is a card is inserted?n”);
printf(“* Is your wiring correct?n”);
printf(“* did you change the chipSelect pin to match your shield or module?n”);
//return;
}
else printf(“Wiring is correct and a card is present.n”);

printf(“nCard type: “);
switch(card.type())
{
case SD_CARD_TYPE_SD1:
printf(“SD1n”);
break;
case SD_CARD_TYPE_SD2:
printf(“SD2n”);
break;
case SD_CARD_TYPE_SDHC:
printf(“SDHCn”);
break;
default:
printf(“Unknownn”);
break;
}
// Now we will try to open the ‘volume’/'partition’ – it should be FAT16 or FAT32
if (!volume.init(card))
{
printf(“Could not find FAT16/FAT32 partition.nMake sure you’ve formatted the cardn”);
return;
}

printf(“Volume type is FAT%dn”,volume.fatType());
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we’ll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
printf(“Volume size (bytes): T%dn”,volumesize);
volumesize /= 1024;
printf(“Volume size (Kbytes): T%dn”,volumesize);
volumesize /= 1024;
printf(“Volume size (Mbytes): T%dn”,volumesize);

if(root.openRoot(volume) == false)
{
printf(“Root Open Failed!”);
return;
}
printf(“Files found on the card (name, date and size in bytes):”);
// list all files in the card with date and size
root.ls((LS_R | LS_DATE | LS_SIZE),8);
root.close();
printf(“n”);

Serial.begin(9600);
}

void loop(){

}

[/vc_column_text][/vc_tab][vc_tab title=”Test result” tab_id=”1394214037910-3-1″][vc_column_text]pcDuino successfully realize the SD card,

and print the information and file inside the card.

The TEST.TXT is the data that we wrote in last experiment.2014-03-06-073544_660x464_scrot

 

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: pcDuino, Shields

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors