I'm trying to access one of those cheapo SD cards with 5 pins, using SPI.
It works great using an Arduino UNO, I can read and write text back and forth. When I plug the board into a Teensy 3.2, I get "SD card initialization failed", every time, no matter what I do.
The "Blink" program works every time, in the Teensy. (It's how I test to make sure I didn't blow something up). I swapped out the Teensy for another with same results.
I'm using a generic SD program, shown here. At one time it DID work as indicated in my comments and also that Pin 10 was used for chip select on both the UNO and the Teensy. This SD card is part of a bigger project using a TFT. I have the TFT program running on an UNO but not enough memory to include the SD, the reason I'm "upgrading" to the Teensy.
Any clues as to what I'm doing wrong?
It works great using an Arduino UNO, I can read and write text back and forth. When I plug the board into a Teensy 3.2, I get "SD card initialization failed", every time, no matter what I do.
The "Blink" program works every time, in the Teensy. (It's how I test to make sure I didn't blow something up). I swapped out the Teensy for another with same results.
I'm using a generic SD program, shown here. At one time it DID work as indicated in my comments and also that Pin 10 was used for chip select on both the UNO and the Teensy. This SD card is part of a bigger project using a TFT. I have the TFT program running on an UNO but not enough memory to include the SD, the reason I'm "upgrading" to the Teensy.
Any clues as to what I'm doing wrong?
Code:
/*This works May10/21
* Arduino SD Card Tutorial Example
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 10; // Pin 10 on Arduino Uno and Teensy
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
// Create/Open file
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.println("Writing to file...");
// Write to file
myFile.println("Testing Testing 1,2,3,4");
myFile.close(); // close the file
Serial.println("Done.");
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
// Reading the file
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("Read:");
// Reading the whole file
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
}
else {
Serial.println("error opening test.txt");
}
}
void loop() {
// empty
}