problem with data transmission
in
Core Library Questions
•
7 months ago
This is a part of a program i am writing. processing is working with arduino, that send on serial a string with millis(), the data that is read from his distance sensor and a value that indicate what sensor is connected to arduino.
It seems that there is a loss of data during the transfer because tre program give me an "ArrayOutOfBoundsExceptions" when i call lettura[2]. someone can help me?
float letturaSpazio=0;
float letturaTempo=0;
String[] lettura=new String[3];
void acquisizione()
{
String myString = null; //string that read the data form Arduino
if (porta.available() > 0)
{
myString = porta.readStringUntil(10); //read until new line
if (myString != null)
{
lettura= split(myString,':'); //split the values of time, distance,and the type of the sensor in an array
if(gira==1) //if the program is going
{
letturaTempo=float(lettura[0]); //save the time into a float global
letturaSpazio=float(lettura[1]); //save the distance into a float global
}
println(int(lettura[2])); //ERROR
porta.clear();
}
}
}
It seems that there is a loss of data during the transfer because tre program give me an "ArrayOutOfBoundsExceptions" when i call lettura[2]. someone can help me?
float letturaSpazio=0;
float letturaTempo=0;
String[] lettura=new String[3];
void acquisizione()
{
String myString = null; //string that read the data form Arduino
if (porta.available() > 0)
{
myString = porta.readStringUntil(10); //read until new line
if (myString != null)
{
lettura= split(myString,':'); //split the values of time, distance,and the type of the sensor in an array
if(gira==1) //if the program is going
{
letturaTempo=float(lettura[0]); //save the time into a float global
letturaSpazio=float(lettura[1]); //save the distance into a float global
}
println(int(lettura[2])); //ERROR
porta.clear();
}
}
}
1