I'd like to connect an Arduino Uno by USBAccesory and read data.
Anyone could post a sample code on connecting a USBAccesory?
I don't know if this is the way:
:sign0085:
Anyone could post a sample code on connecting a USBAccesory?
I don't know if this is the way:
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim accesories() As UsbAccessory
Dim manager As UsbManager
Dim indexArduino As Int
Dim timer1 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime = True Then
Activity.LoadLayout("main")
manager.Initialize
accesories = manager.GetAccessories
For a = 0 To accesories.Length - 1
If accesories(a).Description = "Arduino UNO" Then
indexArduino = a
End If
Next
Label1.Text = accesories(indexArduino).Description
Label2.Text = accesories(indexArduino).Manufacturer
Label3.Text = accesories(indexArduino).Model
timer1.Initialize(1000)
End If
End Sub
Sub timer1_tick
Label4.Text = accesories(indexArduino).InputStream
End Sub
:sign0085:
Last edited: