Heyy,
For a project I am trying to use a SD-card as a external memory. I am still new at this stuff. Sorry if there is already a topic about this. I want to make something like a EEPROM. That you can send data to it and use that data the next time. The reason why i dont use the EEPROM for that is that you only can read/write 100000 times.
Does someone know of it is possible to use a SD-card that way and how?
Thanks!! Yvette
This is what i af till know:
#include <SPI.h> //bieb voor SD
#include <SD.h> //bieb voor SD
File myFile; //
#define button 2
const int chipSelect = 53; //waar de chip heen schrijft. bij een arduino uno is dit pin 10, MEGA is dit pin53
int val = 0;
int currentState = 0;
int previousState = 0;
long counter = 0;
long countertest = 0;
String dataString = "";
void setup () {
pinMode(button, INPUT);
Serial.begin(9600);
pinMode(53, OUTPUT);
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return;
}
myFile = SD.open("datalog.txt");
if (myFile) {
//Serial.println("datalog.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
countertest = myFile;
}
// close the file:
myFile.close();
} else {
Serial.println("error opening test.txt");
}
Serial.print("\n");
Serial.println(countertest);
}
void loop () {
counter = countertest;
val = digitalRead(button);
if (val == HIGH) {
currentState = 1;
}
else {
currentState = 0;
}
if (currentState != previousState) {
if (currentState == 1) {
counter = counter + 1;
Serial.print("real counter: ");
Serial.println(counter);
myFile = SD.open("datalog.txt", FILE_WRITE);
if (myFile) {
myFile.println(counter);
myFile.close();
// print to the serial port too:
}
else {
Serial.println("error opening datalog.txt");
}
}
previousState = currentState;
delay(50);
}
}