Built-in LED not lighting up due to SD card initialisation

For some reason, lines 14-16 (below) are preventing the built-in LED from lighting up. I am using an Uno.

Could anyone please confirm why this might be, and how to work around it? I suspect it has something to do with SD.begin() using the SPI bus, but I’m not sure how to fix it.

#include <SPI.h>                      // Include Arduino SPI library.
#include <SD.h>                       // Include Arduino SD library.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);       // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(9600);                 // Open serial communications and wait for port to open.
  while (!Serial) {
    ;                                 // Wait for serial port to connect. Needed for native USB port only.
  }

  // Initialise SD card.
  Serial.print("Initialising SD card... ");

  if (!SD.begin()) {                  // <<<-- THIS STOPS THE BUILT-IN LED FROM WORKING!
    while (true);                     // Stay here.
  }
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Pin 13 (built in LED pin) is also the SPI SCK pin.

I found this thread with a search for "arduino spi and built in led".

groundFungus:
Pin 13 (built in LED pin) is also the SPI SCK pin.

I found this thread with a search for "arduino spi and built in led".

Does this essentially mean one cannot use the built-in LED and the SPI bus at the same time? Is there no workaround?
The "L" LED on the board does nothing when a file is written to on the SD card (lower down in my code, not posted here). Only the "RX" LED illuminates. So SPI bus communications do not appear to take advantage of the built-in LED, they just stop it from working.

jimixter:
The “L” LED on the board does nothing when a file is written to on the SD card (lower down in my code, not posted here).

The clock pulses on SCK are very short duration, likely imperceptible as a change in brightness on an LED.

Does this essentially mean one cannot use the built-in LED and the SPI bus at the same time? Is there no workaround?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.