Go Down

Topic: passthrough from usb host to hid acting as a keyboard (Read 1 time) previous topic - next topic

anthezium

hi, I'm completely new to arduino and setting up my first project!
reading
http://hunt.net.nz/users/darran/weblog/c6f35/Arduino_USB_Keyboard_Passthrough.html
it appears that adding another usb host to the arduino can allow it to act as a host to a usb keyboard and forward keypresses via its usb hid.

i'd like to modify an existing library that runs on an arduino uno and forwards stuff corresponding to keypresses to some i2c thing from a computer, which is connected via usb to the arduino and grabs some java SerialPort object corresponding to /dev/ttyACM0 and communicates with the arduino via said SerialPort's InputStream/OutputStream objects.  i want to maintain this pc-arduino interface but have the uno pretend to be a usb keyboard (with its usb hic right?) and send keypresses to another computer (rather than sending to i2c) for testing purposes.

questions:
1) the uno built-in usb dude is functioning as a usb host in this situation, right? 
2) if i add a usb host shield to an uno and free up its main port to function as the fake keyboard, could the communication described above still occur via the add-on host interface?
3) if so, can i do this with just an arduino uno, a usb host shield, and some a-a and a-b usb cables?

thanks for reading!

Grumpy_Mike

Quote
1) the uno built-in usb dude is functioning as a usb host in this situation, right?

Wrong, it is not.

Quote
2) if i add a usb host shield to an uno and free up its main port to function as the fake keyboard, could the communication described above still occur via the add-on host interface?

No.

Quote
3) if so, can i do this with just an arduino uno, a usb host shield, and some a-a and a-b usb cables?

No.

I think you need to read that page again.

anthezium

thanks for the helpful and informative response!

having read again, my understanding of the passthrough setup from the link:
* the built-in atmega8u2 USB, flashed to look like a USB Keyboard HID, is connected to a host controller on the computer receiving the keystrokes
* the add-on USB host shield is connected to the keyboard that's sending the keystrokes
* the "sketch" running on the arduino is forwarding/mangling what is received via the host controller on the shield out the built-in controller

my updated guess regarding what i'd need to build to accomplish my goals:
* 2 USB controllers on the arduino, both of which can function as USB devices
* one is set up to look however the uno's included controller typically looks, and is connected to a host controller on the laptop, receiving data from the library described
* one is flashed to look like a USB Keyboard HID, and is connected to a host controller on the computer receiving keystrokes
* a modified version of the sketch i've been provided with running on the arduino is sending keystroke events via the controller acting as a USB Keyboard HID based on the messages it receives from the laptop connected to the other USB controller

what is correct/incorrect in this iteration?
thanks for reading!

anthezium

for instance, could I wire this
http://www.sparkfun.com/products/10277
to an uno and use it as i described?

Grumpy_Mike

Yes I think that is possible, that board should make life much easer for you. Are you thinking of using two of them. That way you don't have to mess about with the one on board and you can still upload sketches.

anthezium

does the built-in usb port on the uno not typically appear as a serial device, e.g. /dev/ttyACM0, i.e. i'd have to flash the firmware to make this happen, and this would mean that i couldn't upload sketches?  or is it just that while the program that receives data from the laptop is running it would hog the port and i'd have to reset the uno or something to get it to let me upload again?  if i got 2 of these atmega8u2 boards, there're enough pins or whatever to have both connected at the same time?

Grumpy_Mike

Quote
i'd have to flash the firmware to make this happen, and this would mean that i couldn't upload sketches?

Yes that is why I said two boards.

Quote
if i got 2 of these atmega8u2 boards, there're enough pins or whatever to have both connected at the same time?

The output is a simple TTL serial interface so just two lines per board are all you need. You also need ways of reading these say with the ports on a Mega or a software serial library.

anthezium

thanks, duly noted.  ordered an uno (a while back), two of those boards, and some a-b usb cables. 

anthezium

alright, plan v1 for the USB HID one:

* the breakouts I purchased come pre-loaded with this: https://github.com/a1ronzo/SparkFun-USBtoSerial/tree/master/Projects
  looking here: https://github.com/a1ronzo/SparkFun-USBtoSerial/blob/master/Projects/sparkfun_USBtoSerial-v10/sparkfun_USBtoSerial.c
  it currently keeps some little ring buffers around to forward bidirectional traffic between the usb and "serial" ports.  in the case of this beauty http://www.sparkfun.com/products/10277 I'm guessing that "serial" means the tx, rx, and maybe some of the other ones on the end of the board opposite the usb port.  i'll figure that out on their irc or something...  anyway the software changes I think I need to make are:
  * from https://github.com/abcminiuser/lufa-lib/tree/master/trunk/Demos/Device/ClassDriver/Keyboard some dance of including Keyboard.h and copying code from Keyboard.c to initialization functions.  goal here is getting the device to appear as a HID and cook up a version of CALLBACK_HID_Device_CreateHIDReport that polls some memory set when data is received via serial
  * write code to receive characters or something via serial and set aforementioned memory so CreateHIDReport has something to read.  put in main loop before USB crap

is this coherent?  are there obvious problems with it?  i'll update as i make progress

Go Up