followed this (EXITING) thread. Did setup an RPi and ran successfully first simple B4A test apps.
Next wanted to connect an Arduino to the RPi to send data in both ways using SoftwareSerial:
Via Serial Port: According development stage of Android Things, USB Serial Port is not yet supported.
Via SoftwareSerial: Looked at UART, which is already supported.
Question:
Are there plans to extend the B4A things library to support SoftwareSerial (via USB and/or 3-wire connection TX,RX,GND)? and use subsequently the B4XSerializer to exchange data both ways.
thanks for the updated library. Test Setup Wiring
Arduino UNO Pin 10 = RX to RPi 3 Pin 8 = UART0 TXD
Arduino UNO Pin 11 = TX to RPi 3 Pin 10 = UART0 RXD
Arduino UNO GND to RPi Pin 6 GND
Tested software serial connection between an Arduino UNO and Arduino MEGA using B4R: OK
Tested Arduino UNO to RPi 3 using B4R and B4A: No success, no data arriving (event DataAvailable).
The B4A and B4R code attached, but here the B4A code snippet showing UART setup:
B4X:
Sub Process_Globals
Private pm As PeripheralManager
Private uart As UartDevice
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
...
uart.Initialize("UART0", "uartdevice", pm)
uart.Baudrate = 57600
uart.StopBits = 1
uart.Parity = uart.PARITY_NONE
uart.DataSize = 8
..
End If
Activity.LoadLayout("Main")
End Sub
Sub uartdevice_DataAvailable(Buffer() As Byte)
Log("UART Data is available: " & Buffer.Length)
Dim bc As ByteConverter
Log("UART=" & bc.StringFromBytes(Buffer, "UTF8"))
End Sub
Performed another test by sending data from B4A using uart.write to B4R by timer (see code snippets below). Result: The data send by B4A is received by B4R asyncstreams. So the wiring is OK.
Seems the issue is with the B4A event uart DataAvailable.
B4A Code Snippet
B4X:
Sub timer1_tick
Dim state As Boolean = pin22.value
Log("Timer Tick: " & state)
pin22.value = Not(state)
Dim b As Byte
If state Then b = 1 Else b = 0
uart.Write(Array As Byte(b))
End Sub
B4R Code Snippet
B4X:
Sub astream_NewData (Buffer() As Byte)
Dim state As Boolean = Buffer(0) = 1
Log("NewData: State=",state)
led13.DigitalWrite(Not(state))
End Sub
Great - Confirmed working.
Created a testproject to display the temperature & humidity in a line chart on the Raspberry Pi from a DHT11 sensor connected to an Arduino UNO.
Attached the B4A and B4R code.
Screenshot - the data is updated every second, max 20 entries, used this B4A chart class (thanks for providing).
compiling your example I get this error:
------------------------------------------------------
B4A version: 6.50
Parsing code. (0.02s)
Compiling code. (0.06s)
Compiling layouts code. (0.01s)
Organizing libraries. (0.00s)
Generating R file. (0.09s)
Compiling generated Java code. Error
Cannot find: C:\Anywhere Software\Basic4android\libraries\androidthings.jar
--------------------------------------------------------------------------------
where can I find the missing jar file?
the library was included in the first things library version (0.9) of this post, but missing in the subsequent updates.
Pls find the things library v1.01 incl androidthings.jar.
Looking forward to hear your experience - its fun to see B4A apps running on the RPi communicating to an Arduino with sensors.
Working with sensors directly connected to the RPi3 is next on the todo list.
The Android Things peripheral drivers are in progress - look here.
... BUT need to understand how to use in B4A =would be good to have a library "thingsperipherals.jar" containing all available drivers to then (easy) use in B4A.