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)