B4J Question [IOT] Connect Raspberry pi and Arduino - Solved ! (but not Orangepi)

derez

Expert
Licensed User
Longtime User
Arduino has many sensors while RPi is somehow limited, while RPi can run server tasks, so I decided to use them both - Arduino will send the results of its program to the RPi using the USB cable using Serial print commands and the RPi will use the data as a server.
Implementation was not so simle...
I looked at Erels RPXBee example https://www.b4x.com/android/forum/t...ation-between-android-and-raspberry-pi.62564/ and copied the part of getting the serial port and the stream:
B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private AST As AsyncSteamsText
    Private serial As Serial
End Sub

Sub AppStart (Args() As String)
    serial.Initialize("serial")
    Log($"Serial ports: ${serial.ListPorts}"$)
    serial.Open("/dev/ttyUSB0" )
    AST.Initialize(Me, "AST", serial.GetInputStream, serial.GetOutputStream)
    Log("serial port is open")
    StartMessageLoop
End Sub

Private Sub AST_NewText (Text As String)
    Log(Text)
End Sub

Connected the Pi and Arduino and ran the program, got these logs:
Waiting for debugger to connect...
Program started.
Serial ports: [/dev/ttyUSB0]
serial port is open
but no data came to the AST_NewText
Any idea what the problem is ?

Edit: Sorry, it was just a typo in the Arduino's sketch. It works !
 
Last edited:

derez

Expert
Licensed User
Longtime User
I can't get it to work on my OrangePi .
Using ttyS0 because it is the result of serial.ListPorts
I use 115200 baud in the Arduino because of this
root@orangepi:~# ps -es | grep tty
...
0 2391 0000000000000000 0000000000000000 0000000000000006 0000000000000000 Ss+ ttyS0 0:00 /sbin/getty -L ttyS0 115200 vt100HOME=/ TERM=linux PATH=/sbin:/usr/sbin:/bin:/usr/bin SHELL=/bin/sh RUNLEVEL=2 PREVLEVEL=N CONSOLE=/dev/console INIT_VERSION=sysvinit-2.88
...
port is open but no data :(
How can I change the port to listen at 9600 ?
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
It did not help. I checked several rates in both sides. Problem is the same - no data.
Checked with B4R - with RPi and (even) chinese UNO it works (using ttyUSB0), with OPi - no.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
At least I'm not the only one having this problem, and now I know it is not something I did wrong ... : http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=1070

Running lsusb command when the arduino is connected to a usb port, I get this:
Bus 002 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
The device number is changed if I change the usb port.
Which shows that the arduino is sensed by the pi. Since using port ttyS0 is not working, maybe something in the above quote can tell what to use ?
The ID ?
Edit: ttyS0 is the same as com1 in the pc and appears even when the arduino is not connected. It is for sure the wrong port to set.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
I'm here again with the same problem - this time with a USB GPS receiver.
It works with RPi using USB0 port but in the Orangepi there is no such port.
I get the device listed as "Bus 002 Device 005.." with its ID but which port (from the tty list) it is ?
the list of ports in the application shows only ttyS0 which is not the required port.
Has anyone found the solution ?
 
Upvote 0
Top