USB to Arduino only working in one direction

wolvo66

Member
Licensed User
Longtime User
Hi,
I’m trying to connect to an Arduino compatible via usb, the connection from Android to the Arduino works ok, but nothing in return direction – it even seems that the usb connection is blocking the Arduino from transmitting as the tx led isn’t lighting. My Arduino code is just looping back what it receives.
When I connect the Arduino to PC and use hyperterminal everything works fine, tx led lights and messages are sent from Arduino to PC.
I’m using a Nexus 7 with an on-the-go cable and AGraham’s latest usb serial library v2.3

I’ve experimented with setting driver and pid based on my configuration, but that didn’t seem to help e.g.
B4X:
    If (usb.HasPermission) Then
      usb.SetCustomDevice(usb.DRIVER_CDCACM, 0x2341,0x8036)  
      Log(usb.DeviceInfo)

I have a usb tracer, but I’m not sure what to look for e.g. I can see some differences in endpoints compared to PC case.
Any suggestions what I could try?
- Thanks!
 

agraham

Expert
Licensed User
Longtime User
Those IDs are for the Arduino Leonardo and are already recognised by the CDC ACM driver so the author of the driver thought that it would work. However! from arduino.cc
The Leonardo differs from all preceding boards in that the ATmega32u4 has built-in USB communication, eliminating the need for a secondary processor. This allows the Leonardo to appear to a connected computer as a mouse and keyboard, in addition to a virtual (CDC) serial / COM port.
I suspect that the mouse and keyboard capability may be affecting getting the right endpoints. If you can do a DeviceInfo on it and post the results there I'll take a look to see if there is anything I could do.
 
Upvote 0

wolvo66

Member
Licensed User
Longtime User
Thanks for the reply :)
Yes... I think that may be it, when the Leonardo is connected the Android keyboard is blocked from opening
Device info trace attached... yes it's recognized as a HUD.

So maybe I have to hack it from the Arduino end that it is recognized as something else than a Leonardo?
Or is there some other possible solution?

Thanks again for you help!
 

Attachments

  • usbDeviceInfo.txt
    1.4 KB · Views: 447
Upvote 0

agraham

Expert
Licensed User
Longtime User
Android claims HID devices so to use it would need a change to the Arduino to stop it being recognised as an HID device which I guess would mean suppressing the HID interface details. Other than that it looks like it should work, or to put it another way, if it doesn't work I can't see what I could change to make it work.
 
Upvote 0

wolvo66

Member
Licensed User
Longtime User
Thanks for the guidance agraham :)
I managed to suppress the HID in the Arduino as you proposed (I can see from the device info that it is not there and the Android keyboard opens - which it didn't before). SO some progress!
But still the Android doesn't receive any messages back from the Arduino. Pid and vid are as Leonardo 0x2341,0x8036, so I guess this line of code is still redundant:
usb.SetCustomDevice(usb.DRIVER_CDCACM, 0x2341,0x8036)

Then I tried changing the pid and vid in the Arduino to some random numbers e.g. 0x1111 and 0x1111
Now the Android doesn't recognize that a USB device is connected.

Still it works great with an Arduino with FTD.
Any idea what I could try next?
 
Upvote 0

Peter Gould

Member
Licensed User
Longtime User
Thanks for the information so far. I've gotten to the same point as wolvo66. I can communicate with the Arduino Leonardo chip (Atmega32U4) but I cannot receive data back. This seems particularly strange since my understanding is that USB hardware is bi-directional. It uses the same conductors to send and receive data. Why would it work in only one direction with Android?

Anyone made any additional progress on this?

***A little more on this****
I also found that none of the serial monitor programs (e.g., Termite) on my Windows machine will receive data from the Leonardo but work with the Uno. So it's not only Android. But the Arduino built-in serial monitor does work. Next step is to figure out what Arduino is doing differently.
 
Last edited:
Upvote 0

Peter Gould

Member
Licensed User
Longtime User
SOLVED
I got two-way communication with a Leonardo board (actually a variant from my company www.olympiacircuits.com that uses the same ATMega 32U4 chip). The issue seems to be that a ready-to-send signal is needed somewhere in the virtual com port. After making the connection with the device you need to set the RTS signal to True. Here's a code snippet based on the USBSerialDemo in agraham's usbSerialV2.3.
' within Sub btnOpen_Click make the USB connection and call the sub setRTS
If dev <> usb.USB_NONE Then
Log("Connected successfully!")
btnOpen.Enabled = False
btnClose.Enabled = True
btnSend.Enabled = True
setRTS
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
Else

'The sub

Sub setRTS
Dim R As Reflector
R.Target = usb
R.Target = R.getField("driver")
R.RunMethod2("setRTS", True, "java.lang.boolean")
End Sub


Cool.
 
Upvote 0
Top