Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: USB, USB Keyboard to USB-HID

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4

    USB, USB Keyboard to USB-HID

    I'm a software developer with amateur electronics skills, and I've accidentally volunteered myself (need to work on those soft skills lol) to prototype a "Device" with the following requirements:

    1) Need a "Device" to be connected inline via USB to a USB Host system and an Android device.

    2) The Host system must detect the Device as USB HID (can't install drivers.)

    3) The Android device needs to be able to programmatically tell the device to send arbitrary keystrokes & combinations to the Host via its HID connection.

    4) I have to keep the price down, because once I demonstrate proof of concept I'm to make hands on demos which will be given to developers.

    I really like the Teensy 3.0 for this, because its compact, affordable, and easy to prototype with (I'm hoping to encourage these developers to become more involved.)

    I'm trying to avoid the added cost of a USB or Host USB shield, so I can make more units within budget.

    The v-usb project looks promising, since speed is already limited by the keyboard limitation .. (absurd bureaucracy does support job security, at least,) I'm not too concerned about a software USB implementation.

    I've seen a lot of examples of similar projects here on pjrc and beyond, but as a novice in this area I can use any guidance you're willing to share.

    I have read a lot of docs in the last couple days, but I am a noob at this so please forgive my temporary lack of subject knowledge, just looking for some leads and/or a good shove for my first microcontroller project.

    First, is the Teensy 3 my best option for this?

    Are there any products that already do this that I've missed?

    Can I add a USB port by wiring a port to the board and utilizing the vusb library?

    As far as I can tell, I won't *need* it to be a USB Host, I could just setup the Teensy 3 USB Micro AB as a HID emulator, then wire in a USB cable or port for attaching an Android device; then, I believe I could enumerate the device as a printer or some other device that could accept a data stream, then Teensy 3 could format and send the keystrokes & combinations?

    Could a wired-in port/cable perform as a USB-Host (for charging the Android device) or emulated/enumerated HID (so I could reversr the roles and use the built-in USB Host port to charge the Android device?

    Sorry for the verbosity, I really did edit out a ton of text...

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,653
    Quote Originally Posted by codeshane View Post
    1) Need a "Device" to be connected inline via USB to a USB Host system and an Android device.
    As a USB device, Teensy can only connect to a single USB host. You could unplug the cable from the "host system" (is that a PC or Mac?) and plug is into your Android product, assuming it has a USB host port. But you can't simultaneously connect to both. USB just doesn't work that way.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    (edit)
    Mostly Linux boxes and some Windows; OSX support would be nice, but don't need it currently.
    (end edit)

    Thank you for your quick and straight-forward reply. I had just seen this link about adding serial USB to an AVR:

    http://hackaday.com/2013/10/23/seria...crocontroller/

    And now I just found an interesting read, for anyone who may find this page later:

    http://forums.hackaday.com/viewtopic.php?f=5&t=1417

    While I'm waiting on parts I'm going to read into the USB Standards as well as Teensy 3's specs & how it implements Host USB.

    Thanks again!
    Last edited by codeshane; 11-24-2013 at 01:23 AM. Reason: because I'm lame and didn't answer the question..

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Also, what I had been trying to suggest is either:

    (Option A: teensy host for charging) Android:usb(1)~~cable~~hostevice:hid~~cable~~host:System

    (Option B: Android using OTG, but only if this would simplify the project)
    Android:OTG(2)~~cable~~peripheralevice:hid~~cable~~host:System

    Sorry for my diasciigrams, but my drawing skills are more embarrassing .. the colon-char represents a hardware/subcomponent connection/relation.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,653
    Here is a direct link to a copy of the USB spec. Chapter 4 has the info you need. The first part of chapter 5 is also good to read.

    http://www.pjrc.com/teensy/beta/usb20.pdf

    You _might_ be able to run V-USB on a Teensy 2.0. In fact, here's an old copy that was tweaked to work on Teensy 2.0. Look in vusb-20090822/examples/hid-mouse/firmware for the mods specific to Teensy 2.0.

    I also want to be clear, this is FAR from a complete solution. It will compile to a stand-alone .hex file that might implement a mouse. It is not in any way integrated with the Teensyduino code... it's only a stand alone project. You'll have a LOT of software work to do. Please plan accordingly.

    But at least maybe this will give you a head start?
    Attached Files Attached Files

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thank you very much, I appreciate your diligence. If all else fails, pairing up two Teensy 3's would be a much faster solution, would be similar in price to adding a shield, and would give a lot more room for expansion. Either way, I really appreciate your work and support!

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,653
    Yes, two Teensy3s connected together with Serial1 TX-RX and vise-verse would be much easier. You could also link them together with I2C using the Wire library, but Serial is probably simpler.

  8. #8
    Junior Member
    Join Date
    Jan 2014
    Location
    Warsaw
    Posts
    1
    I work on a very similar device, but instead of using USB-OTG:
    host<-(USB)->uC<-(USB OTG)->Android
    I've decided to use Bluetooth:
    host<-(USB)->uC<-(Bluetooth)->Android
    take a look at my blog or InputStick website

  9. #9
    Senior Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    119
    All the USB devices that the Teensy can pretend to be send data only one way, from the device to the host, with the exception of the serial and MIDI devices...

    The Teensy doesn't (at this time), support hosting USB... So I'm not sure how you plan to move data between the android and computer this way... It might be easier to just use two FTDI chips

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •