
CDMania (Customer) asked a question.
I am trying to get the uSD card slot to work on my P1AM-100. I am using the example code and changed the chipselect pin to 28. This still get the "card failed, or not present" every time. The file "datalog.txt" exists on the SD card, it is a 4gb uSD card. I have it formated as FAT (I have tried multiple formates just to verify that wasn't the issue.
Does anyone know what i am doing wrong? Is there a certain formate that the P1AM likes best?
Thanks,
#include <P1AM.h>
#include <SPI.h>
#include <SD.h>
const int chipSelect = 28;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
delay (4000);
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}
void loop() {
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
I have this code, which does work with my P1AM, I assume I got it from facts-engineering examples somewhere. I have a 256 MB uSD card installed.
It doesn't log data, just verifies the SD card, but it may get you going in the right direction. Two quick differences I see are, a) this sketch includes <SPI.h>, not sure it is required, but the SD card does use SPI,
and, b) you are very specific about the chipSelect pin 28, why not use the default:
Here's the whole sketch: