Android Question help me about FelUSBSerial library

Discussion in 'Android Questions' started by Dinh Huy Cuong, Apr 29, 2019.

  1. Dinh Huy Cuong

    Dinh Huy Cuong New Member Licensed User

    hi everyone
    i'm new B4A, I want connect my tablet android with my arduino board
    i find a FelUSBSerial libray and use it,it worked , but i have 1 problem: My arduino board send 1 number increase, my tablet receive a number with "3" in top
    my arduino code is
    Code:
    unsigned int a = 0;
    void setup() {
      // put your setup code here, 
    to run once:
    Serial.begin(115200);
    }

    void loop() {
      // put your main code here, to run repeatedly:
    Serial.print(a);
    delay(1000);
    a++;
    }
    and my b4a code is
    Code:
    Private Sub serial_DataAvailable (Buffer() As Byte)
        LblReceive.Text=
    ""
        LblReceive.Text= bc.StringFromBytes(Buffer,
    "UTF8")
        
    'Log("New data: " & Buffer)
    End Sub


    Sub BtnDisConnect_Click
        
    End Sub

    Sub BtnConnect_Click
        
    If manager.GetDevices.Length = 0 Then
            
    Log("No connected usb devices.")
        
    Else
            
    Dim device As UsbDevice = manager.GetDevices(0'assuming that there is exactly one device
            If manager.HasPermission(device) = False Then
                
    ToastMessageShow("Please allow connection and click again."True)
                manager.RequestPermission(device)
            
    Else
                usb_Serial.Initialize2(
    "serial", device, -1,"CH34xSerialDevice")
                usb_Serial.BaudRate = 
    115200
                usb_Serial.DataBits = usb_Serial.DATA_BITS_8
                usb_Serial.StartReading
            
    End If
        
    End If
    End Sub
    when arduino send "1", tablet receive "31"
    when arduino send "15, tablet receive "315"
    i can slipt the string, but i don't want do that, please help me how can i receive
    exactly what arduino send.
    thank you very much
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Moved to the questions forum.

    Note that you can use B4R to program the Arduino. It will be simpler once you want to send more complicated stuff.

    What is the output of Log(bc.HexFromBytes(Buffer)) ?
     
  3. Dinh Huy Cuong

    Dinh Huy Cuong New Member Licensed User

    thank erel
    i'm just join today, i will download and change to use B4R,
    Log(bc.HexFromBytes(Buffer)) result : send 1 -> 31, send 2 -> 32, send 11 -> 3131

    and i find out where i'm wrong, i miss delare stopbit and parity mode

    usb_Serial.StopBits = usb_Serial.STOP_BITS_1
    usb_Serial.Parity = usb_Serial.PARITY_NONE
    after that, it receive exacly ,
    thank you
     
  4. Dinh Huy Cuong

    Dinh Huy Cuong New Member Licensed User

    hi erel, please help me this code
    Code:
    Sub btnSend_Click
        
    Dim temp As Byte
        temp = bc.StringToBytes(txtSend.Text,
    "UTF8")
        
    Log("Send " & txtSend.Text & " " & temp)
        usb_Serial.Write(temp)
    End Sub
    i want send a string to aduino with this code , but log show
    can't cast type:{type = byte,rank = 0, remote = true} to {type = byte , rank =1, remote = true}
    how can i fix it and send a string to arduino
    thank you
     
  5. Dinh Huy Cuong

    Dinh Huy Cuong New Member Licensed User

    I Solved all, thank you
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice