Leonardo and SD board setup queries

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Leonardo and SD board setup queries

Post by savard »

Hello,
I have several questions for the Leonardo and SD card board. These are listed below in 3 separate categories: Hardware; Libraries; and Software/Examples

1) Hardware setup
We took a Leonardo (PID: 849) and snap it together with SD Card board – data logging shied (PID: 1141) [photo attached] and included the small battery and connected this with the USB to the PC to power it up.
Questions:
a) I want to confirm if additional external power is necessary or if the current power setup is sufficient?
b) Is there additional hardware setup required in this model?
c) Is an ICSP connector required, after connecting Leonardo with SD Card board? If so – what is the current ICSP connector and is it taken care of?

2) Libraries
Following this link: http://learn.adafruit.com/adafruit-data ... d-leonardo for the “Mega and Leonardo” and
a) Downloaded the SD library zip file and unzipped the file
b) Created the folder “SD” under Arduino -> libraries -> SD and copied all the files
c) Once I copied the files, checked the SD folder to confirm that the SD.c and SD.h file exist in the SD folder

3) Software/ Examples
We have run the example: File -> Example -> SD -> CardInfo
but when we compile the code, run it and see the output window – it keeps printing messages relating to not able to find the card, and fail to initialize the card.
Questions:
a) Do we have to specify any pins in SD.h / SD.cpp or with CardInfo example?
b) Is there anything additional required for this example to run properly – if the above requirements are met?
Attachments
Leonardo and SD Card Board connection
Leonardo and SD Card Board connection
photo 1.JPG (269.63 KiB) Viewed 2030 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

1) Hardware setup
We took a Leonardo (PID: 849) and snap it together with SD Card board – data logging shied (PID: 1141) [photo attached] and included the small battery and connected this with the USB to the PC to power it up.
Questions:
a) I want to confirm if additional external power is necessary or if the current power setup is sufficient?
b) Is there additional hardware setup required in this model?
c) Is an ICSP connector required, after connecting Leonardo with SD Card board? If so – what is the current ICSP connector and is it taken care of?
a) That should be sufficient.
b) No.
c) No. You can program it via the USB port.
2) Libraries
Following this link: http://learn.adafruit.com/adafruit-data ... d-leonardo for the “Mega and Leonardo” and
a) Downloaded the SD library zip file and unzipped the file
b) Created the folder “SD” under Arduino -> libraries -> SD and copied all the files
c) Once I copied the files, checked the SD folder to confirm that the SD.c and SD.h file exist in the SD folder
You are missing the step where the existing SD library is disabled in the Arduino install. If you do not remove the old SD library, there will be 2 copies of it and system can get confused. Review the first few paragraphs of this page: http://learn.adafruit.com/adafruit-data ... d-leonardo
3) Software/ Examples
We have run the example: File -> Example -> SD -> CardInfo
but when we compile the code, run it and see the output window – it keeps printing messages relating to not able to find the card, and fail to initialize the card.
Questions:
a) Do we have to specify any pins in SD.h / SD.cpp or with CardInfo example?
b) Is there anything additional required for this example to run properly – if the above requirements are met?
You need to specify the SPI pins in the call to card.init() in cardinfo. See the last paragraph of this page: http://learn.adafruit.com/adafruit-data ... d-leonardo

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

Thank you for these answers. I do have follow up questions:
You are missing the step where the existing SD library is disabled in the Arduino install. If you do not remove the old SD library, there will be 2 copies of it and system can get confused. Review the first few paragraphs of this page: http://learn.adafruit.com/adafruit-data ... d-leonardo
Regarding the disabling of the SD library in the Arduino install. Is it possible to disable this by changing the name of SD folder to “SDbackup” in the libraries folder as an alternative means?

You need to specify the SPI pins in the call to card.init() in cardinfo. See the last paragraph of this page: http://learn.adafruit.com/adafruit-data ... d-leonardo
For the CardInfo example, for specifying the SPI pins with the card.init() code. If we assume to use pins 10,11,12,13 for Leonardo. Can you please confirm that this is the appropriate code:
card.init(SPI_HALF_SPEED, 10,11,12,13);

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

Regarding the disabling of the SD library in the Arduino install. Is it possible to disable this by changing the name of SD folder to “SDbackup” in the libraries folder as an alternative means?
No. The IDE scans all top level folders in the libraries folder - regardless of folder name.
Can you please confirm that this is the appropriate code:
card.init(SPI_HALF_SPEED, 10,11,12,13);
Yes.

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

One more follow-up question. and Thank you so far!
The IDE scans all top level folders in the libraries folder - regardless of folder name.
Question: If we delete the old SD folder and all the files in it? Would this act as if the SD folder is disabled?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

If the IDE can't find it at the top level of the Libraries folder, it is effectively disabled.

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

Another follow up question. I'm wondering if you can confirm if this is an appropriate code below. Please offer insights for anything which needs to be altered. Thank you!

while (!card.init(SPI_HALF_SPEED, (10,11,12,13))) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

That looks correct.

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

Hello -

I'm using 2GB cards in the format of the FAT system. But I'm still unable to get this to work properly by testing the program for the SD card. I'm getting the conventional initialization failed error system.

I made changes to the CardInfo program and have included the modifications of the file below. I'm sending out the entire file with the changes made - can you please look at this and offer insights. I'm hoping you can offer additional modifications that will make this program run. Thank you!

The changes made are within this file:
while (!card.init(SPI_HALF_SPEED, chipSelect))

The current change is to:
while (!card.init(SPI_HALF_SPEED, (10,11,12,13)))

-------------------------------------------

Code: Select all

created  28 Mar 2011  by Limor Fried 
 modified 9 Apr 2012   by Tom Igoe
 */
 // include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;    

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(SS, OUTPUT);


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  while (!card.init(SPI_HALF_SPEED, (10,11,12,13))) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
  } 
  
  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  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
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) { 
}
Last edited by adafruit_support_bill on Tue Aug 20, 2013 6:32 am, edited 1 time in total.
Reason: Please use [code] tags when posting code

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

Code: Select all

while (!card.init(SPI_HALF_SPEED, (10,11,12,13)))
You have an extra layer of parentheses there. You need:

Code: Select all

while (!card.init(SPI_HALF_SPEED,10,11,12,13))

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

Thanks for the quick reply.

Wondering if there are any others changes that can be made to the CardInfo file program to get this running? Since I'm still having difficulties...

Do you recommend using a 2GB sd card - or will another size be useful?
Should I change the structure of the pins?
Any other insights would be wonderful

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Leonardo and SD board setup queries

Post by adafruit_support_bill »

Are you still getting errors reported on the serial monitor? Post the exact error message text.

User avatar
savard
 
Posts: 34
Joined: Mon Feb 11, 2013 12:46 pm

Re: Leonardo and SD board setup queries

Post by savard »

As I run this message without the extra layer of parentheses :
while (!card.init(SPI_HALF_SPEED,10,11,12,13))

The serial monitor is blank. It does not display an error message nor does it continue with the program. So I am unsure what would be the next step in correcting this file allowing it to run properly. Any advice ? Thank you

00maxi
 
Posts: 1
Joined: Thu Aug 29, 2013 6:08 am

Re: Leonardo and SD board setup queries

Post by 00maxi »

Hello all together,

I've exact the same problem as described below.

I tested my SD card with an Arduino UNO board using the correct libraries and it works fine.
But when I ust the same shield on my Leonardo with the Leonardo library and the necessarry changes ( PIN 10 and "while (!card.init(SPI_HALF_SPEED,10,11,12,13))" ) I have the same problem as described by savard.

How could the problem be solved?

Thank you

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”