Using kivy-android-serial

794 views
Skip to first unread message

Yves Surrel

unread,
Nov 14, 2018, 5:14:48 PM11/14/18
to Kivy users support
Hi all

I want to have some GPIO capabilities from my Android device, and a possible solution seems to use an Arduino board. So I need to have serial communication.
In the Installing section of  kivy-android-serial , it is stated: 

4-Add device_filter.xml to your android res/xml/ folder

It is not clear where is supposed to be this android res/xml/ folder. I tried in ~/.buildozer/android/platform/android-sdk-20/platforms/android-19/data/res/xml and ~/.buildozer/android/platform/android-sdk-20/platforms/android-24/data/res/xml because I have these two directories but I always get an error message Error: No resource found that matches the given name (at 'resource' with value '@xml/device_filter') when buildozering.

Also, it is also stated 

5-Add <uses-feature android:name="android.hardware.usb.host" /> to your AndroidManifest.xml

Here too, it is not clear where is this file.

Any idea for these points?

QuanTech

unread,
Nov 15, 2018, 7:25:51 PM11/15/18
to Kivy users support
Adding USB host function is somewhat tricky.
You probably need to build it twice.
When first build show that error, it is all right. That's when the "res" folder is generated in your project.
Then find it in your project's ".buildozer" folder (not in your home folder).
Add "xml/device_filter.xml" in "res" folder. Note that you need to create "xml" folder manually.
Then in your project folder find a folder like this, depending on your project name: ".buildozer/android/platform/build/dists/YOUR_PROJECT_NAME/templates/".
Add <uses-feature android:name="android.hardware.usb.host" /> at a good position in the file named AndroidManifest.tmpl.xml
Then build again. If you are lucky, it should build without that error.

Good Luck!

Yves Surrel

unread,
Nov 16, 2018, 8:16:23 AM11/16/18
to kivy-...@googlegroups.com
Thank you so much, I followed your instructions and the compilation worked OK.

More precisely, for those who may be interested, among many res folders in the project .buildozer directory, the good one is
<project_dir>/.buildozer/android/platform/build/dists/<project>/src/main.

Now I will check the execution ;-)

Yves


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/31be0062-88fd-4983-b062-925cbb824b98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yves Surrel

unread,
Nov 16, 2018, 11:14:30 AM11/16/18
to Kivy users support
After experimenting the execution, I still cannot use the serial port.

