Page 1 of 1

SD.begin(chipSelect) seems to be change blue LED pin mode

Posted: Sun Dec 09, 2018 12:55 pm
by FredY
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:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
Serial.println("Initializing SD card...");

// 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:
while (1);
Serial.println("card initialized.");


void loop(void)

void Blink_LED (int times)
for (int i =0; i<times; i++)
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);

Re: SD.begin(chipSelect) seems to be change blue LED pin mode

Posted: Mon Dec 10, 2018 11:21 pm
by sterretje
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).

Re: SD.begin(chipSelect) seems to be change blue LED pin mode

Posted: Wed Dec 12, 2018 2:05 pm
by FredY
Thanks for the clarification.
I thought that was the problem, but hoped the s/w keep track of it and set it back.
Another LED and resistor is the answer.

Cheers, Fred