TY for your help, but I've still problems of conversion.. ![]()
In fact my file "Test.txt" contains 3digit-numbers from 0 to 255, like this :
"076;234;145;024;245;ect..."
Here is your code that I adapted.
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char name[] = "Test.txt"; // name of the file n my SD card
char inData[1000];
byte index;
void setup()
{
Serial.begin(9600);
// Etc...
}
void loop()
{
file.open(root, name, O_READ); //Open the file in read mode.
char inChar=file.read(); //Get the first byte in the file.
while(inChar >0){
char inChar = file.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 999)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
}
We are here because all pending serial data has been read , does it change something in the code ?
if(started && ended)
{
// Process the packet = Segment + store in an array + convert to int ?
// segmentation
char *token;
token = strtok (inChar, ";");
// creation of an array (3 digit-numbers)
int a;
char array[3]= {0};
how to store "token" in this array ? does "a=sprintf(array,token)" is correct ?
int a = atoi (array);
and how to convert them one by one ?
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}