SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
#201349
First I am new to Arduino.
Second I am using the SparkFun RedBoard and SD Shield.
I am trying to use the blue LED to indicate what is happening as the program runs.
This problem exists with or without the SD Shield attached.
It is the call to this function that seems to cause the problem --- if (!SD.begin(chipSelect))

Below is my code stripped down to troubleshoot the problem.
About 2/3rds of the way down I bolded the two lines that create or cure the problem.
If I visual monitor the RX LED and the blue LED the call if (!SD.begin(chipSelect)) seems to be where it goes astray,
i.e. long blue LED, then nothing.
Hopefully somebody has seen this and can help.

Thanks, Fred

*****************************************************
#include <SPI.h> // include SPI library
#include <SD.h> // include the SD library:

// The Sparkfun microSD shield uses pin 8 for CS
const int chipSelect = 8;

// variables for dual temperature probe on A0 & A1
float Temp1, Temp2;
float constant = (5.0/1024.0)*100.0; //used to convert LM35 from C to F
long loop_count = 0; //passes through the loop

void setup()
{
// 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(10, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT); //set blue LED pin to output

// 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.println("Initializing SD card...");
delay(3000);
Blink_LED(3);

// see if the card is present and can be initialized:
// if (!SD.begin(chipSelect)) //when used - 3 blinks, long blue LED, no more blinks
if (1) //when used - 3 blinks, pause, then 3 blinks i.e. normal behavior

{
Serial.println("Card failed, or not present");
// don't do anything more:
delay(3000);
Blink_LED(3);
while (1);
}
Serial.println("card initialized.");

}

void loop(void)
{
while(1);
}

void Blink_LED (int times)
{
for (int i =0; i<times; i++)
{
Serial.println("Blink");
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
delay(800);
}
}
#201366
The built in led is connected to pin 13; pin 13 is also the SPI clock used by the card reader.

You have to take a decision what is the important feature of your project ;) You can use a led + resistor on a different pin that is still free; for SPI, stay away from pins 10..13 and for the specific shield, pin 8 (the chip select in your code).