When the Arduino is not connected, at the line 'self.s = CdcAcmSerialPort('/dev/ttyACM0', 9600)', I have the exception 'Device not present /dev/ttyACM0'. No surprise.
When it IS connected, I get 'Failed to open device', meaning I think that /dev/ttyACM0 exists but there is some problem.
Note that 'Serial USB Terminal' app can connect to the Arduino without problem.
Some permission problem? How could I get more details about that (logical doesn't show anything interesting)

QuanTech

unread,
Nov 17, 2018, 10:12:27 PM11/17/18
to Kivy users support
I just had a very quick look into the kivy-android-serial project and found in device-filter.xml it specify only a very specific device to be connected.
Try in this file delete both vendor-id="5824" product-id="1155"
That makes the content in this file look like:
<?xml version="1.0" encoding="utf-8"?>

<resources>
    <!-- <usb-device vendor-id="16c0" product-id="0483" />  -->
    <usb-device />
</resources>

Make a build with this version, and this time when you connect the device to your android phone/tablet, it should prompt you for permission to connect it.
I never use Arduino, so I don't know if the usb driver is compatible with it. But anyway it doesn't hurt to try.

Good luck!

Yves Surrel

unread,
Nov 20, 2018, 5:47:00 PM11/20/18
to kivy-...@googlegroups.com
Jack

You were right to look into device-filter.xml. After the change you suggested, it behaved as you said, I am prompted to choose between my app and « Serial USB Terminal » for the connection.

However, I am still not through. The port opens OK (although I had to add a missing self.is_open = True at the end of the open() procedure in driver.py), but I get a timeout error (I guess, as there is only a -1 return code after 1s) when writing, coming from self._connection.bulkTransfer() in the serial port class CdcAcmSerialPort.
There is no hardware handshake enabled by default, my baud rate is the standard 9600, and I am just trying to send a single character:

        if self.serial_port is not None:
            try:
                self.serial_port.write('a') # also tried self.serial_port.write(b'a')
            except Exception as e:
                self.parent.label.text =  str(e)

Thanks for any other idea...


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.

QuanTech

unread,
Nov 21, 2018, 7:39:55 PM11/21/18
to Kivy users support
Hi Yves,

Could you get the vendor id and product id when connecting to your Arduino board?
You can get these info by using Serial USB Terminal, (Upper left menu->USB device)

Yves Surrel

unread,
Nov 22, 2018, 2:35:37 AM11/22/18
to kivy-...@googlegroups.com
The vid is 9025 (arduino.cc) and the pid is 67.

May this have an incidence ???

QuanTech

unread,
Nov 22, 2018, 4:45:16 PM11/22/18
to Kivy users support
Some posts from internet say Arduino could use either FTDI or CDC driver. I'd just like to double check this.
FTDI usb devices always have 1027(0x0403) as vendor id(VID). Since your board's VID is something else, CDC should be the right driver.
And you can connect your board with the name "ttyACM0", this also suggests CDC is the right driver.
In this case there could be bug in the driver itself(driver.py) or something beyond my knowledge.

Yves Surrel

unread,
Nov 24, 2018, 9:51:42 AM11/24/18
to kivy-...@googlegroups.com
Hurray, the thing is now working OK. There were actually some bugs in driver.py of kivy-android-serial.

First, I had to add the two lines

self.is_open = True
self._reconfigure_port()

at thé end of the CdcAcmSerialPort.open() method, because if you look at the SerialBase__init__ procedure CdcAcmSerialPort is subclassing, you see that the baudrate, parity etc. are set via setters that run _reconfigure() only if is_open is True.

Second, I had to add 

timeout = int(self._timeout if self._timeout else self.DEFAULT_TIMEOUT)

and replace self._write_timeout by timeout in the following call to self._connection.bulkTransfer, because self._write_timeout defaults to None, which is not accepted as an argument of connection.bulkTransfer.

QuanTech

unread,
Nov 25, 2018, 5:01:37 PM11/25/18
to Kivy users support
Congratulations Yves!
Very glad to hear your success! I'm also considering writing some simple library to make Android USB serial easier. But I can only do it in my spare time, don't expect that happens in a quick manner.

Samuel Loury

unread,
Nov 27, 2018, 5:44:05 AM11/27/18
to Yves Surrel, kivy-...@googlegroups.com
Hi,

Yves Surrel <y.su...@gmail.com> writes:

> Hurray, the thing is now working OK. There were actually some bugs in
> driver.py of kivy-android-serial.

Could you please submit a pull request ?

I also used to play with a couple android/arduino. I did not know about
kivy-android-serial so I reinvented the wheel. Next time I need to play
with android/arduino, I would love to try kivy-android-serial, with your
correction.

My two cents,
--
Konubinix
GPG Key : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE 5C36 75D2 3CED 7439 106A
signature.asc

QuanTech

unread,
Nov 28, 2018, 4:33:30 AM11/28/18
to Kivy users support
Hi Yves and Samuel,

Just for your information.
I just started a project for Android USB Serial. If you are interested, have a look at https://github.com/jacklinquan/usbserial4a
I only have a FTDI device at hand. So for the moment it only supports FTDI USB serial device.
More are coming when I get other devices.

Samuel Loury

unread,
Nov 29, 2018, 2:44:54 AM11/29/18
to QuanTech, Kivy users support
QuanTech <jackl...@gmail.com> writes:

> Just for your information.
> I just started a project for Android USB Serial. If you are interested,
> have a look at https://github.com/jacklinquan/usbserial4a
> I only have a FTDI device at hand. So for the moment it only supports FTDI
> USB serial device.
> More are coming when I get other devices.

Thank you for sharing :-)
signature.asc
Reply all
Reply to author
Forward
0 new messages