Skip to content Skip to sidebar Skip to footer

Textview Values Does Not Update When Data Received From Arduino

I receiving 3 data from Arduino and the data just keep coming in. My problem is the data doesn't update to the new received values. Here is the screenshot from the logcat: So D/

Solution 1:

Try this

1 . replace

privateStringBuilderrecDataString=newStringBuilder();

with this one

privateStringrecDataString="";

2 . replace

recDataString.append(readMessage);

with this one

recDataString = readMessage ;

Data Parsing for different-2 situations :

if(recDataString.lenth > 0){
   //If Oxiometer is OFFif(recDataString.startsWith(#00) && recDataString.length == 8){//Do Parsing here  #0028.14String BPM = "0";
     String SPO2= "0";
     String temp = recDataString.split("00")[1];

     myLabel.setText("BPM" + "  " + BPM);
     myLabel1.setText("SPO2" +"  "+ SPO2);
     myLabel2.setText("Temp"+"  " + Temp);
  }

   //If Oxiometer is on if(recDataString.startsWith(#) && recDataString.length() == 10){//Do Parsing here  #779928.08String BPM = recDataString.substring(1,3);
     String SPO2= recDataString.substring(3,5);
     String temp = recDataString.substring(5,recDataString.lenth());

     myLabel.setText("BPM" + "  " + BPM);
     myLabel1.setText("SPO2" +"  "+ SPO2);
     myLabel2.setText("Temp"+"  " + Temp); 
  }

   //If String contains # only .if(recDataString.startsWith(#) && recDataString.length == 1){//Do nothing or you can decide

  }

}

Solution 2:

Before recDataString.append(readMessage); try to reset the recDataString first, like this:

recDataString.setLength(0);

Because if it does not reset, it will continue append new strings:

#689928.0#689928.06899719928.11 ...

Post a Comment for "Textview Values Does Not Update When Data Received From Arduino"