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?
|