Hi , is there a way to read a text file, analyze data from a line and while still reading write those analyzed lines in another file using the Sd.h lib?
Sorry about my english...
Hi , is there a way to read a text file, analyze data from a line and while still reading write those analyzed lines in another file using the Sd.h lib?
Yes.
What code do you currently have? How much available memory do you have when that code is running?
PaulS:
Yes.What code do you currently have? How much available memory do you have when that code is running?
Hi, im using 920 bytes of 2048 RAM. Its a nano. The code is for a load cell. It should read the values, write on sd, acess the file, compare lines and write the chosen values in another file. I made a function called compare() in the end of the code, but i dont know how to proceed in the final part, accessing the files compirng data and write it on SD.
Here is my code :
#include <SPI.h>;
#include <SD.h>;
File myFile;
unsigned long value = 0;
float ti;
int zeta = 0; //counter
int iota = 0; //counter
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT); //slk
pinMode(3, INPUT); // dout
digitalWrite(2, HIGH); //load cell initialization
delayMicroseconds(100);
digitalWrite(2, LOW);
myFile = SD.open("resposta.txt", FILE_WRITE);
}
void loop()
{
read();
if(zeta==0){
ti = millis();
zeta++;
}
while(iota==0){
if(value <4000000000) // a too fast reading would express a value above that number. So im excluding those kind of readings.
{Serial.print(value);
Serial.print("");
Serial.println(millis() - ti);
myFile.print(value);
myFile.print("");
myFile.println(millis() - ti);
if((millis() - ti)>=90000) // data reading time limit 1.5min.
{
iota++;
}
}
delay(40); // the minimum delay to read something
}
}
void read ()
{
uint8_t data[3] = { 0 };
uint8_t filler = 0x00;
digitalWrite(2, HIGH);
digitalWrite(2, LOW);
data[2] = shiftIn(3, 2, MSBFIRST);
data[1] = shiftIn(3 , 2, MSBFIRST);
data[0] = shiftIn(3, 2, MSBFIRST);
if (data[2] & 0x80) {
filler = 0xFF;
} else {
filler = 0x00;
}
value = ( static_cast(filler) << 24
| static_cast(data[2]) << 16
| static_cast(data[1]) << 8
| static_cast(data[0]) );
return static_cast(value);
}
void compare () //reading, processing and writing data to an SD function
{
if(iota != 0) //start function
{
// SD processing code here
}
}
Why does read() try to return a value, when the type is void?
Why do you need to return a global variable?
What do you want to read from the file, in compare()? From what file?
What do you want to write to the file, in compare()? To what file?