Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: SD Card fails to connect
Oliiver
Newbie
Posts: 1
Permalink
Post SD Card fails to connect
on: January 11, 2016, 01:51
Quote

I have unsuccessfully tried making so I can connect to a micro USB for the last day.

To try and narrow down the problem I copied the SD connect code into an empty Arduino project like so.

#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

bool cardPresent = false;
bool cardInit = false;
File root;

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
  }
  
  pinMode(chipSelect, OUTPUT); // necessary for SD card reading to work

  // see if the card is present and can be initialized:
  int initValue = 0;
  initValue = SD.begin(chipSelect);
  if (initValue == 0) {
    Serial.println("Card failed, or not present");
  }
  else {
    Serial.println("Successfully beginned.");
    cardPresent = true;
  }
  
  if (cardPresent) {
    Serial.println("card initialized.");
    root = SD.open("/", FILE_READ);
    cardInit = true;
    Serial.println("done!");
  }
}

void loop(){
  
}

This works fine and prints the following message to the Serial.

Successfully beginned
card initialized
done!

However, this exact same code in the main code (The polagraph one) DOES not work and I get the following message.

Card failed, or not present

Does anybody have the same problem? Am I doing something wrong?

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: SD Card fails to connect
on: January 11, 2016, 20:58
Quote

Who can say? If you'd said what kind of hardware you have, which polargraph firmware you copied from then perhaps we could start to make a guess.

When asking for help, please have a think about whether you have supplied enough information to allow us to help.

sn

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.016 seconds.