USB to Arduino only working in one direction

Discussion in 'Android Questions' started by wolvo66, Apr 24, 2013.

  1. wolvo66

    wolvo66 Member Licensed 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.
    Code:
    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!
     
  2. agraham

    agraham Expert Licensed 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
    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.
     
  3. wolvo66

    wolvo66 Member Licensed 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!
     

    Attached Files:

  4. agraham

    agraham Expert Licensed 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.
     
  5. wolvo66

    wolvo66 Member Licensed 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?
     
  6. agraham

    agraham Expert Licensed User

    As you say SetCustomDevice should be redundant as the library will recognise those IDs.

    If it is still working in only one direction then there is nothing more I can suggest to try as it looks like the Leonardo is too different from the other Arduinos.
     
  7. Peter Gould

    Peter Gould Member Licensed 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: Mar 1, 2014
  8. Peter Gould

    Peter Gould Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice