B4A Library UsbSerial library 2.0 - supports more devices

agraham

Expert
Licensed User
Longtime User
Which "install instructions" are giving you trouble? This library installs like any other library by moving the jar and the xml file to your Additional Libraries folder, though I have just noticed that there is a typo in the Readme.txt file where jars is plural rather than singular - a hangover from the original UsbSerial library where the drivers were in a separate jar file.
 

jimTaylor

Member
Licensed User
Longtime User
Tried to run before I could walk

I backed up to the beginning and started the b4a beginners guide again. I never created the Additional Llibraries folder, so I couldn't find a place to put the stuff.

I installed it and tried the example. when I click on btnOpen I get

RuntimeException: Cannot parse: 0 as boolean.

Another problem: I am connected to my tablet with a USB cable, but I see nothing on the screen. The action is all on the virtual tablet, not the real one.
 

jimTaylor

Member
Licensed User
Longtime User
Still having problems

I just plugged my phone into a USB port on the tablet. The tablet tried to charge my phone and download my pictures, so it seems to me that the tablet thinks it's a USB host. My phone thinks so, too, because it said it was receiving power from the tablet.

I have a USB-to-serial cable plugged in to the other USB port on the tablet, with a loop-back plug at the serial port end. I know the converter is good, because I have been using it to talk to my serial devices from my PC. What I am trying to do is use the tablet to control the devices instead of the PC. The PC code is in VB, so I figured it would be a piece of cake to move the project to b4a, but I'm have a rough time getting past step one.

Assuming I can find a way to make this work, does the Android USB-to-serial code have a way to set the parameters of the link? The VB code I'm running, and the hardware I'm controlling, would like to run at 115200 baud.

Thanks for your help. I need it, if only to make me stop and think about what I'm doing.
 

jimTaylor

Member
Licensed User
Longtime User
Error on Open

I have an FTDI USB-to-Serial cable connected. The usb.RequestPermission() function work as described, and usb.DeviceInfo() returns

Manufacturer: FTD
Product: TTL
Serial: FTG

DeviceName: /dev/bus/usb/001/006
DeviceClass: USB_CLASS_PER_INTERFACE
DeviceSubClass: 0
DeviceID: 0x3EE
ProductId: 0x6001
VendorID: 0x403

B4aInterfaceNumber: 0
InterfaceClass: USB_CLASS_VENDOR_SPEC
InterfaceSubClass: 255
InterfaceProtocol: 255

plus a whole lot of other information about endpoints.

Then the program hangs up at the same place it did before, only now instead of complaining that it can't interpret 0 as boolean, it says the same about 1.

Any suggestions?
 

agraham

Expert
Licensed User
Longtime User
Are you using the unmodified demo from the UsbSerial2.3.zip archive and not an earlier version for the original UsbSerial library? It looks suspiciously like a test for successfully opening the port might be expecting a Boolean return from Usb.Open which was changed to return an Int in UsbSerial2.
 

jimTaylor

Member
Licensed User
Longtime User
Error opening USB port

I re-downloaded the usbSerial 2.3 package, replaced the jar and xml files in my additional libraries folder, and put the files and objects folders and the b4a file in a new folder. The I fired up the bridge and tried to run the program. With a little prodding I got it installed and started.

The Start and Exit buttons have bright text, the Stop and Send buttons are grey on grey, hard to see. When I click on Start, I get a display of the USB Device Information, which says, basically, that the provenance of the device is unknown, but it has three endpoints, one for interrupts and two for bulk transfer. Tapping OK at the bottom of the DI list returns to the initial state, and adds "Error opening USB port" to the log.

I replaced the FTDI serial cable with one I got from RadioShack. The DI listing showed different packet sizes, but was otherwise the same. When I disconnected one cable and attached the other, the log added "Activity (main) Pause," "Activity (main) Resume," "Checking permission," "Error opening USB port," and "Checking permission." When I tapped "OK," it added "Error opening USB port" and returned to the initial state.

For my third try I used a USB to RS485 converter from USConverters. It just worked, reporting "Connected successfully" and three copies of "NewData" and "abcde"

Now to figure out why it loves the FTDI chip in the USConverters part and hates the two RS232 cables.

Thanks immensely for you patience and help!
 

Bill

Member
Licensed User
Longtime User
michw to determine is your goclever capable of working with this library go to the google market and install "usb host diagnostics".
Thank you so much for that I have been trying to get the sample basic for android usb application to run for days duuuh.... one run of USB host diagnostics said found a problem do you want to fix it...and it did, didn't tell me what it was though, but the app works now so....Yeahhh!
 
Last edited:

Gaver Powers

Member
Licensed User
Longtime User
I read in this thread where others have had success at connecting an Android Device to an Arduino UNO board. Could someone please share what cable they used for the connection? My Arduino does not have the standard USB female connector on the board - Mine is more like a printer usb connector. So... I'm thinking the OTG cable will not work for connecting between the two.

I'm trying to connect a Samsung Galaxy Tab 7 to the Arduino.

UPDATE: For others that might be following this thread in an attempt to connect an Arduino UNO to a Samsung Tablet. The standard OTG Cable mentioned through out this thread is not compatible with the Samsung Tab 2 - 7 or 10 inch tablets. It's also unclear if the 8 Gigs of memory is adequate to store the program or if an SD card is still required.
 
Last edited:

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
help...
sorry for the lame question but i am really in a "needy" situation...

can this library be used to READ data from the audio jack ?
what i am looking for (urgently) is to be able to read a magnetic card using a reader attached to the audio jack.
i have the reader but can't read the swipped card
anyone ?
thanks
 

jcrouchley

New Member
Licensed User
Longtime User
This is a great library and as of 2.3 it supports my TI CC1111 based devices. Only one issue - I seem to get all my data twice. I am using the UsbSerialDemo code with the addition of
usb.SetCustomDevice(usb.DRIVER_CDCACM,0x0451,0x16A6)
I am getting two calls into Astreams_NewData for every packet with exactly the same data. A separate (PC based) monitor is showing the data correctly.
Any ideas?
 

jcrouchley

New Member
Licensed User
Longtime User
OK Modified the demo app to log to a label instead and it is OK - so must be something to do with logging. No longer an issue for me.
 

Thuong

Member
Licensed User
Longtime User
Good job !!! thank
I can connect Android tablet ONDA Vi60 to Arduino UNO r3
 

Thuong

Member
Licensed User
Longtime User

The fist , you should have OTG cable (has USB A female)
Second, you check USB host API is presented on your Samsung Galaxy Tab 7 (by USB host diagnostic from google store). Your galaxy should has USB Host full support
simple, you plug OTG cable to Galaxy Tab ---> to "printer" USB cable ---> to Arduino UNO
 
D

Deleted member 103

Guest
The example "UsbSerialDemo" runs correctly on my Nexus 7 (Android 4.3), which means the USB device is recognized.
On a Samsung GT-P5110 (Android 4.1.2) but is only the error message "No USB device or accessory detected".
What can it be?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…