Android Question help me about FelUSBSerial library

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
B4X:
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
B4X:
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
 

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
 
Upvote 0

Dinh Huy Cuong

New Member
Licensed User
hi erel, please help me this code
B4X:
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
 
Upvote 0
Top