i just got a arduino Mega for xmas and ive been generally mucking around with it.
i cut an old usb cable and found 4 wires which wikipedia labels as VCC, D-, D+, GND
if i wired those wires into the right places on my arduino (e.g. TX1, RX1 etc) could i control a USB device from the arduino (if i knew the protocol of the attached device)
The USB shield only breaks out the appropriate pins. You have to then program the Arduino to be a USB master for whatever you plug into the USB part on the shield.
That is not a trivial task, for must USB (slave) devices.
Basically, you are writing a driver for the device you have connected, and you have a limited amount of space in which to do that.
The USB shield only breaks out the appropriate pins. You have to then program the Arduino to be a USB master for whatever you plug into the USB part on the shield.
That is not a trivial task, for must USB (slave) devices.
Basically, you are writing a driver for the device you have connected, and you have a limited amount of space in which to do that.
Seriously, if you can get the details about the device that you are trying to write the driver for, it can be rewarding getting the driver to work. It can be very frustrating trying to guess what the driver should see/do/send/read at any given time, if the device you want to deal with hasn't published the USB specs. Many devices do not.
There is a library for the Max3421 that I have used with a USB Host shield. If the attached device is HID compliant, the library and shield work out of the box. At least they work for me with a USB keyboard. They also work with a USB mouse.
I think that writing actual device drivers to reside on an Arduino would be an adventure. I won't predict how difficult I think it might be, and I certainly wouldn't say that it can't be done.
Footnote:
An unexpected bonus from this shield and library (at least I didn't see it coming):
The '3421 has eight general purpose input pins and eight general purpose output pins that are brought out to pads on the shield.
It is possible to use some of these pins to interface to common text LCD display (HD44780 controller without using any more Arduino pins (other than the SPI port interface pins to the '3421). How cool is that?
There is an example sketch in the MAX3421 library directory that shows how it's done. In fact, my specific application was with a 19-key USB keypad and a 20x2 LCD. All of the interface stuff was already done for me!
so with that USB Host sheild, do you lose all the arduino pins that it plugs into, but gain some extra ones due to the general purpose 'pins' on the sheild?
An LCD interface for the type of device I am referring to takes six Arduino output pins.
The USB Host shield that I am referring to takes a total of seven Arduino pins, and in addition to supporting USB Host functionality, allows you to connect an LCD device to the shield.. Three of the Arduino pins used by the shield are SPI port pins, which can be used with other SPI devices, so they aren't necessarily "lost."
After connecting the LCD in the manner supported by the library, you have two output pins on the '3421 and eight input pins that you can use for general purpose I/O.
Bottom line: "Worst case" with this shield is that you lose one additional Arduino pin for that particular type of LCD module. If you have some other type of LCD (or if you aren't connecting an LCD), and if you don't use any other SPI devices, you have lost seven Arduino pins but have gained eight output pins and eight input pins for general purpose I/O (subject to SPI port speeds to/from the '3421).
There are other ways of obtaining USB Host functionality, and there very well may be 'better' ways, depending on the context of particular developer. I have no particular interest in people using the board that I am talking about here, but it is a way to get some kind of USB Host operation from an Arduino board. I am just reporting my personal experience with that shield with Duemilanove and other Arduino ATmega328 boards. See Footnote.
Regards,
Dave Footnote:
Now, here's the 'slightly messy' news for Arduino Mega users:
This shield, like many other non-Mega shields that use the SPI port, is not compatible with Mega boards without a little more work. This is because the SPI MOSI, MISO, and SCK pins are Arduino pins 11-13 for '328 chips but are different for '1280 and '2650 chips. The least-surgical method of using them with a MEGA board is to get a MEGA proto-shield and make some mods so that the proper MEGA SPI pins can be routed to the proper ones on the USB Host shield. This is not as clean as it could have been with a slightly different design of the shield, but it gives a stable platform for software development.