Pages: [1]   Go Down
Author Topic: manual USB with Mega  (Read 1687 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

or is it more complex than this?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

spooky
i was just reading about this



Brendan
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so u guess i need to buy a sheild then, and can't do it manually?

NB: i am a professional programmer so im not afraid of complex code. just don't know much about hardware
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks man. seems like i should just buy a USB sheild smiley

I am definately no guru in USB. and if noone else has been able to do it before now then i wont be the one to be able to do it smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49040
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

well that's the fun of it all, isnt it smiley-wink
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49040
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
well that's the fun of it all, isnt it
It's all fun and games until somebody gets hurt.  smiley-wink

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.
Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Here's the board I am using: http://www.sparkfun.com/products/9628

I downloaded the library from here: https://github.com/felis/USB_Host_Shield

Here's a page with some projects: http://www.circuitsathome.com/arduino_usb_host_shield_projects


Good luck!  I hope you keep us informed.



Regards,

Dave

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!

« Last Edit: January 10, 2011, 10:32:08 am by davekw7x » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I havn't had a chance to use any sheild yet.

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?

sorry if this is a silly question smiley-wink
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33959
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
do you lose all the arduino pins that it plugs into
Depends on the shield but basically yes.

Quote
but gain some extra ones due to the general purpose 'pins' on the sheild?
Depends on the shield but basically no.
Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 10, 2011, 01:05:52 pm by davekw7x » Logged

Pages: [1]   Go Up
Jump to: