READING SD CARD DATA and parse 6 diff data

hii...thanks for reading my post..

my project was to extract this notepad data into six different values on every 20 ms delay...i tried to use sub string commands but data was not parsing proberly...please guide me to go further....
text file 2 is data..and i have attached my progress program also...

/*
  Servo position playback
  servo-playback.ino
  Plays back servo movements from SD card
  Used with servo-record.ino
  Displays results on Serial Monitor
  DroneBot Workshop 2019
  https://dronebotworkshop.com
*/

// Include libraries



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



String angle; //data String
String fuel;
String fuels;
String speed1;
String altidude;
String altidude1;

int ind1; // , locations
int ind2;
int ind3;
int ind4;
int ind5;
int ind6;
 

// CS pin for SD Card Module
const int chipSelect = 10;

// String to hold one line of text
String buffer;

// Create a Servo object
Servo myservo;
Servo myservo1;
Servo myservo2;

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...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  // Attach servo on pin 9 to the servo object
  myservo.attach(9);
  myservo1.attach(6);
  myservo2.attach(5);
 

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("2.txt");


  // If the file is available, read it
  if (dataFile) {
    while (dataFile.available()) {
      // Write one line to buffer
      buffer = dataFile.readStringUntil('\n');
      // Print to serial monitor

      ind1 = buffer.indexOf(' ');  //finds location of first ,
     // angle = buffer.substring(0, ind1);   //captures first data String
      angle = (buffer.substring(0,8));
      //ind2 = buffer.indexOf(' ', ind1 );   //finds location of second ,
      fuels = buffer.substring(16,24);
      ind3 = buffer.indexOf('        ');
      fuel = buffer.substring(32,40);   //captures second data String
      ind4 = buffer.indexOf('8', ind2+0 );
      speed1 = buffer.substring(48,56);
      ind5 = buffer.indexOf('8', ind3+1 );
      altidude = buffer.substring(64,72); //captures remain part of data after last ,
      altidude1 = buffer.substring(80,88); //captures remain part of data after last ,

      //Serial.println(buffer);

      Serial.print("angle = ");
      Serial.println(angle);
      Serial.print("fuels = ");
      Serial.println(fuels);
      Serial.print("fuel = ");
      Serial.println(fuel);
      Serial.print("speed = ");
      Serial.println(speed1);
      Serial.print("altidude = ");
      Serial.println(altidude);
      Serial.print("altidude1 = ");
      Serial.println(altidude1);
      Serial.println();
      Serial.println();
      delay(10);

      
      // Convert string to integer and position servo
      myservo.write(angle.toInt());
      delay(15);
      myservo1.write(fuels.toInt());
      delay(15);
      myservo2.write(altidude.toInt());
      delay(15);

    }
    dataFile.close();
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening servopos.txt");
  }
}

void loop() {
}

program.ino (3.26 KB)

2.txt (2.73 KB)

Read the first topics telling "How to use thid Forum", "How to attach code" etc.
Whst is the question?

Your text file has columns separated by tabs but you're looking for eight spaces instead. That's likely defeating your parsing.

hii...thanks for correcting me...i thought it was space...its tab actually...but still problem not solved...please see my data file fully...wen all six data available there is no tab between them...

What character is between them then?

If data is there it’s showing 8 lines number or else zero only....please check tat 2.txt files data

Your data is separated by tabs, and each line ends with a carriage return and newline, except for the final line.
The file begins with a carriage return and newline, essentially a blank line.

0000000  \r  \n   4   .   0   4   4   4   1  \t   0  \t   4   .   2   2
0000010   2   0   1   4  \t   0  \t   0  \t   0  \r  \n   4   .   0   4
0000020   4   4   1  \t   0  \t   4   .   2   2   2   0   1   4  \t   0
0000030  \t   0  \t   0  \r  \n   4   .   0   4   4   4   1  \t   0  \t
0000040   4   .   2   2   2   0   1   4  \t   0  \t   0  \t   0  \r  \n
0000050   4   .   0   4   4   4   1  \t   0  \t   4   .   2   2   2   0
0000060   1   4  \t   0  \t   0  \t   0  \r  \n   4   .   0   4   4   4
0000070   1  \t   0  \t   4   .   2   2   2   0   1   4  \t   0  \t   0
0000080  \t   0  \r  \n   4   .   0   4   4   4   1  \t   0  \t   4   .
0000090   2   2   2   0   1   4  \t   0  \t   0  \t   0  \r  \n   4   .
00000a0   0   4   4   4   1  \t   0  \t   4   .   2   2   2   0   1   4
00000b0  \t   0  \t   0  \t   0  \r  \n   4   .   0   4   4   4   1  \t
00000c0   0  \t   4   .   2   2   2   0   1   4  \t   0  \t   0  \t   0
00000d0  \r  \n   4   .   0   4   4   4   1  \t   0  \t   4   .   2   2
00000e0   2   0   1   4  \t   0  \t   0  \t   0  \r  \n   4   .   0   4
00000f0   4   4   1  \t   0  \t   4   .   2   2   2   0   1   4  \t   0
0000100  \t   0  \t   0  \r  \n   4   .   0   4   4   4   1  \t   0  \t

The code you posted seems to be searching for the delimiter (space in the case of the original code, should be tab), but then ignores where that is found and instead takes a substring from a fixed position.

wen all six data available there is no tab between them...

All lines have tabs between the data.
This is your data with all tabs replaced with commas for clarity:

4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.04441,0,4.222014,0,0,0
4.043404,0,4.241423,0,0,0
4.042443,0,4.224444,0,0,0
4.042244,0,4.214344,0,0,0
4.04444,0,4.204434,0,0,0
4.041444,0,4.204442,0,0,0
4.044042,0,4.214343,0,0,0
4.044234,0,4.242424,0,0,0
4.044244,0,4.204341,0,0,0
4.044434,0,4.211444,0,0,0
4.134443,0,4.214041,0,0,0
4.042444,0,4.144431,0,0,0
4.043434,0,4.20444,0,0,0
4.043404,0,4.14104,0,0,0
4.044444,0,4.222444,0,0,0
4.041422,0,4.21434,0,0,0
4.042032,0,4.233304,0,0,0
4.044414,0,4.214444,0,0,0
4.042244,0,4.20401,0,0,0
4.043444,0,4.224442,0,0,0
4.040044,0,4.223441,0,0,0
4.044412,0,4.143441,0,0,0
4.044223,0,4.144404,0,0,0
4.042103,0,4.144401,0,0,0
4.044042,0,4.144441,0,0,0
4.044444,0,4.214201,0,0,0
4.044122,0,4.144244,0,0,0
4.043014,0,4.200043,0,0,0
4.044443,0,4.144441,0,0,0
4.044443,0,4.221444,0,0,0
4.040404,0,4.211444,0,0,0
4.044141,0,4.224144,0,0,0
4.042434,0,4.244441,0,0,0
4.04431,0,4.204344,0,0,0
4.044433,0,4.203404,0,0,0
4.041444,0,4.231441,0,0,0
4.411442,0,4.244442,0,0,0
4.044244,0,4.224442,0,0,0
4.041244,0,4.214133,0,0,0
4.044444,0,4.144444,0,0,0
4.044204,0,4.244403,0,0,0
4.044421,4.213013,4.204404,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.213013,0
0,4.213013,0,0,4.032404,0
0,4.213013,0,0,4.044214,0
0,4.213013,0,0,4.030212,0
0,4.213013,0,0,4.03414,0
0,4.213013,0,0,4.044044,0
0,4.213013,0,0,4.033422,0
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.043142
0,4.213013,0,0,0,4.0431

thanks guys...now my code working after replacing with tab delim....@david_2018 which tool u used to know the data delim viewer...in future its useful for me to avoid this mistakes...