0
votes

I'm trying to send Arduino ADC data to android tablet using USB serial Communication. I'm using Serial.println() at arduino side. My Issue is that I'm not able to Decode the data received at the android end.
For Eg. Suppose I send Serial.println(768) from arduino, I check my android receive buffer and it Shows (55,54,56,13,10).

How can i decode this data back to 768 value?

2

2 Answers

1
votes

Looking into an ASCII table you'll find that

55,54,56,13,10

represents

"768\n\r"

Most programming languages provide means for conversion between byte values and characters/strings with their string libraries. So you don't have to implement the decoding yourself.

Refer to https://howtodoinjava.com/array/convert-byte-array-string-vice-versa/

or UTF-8 byte[] to String

or anything else you find online for "byte to string Android"

0
votes

String rawdata = " " ; String finaldata = " "; UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read. @Override public void onReceivedData(byte[] arg0) {

        byte[] buffer = arg0;
        for (i =0;i <=(buffer.length-1);i++) {
         if(buffer[i]!= 13) {
             if(buffer[i]== 10){
                 finaldata = rawdata;
                 rawdata = "";
             }else {
                 chdata = (char) buffer[i];
                 rawdata += chdata;
             }
         }

      }

            data = Integer.parseInt(finaldata);

}