Log Data Whilst SD In
hi all,
i'm trying seemingly simple following error every time insert card.
- initialization failed!
- couldn't create file...
the line below gives me 1 when inserted 0 when isn't.
what doing wrong?
thanks in advance,
charles
i'm trying seemingly simple following error every time insert card.
- initialization failed!
- couldn't create file...
the line below gives me 1 when inserted 0 when isn't.
code: [select]
reading = digitalread(sdinpin);
what doing wrong?
thanks in advance,
charles
code: [select]
#include <spi.h>
#include <sd.h>
// --------- general -----------
int sampletime = 10;
long int previous = 0;
long int starttime = 0;
int sdinpin = 2;
boolean starting = true;
boolean reading = false;
file datafile;
const int chipselect = 8;
void setup() {
serial.begin(115200);
}
void loop() {
reading = digitalread(sdinpin);
if (reading) {
if (starting) {
serial.print("starting: ");
serial.println(starting);
loadsd();
starttime = millis();
starting = false;
}
if (millis() - previous > sampletime) {
string datastring = "";
// add data datastring
serial.println(datastring);
datafile.println(datastring);
datafile.flush();
previous = millis();
}
} else if (starting == false) {
starting = true;
}
}
void loadsd() {
pinmode(ss, output);
if (!sd.begin()) {
serial.println("initialization failed!");
}
// create new numbered file
char filename[] = "pheet00.csv";
for (uint8_t = 0; < 100; i++) {
filename[5] = / 10 + '0';
filename[6] = % 10 + '0';
if (! sd.exists(filename)) {
// open new file if doesn't exist
datafile = sd.open(filename, file_write);
break; // leave loop!
}
}
datafile = sd.open(filename, file_write);
if (!datafile) {
serial.println("couldn't create file...");
}
}
code: [select]
//mux control pins
int sr0 = 9;
int sr1 = 10;
int sr2 = 11;
int sr3 = 12;
what arduino using? how have wired sd module?
pin 11 mosi , pin 12 miso on spi bus. think pin 10 may need reserved output sd library.
Arduino Forum > Using Arduino > Programming Questions > Log Data Whilst SD In
arduino
Comments
Post a Comment