average of data read from sd card

Is it possible to calculate the average of the data read from the SD card? The average should be calculated in the code itself, and should be displayed in the serial monitor. Please help!

Is it possible to calculate the average of the data read from the SD card?

That depends on what the data looks like.

If the file contains:

The two main browsers at the time were Microsoft’s Internet Explorer and Netscape Navigator. This meant that not only did developers have to be cognizant of the browser type to which they were outputting HTML, but they also had to take into account which versions of those particular browsers might be making a request to their application. Some developers resolved the issue by creating two separate applications. When an end user made an initial request to the application, the code made a browser check to see what browser type was making the request. Then, the ASP page would redirect the request down one path for an IE user or down another path for a Netscape user.

the average of that will be rather meaningless.

The average should be calculated in the code itself

Well, that goes without saying, I would think...

Please help!

With what, specifically? Do you have an SD card reader connected? Can you initialize it? Can you read a file that is on it? Can you recognize just what constitutes a number? Can you convert that string to an int or a float? Can you add the resulting value to another variable? Can you divide two numbers? Can you print to the Serial Monitor?

The data can be displayed in the serial monitor. But how to make the Arduino board to understand which data are integer type, which are floating type and which are character type while reading from the SD card

But how to make the Arduino board to understand which data are integer type, which are floating type

Does it matter? If the file contains numbers, and some of the numbers have decimal points while others don't, that won't affect the average.

If it does matter, there's a hint up there.

Is it possible for ATMEGA328 to read data and from those data to calculate the average of some particular floating type data?

Yes

Is it possible for ATMEGA328 to read data and from those data to calculate the average of some particular floating type data?

Yes. Then, you can compare the result to what you read from a floating pin.

Did you have a specific question?
Some sample data?
Some code that shows you made some effort?

shashsp47:
Is it possible for ATMEGA328 to read data and from those data to calculate the average of some particular floating type data?

When you read data from an SD card you just read bytes. What those bytes actually mean is up to you and your code. The byte can be:-

  1. A byte value from 0 to 256.
  2. A char representing an ASCII character.
  3. One of two bytes making up a 16 bit signed or unsigned integer, even then you have to know if it stored as big endian or little endian. Endianness - Wikipedia
  4. As in 3 but a four byte integer number
  5. As in 4 but a eight byte integer number
  6. One byte of a 4 byte floating point number
  7. One byte of a 6 byte floating point number
    8 ) An op code representing a machine code instruction or part of a machine code instruction.

And their are more options than this. Their is nothing stored that tells you what type of data type you have. You have to know this in advance.
Their are formats that include definitions of the data in them, like the Jason format, but unless you know the format of the file you are reading and how to handle it then you are back to square one and the data you read could be anything.

#include <SPI.h>
#include <SD.h>

File myFile;

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
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
//  myFile = SD.open("test.txt", FILE_WRITE);
//
//  // if the file opened okay, write to it:
//  if (myFile) {
//    Serial.print("Writing to test.txt...");
//    myFile.println("testing 1, 2, 3.");
//    // close the file:
//    myFile.close();
//    Serial.println("done.");
//  } else {
//    // if the file didn't open, print an error:
//    Serial.println("error opening test.txt");
//  }

  // re-open the file for reading:
  myFile = SD.open("CO.txt");
  if (myFile) {
    Serial.println("CO.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}


this is my data

Looks more like "code" than "data" to me, but then "code" is of course a special case of "data". Now how to take the average of this kind of data I don't know. Use the ASCII codes maybe?

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }

Read ASCII data from the file, character by character, and send binary data to the Serial Monitor app (that expects ASCII data). Do not store the data anywhere, so that it can be used for anything.

Not really useful, IMHO.