0

I've been stuck and confused for bytes and buffer code to send a text from Arduino to Android. This is my Activity.xml (TextView)

<TextView
    android:text="Arduino Results"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="45dp"
    android:id="@+id/jarakbt"
    android:layout_below="@+id/button2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

This is some .java code that I don't understand

private void startAndroid()
{
    if (btSocket!=null)
    {
        try
        {
            btSocket.getOutputStream().write("START".toString().getBytes());
            jarakbt.setText(btSocket.getInputStream().read());
        }
        catch (IOException e)
        {
            msg("Error");
        }
    }
}

And also I provided some Arduino code

https://pastebin.com/HFsZvqtr

Arduino Serial results in picture

https://i.stack.imgur.com/xF3uA.jpg

So, I am confused. In my Arduino source code, I don't implement any bytes[] blablabla, but all Android source code that I found, implement bytes[] blablabla.

I found a simple problem and i tried it and success. It's receive Character using Android phone from arduino That source code is for character. As you can see on picture, my results is like "105.72 cm, 1.06 m" and it's not a character...

How can I appear "105.72 cm, 1.06 m" in Android TextView and automatically refresh ?

I am a newbie in Android and Arduino especially Embedded System.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nicky Puff
  • 149
  • 3
  • 14

0 Answers0