This only to load the fram with data from SD card. I have a arduino uno logging data four times a day to an SD card. This program is to load a arduino mega with 56 days of data to graph for the first time. After that the arduino mega will log the data for it self. This program is only used start the the mega with past data for graphing.
I’m not soure how to make this work. All I need is to place the data from the SD card in to array. In the test data program their is forty lines of data.
3.64
3.78
3.60
12.30
13.45
and so on for 40 lines
#include <SD.h> #include <Adafruit_FRAM_I2C.h>
const int cs = 53; // 53 for mega 10 for uno
float depth;
float value;
int i;
float arrayofreading[40];
File myfile;
void setup(){
Serial.begin(19200);
pinMode(53, OUTPUT);
if (!SD.begin(cs))
{
Serial.println("Card failed to initialize");
return;
}
File myfile = SD.open("riverdep.txt"); // open the file named ourfile.txt
if (myfile) // if the file is available, read the file
{
while (myfile.available()) {
for (i=0; i< 40; ++i ) {
arrayofreading = myfile.read();
}*
myfile.close();*
} * } else {
Serial.println("Cannot open file");*
}*
delay(1000);*
for (i=0; i< 40; ++i ) { *
_ value = arrayofreading*; _
_ Serial.println(value);_
_ }_
_}*_
void loop(){ } I'm getting an output but not what is on the SD card.
Learn to post code properly using code tags.
2)
Your code in reply #3 does not compile; how can you get output?
3)
If you want to copy from SD to FRAM, you don't need an array to store 40 (all) readings; read one at a time and save to FRAM.
This is the problem I do not know how to read from an SD card. All the examples show reading then serial printing the context. That I can do, but reading the SD card getting a hold of the context to manipulate, I can not do. All of the examples and programs on the web go off in very complex programs that vary quickly lose me. All I want to do is read a SD card program and save it to a FRAM.
Try readBytesUntil(). You can find it in the reference section under Serial but it also works for files.
Create a character array of at least 4 bytes. Read a line from the file into that character array using the above function. After that, set the last byte to '\0'.
Convert using atof(); google it in case you're not familiar with it