read SD card to fram

I have a file on SD card witch is:
6.55
6.37
6.87
6.97
7.15
7.16
10.23
12.66

And so on for 40 numbers

What I want to do is read SD card into fram array. I can read the SD card and serial print the context of the SD card.

But I can not get it into a fram.

Read_File_To_Fram.ino (4.79 KB)

    while(logFile.available())
    {
     arrayofreading[300] = logFile.read();
    }

Every time you read a character from the file, store it outside the bounds of your array. Does that REALLY seem like a good idea?

Where do you actually write to the FRAM?

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.

If you want to read a text file with each value on a line, you first read a line into a null terminated character array.

Next convert that character array to a float.

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

Create a character array of at least 4 bytes.

It need to be larger than that. OP's data shows values like 13.45, which will need a 6 element array.

Mea culpa, you're right.