Hello,
I have a Mega2560 and a CC3000 Adafruit wifi shield, and I first want to use only the SD card and not the Wifi.
Therefore, i've disabled the wifi CS ( D10 set on OUTPUT and HIGH), and put the hardware SS on OUTPUT (although it seems to be optional if you use SD.begin(sdCSpin) )
I won't bother you with the fact that the card doesn't initialize half the time when i try to connect it on my PC and back on the shield, i think i'm just gonna give up and never remove the SD card from the shield.
But i then have to be able to read datas on my SD card and the read() method doesn't work : the error message is the following "error opening donnees.csv" ( it's the same with a .txt file)
The SD card slave select is normally D4, not D8, but I could be wrong about that shield.
edit: It is D4. This is from the pdf on the adafruit site:
On the CC3000 shield, we use the following pin connections
SCK - #13
MISO #12
MOSI #11
CS for CC3000 #10
VBAT_EN #5 CS for SD Card #4
IRQ #3
On the breakout, b
Don't use these objects for routine access to an SD card:
Sd2Card card;
SdVolume vol;
SdFile root;
They are useful to diagnose problems but just use the SD object like this example:
/* SD card read/write example. Derived from the official example by Bill Greiman */
#include <SD.h>
// Change to SD chip select.
const int8_t sdChipSelect = 4;
// Chip select for any other SPI device or -1 if no other SPI device.
const int8_t otherChipSelect = 10;
File myFile;
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
}
// Disable any other SPI device.
if (otherChipSelect >= 0) {
pinMode(otherChipSelect, OUTPUT);
digitalWrite(otherChipSelect, HIGH);
}
Serial.print("Initializing SD card...");
if (!SD.begin(sdChipSelect)) {
Serial.println("initialization failed!");
while(1);
}
Serial.println("initialization done.");
// open the file.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
I just copy-pasted the script from fat16lib and ddn't think to change the chips when i posted but i did it on arduino.
It seems to work, but oddly the first time i try any script using SD card, it first says that initialisation failed, and i have to push the reset button. The the card is initialized and i'm able to write and read thanks to your script =)
Do you know what the problem with the first initialisation could come from and how to solve it? thx