Interfacing with USB

Codesmith

New Member
Alright so I've put together a few simple projects with my picaxe so far, and I'm looking to do something a little more complex now - a "gamepad" (a mini-keyboard with WASD, 5 re-programmable buttons, shift, and spacebar).
I don't think it will be too difficult to build, with the exception of interfacing it with the computer.

The only issue I have with taking this approach is that I'm wondering if I can use a USB as I/O and power? (Input from driver software to change the buttons, output from the picaxe to determine which button was pushed)
From my research it appears that a USB has 4 pins - +5v, Data+, Data-, and Ground (0v).
Could I wire the 5v and 0v to the picaxe as power, and the Data+- as I/O just by ripping apart a USB cable, or is there something that I need to do beyond that?
 
Last edited:

Codesmith

New Member
Ok, so the +5v and 0v are usable, how do I use the Data+- to be able to communicate with the software?

I assume that the SerIn / SerOut pins of the picaxe could be used, so if I bring up the either the Data+ or Data- to 3.3v would I be able to transmit information to the computer?
 
Last edited:

g6ejd

Senior Member
Alright so I've put together a few simple projects with my picaxe so far, and I'm looking to do something a little more complex now - a "gamepad" (a mini-keyboard with WASD, 5 re-programmable buttons, shift, and spacebar).
I don't think it will be too difficult to build, with the exception of interfacing it with the computer.

The only issue I have with taking this approach is that I'm wondering if I can use a USB as I/O and power? (Input from driver software to change the buttons, output from the picaxe to determine which button was pushed)
From my research it appears that a USB has 4 pins - +5v, Data+, Data-, and Ground (0v).
Could I wire the 5v and 0v to the picaxe as power, and the Data+- as I/O just by ripping apart a USB cable, or is there something that I need to do beyond that?
If only it were that simple. A USB bus requires a master-slave relationship to be established, the easiest way to do what you are trying to do is to get a interface board like:
http://www.ebay.co.uk/itm/USB-to-TTL-converter-FT232RL-for-Arduino-PIC-/111043788878?pt=UK_Computing_Other_Computing_Networking&hash=item19dab9c04e

Or to control devices, something like:
http://www.ebay.co.uk/itm/USB-Host-Shield-Android-ADK-Arduino-UNO-MEGA-Robotics-/171121740463?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item27d7a68aaf

Which provides you with USB host services.
 

Codesmith

New Member
g6ejd said:
If only it were that simple. A USB bus requires a master-slave relationship to be established, the easiest way to do what you are trying to do is to get a interface board.
Awesome, thanks for pointing me in the proper direction.
 

g6ejd

Senior Member
No problem, interfacing a PICAXE with te arduino shields is quite easy and note the 28x board is arduino compatible so even easier as the shield just plugs in.
 

Codesmith

New Member
I've decided to use WinUSB for the I/O, am I right in thinking that sending a write request sends the packet to Rx, where my chip will interpret it, and that sending a read request returns the contents of Tx?
 
Last edited:

g6ejd

Senior Member
I only know the winUSB driver, so I'm not sure if you mean a USB hardware product and also the reference to 'chip' do you mean PICAXE or one of the USB-TTL/RS232 chips?
 

Codesmith

New Member
I'm just confirming that on the RS232 chip when I submit a read request it will give me what I've output via the t(x), and the same goes for the r(x) and reading.
 

rossko57

Senior Member
umm, which RS232 chip? Who is submitting these read requests i.e. which side of this chip? (behaviour can be (should be!) different on either side of a converter)
 

Codesmith

New Member
I guess it's more a question of general USB input..
Am I right in thinking that to send something to the computer I would send the packet from my circuit, then call a read request from the computer?
 

hippy

Ex-Staff (retired)
At the lower protocol level of USB, the computer host will peform an IN transaction to receive data from the USB device and an OUT transaction to pass data to that USB device.

http://www.usbmadesimple.co.uk/ums_3.htm

Most USB interfacing with a PICAXE device would be through a USB-to-serial cable such as an AXE027 or similar. If the USB-to-serial cable is 'hidden' within PICAXE device enclosure it would appear to the outside world to be a USB connected device ( needs a USB-to-USB cable between device and PC ), but it would still be USB-to-serial based and would normally be accessed from the PC via the virtual serial port associated with that cable.

There are other ways the PC can communicate with the USB-to-serial cable other than through the virtual serial port; FTDI for example provide D2XX direct drivers for their cable and it would probably be possible to use lower levels of protocol to do what those D2XX drivers do.

I expect most members here have only limited knowledge and understanding of USB transactions at such a low level and there may be other forums better suited to such discussions.
 

Codesmith

New Member
Alright I think I finally get it, thanks Hippy. (and if I don't, well I guess it's time to just start messing around)
 

mrburnette

Senior Member
If the USB-to-serial cable is 'hidden' within PICAXE device enclosure it would appear to the outside world to be a USB connected device ( needs a USB-to-USB cable between device and PC ), but it would still be USB-to-serial based and would normally be accessed from the PC via the virtual serial port associated with that cable.
@Codesmith.... The bottom line is that the PICAXE series of PIC UC's were designed at a time when "serial was king." I got into this stuff back when one had to use a parallel printer port! Then things evolved to dB25 serial ports and then to dB9 serial ports and now to USB-ish ports.

There are UC's that can directly (may need some discrete parts like resistors or diodes based on the manufacturer's reference circuits) to the USB bus on a host PC. But PICAXEs are not designed this way... A small device that does USB on one side and serial TTL on the other is the generally recommended accessory. In the long-run, this approach can save you money if you are training students or if your PICAXE project does not need to be always connected to the PC. For projects that must always be connected, it adds a small cost but may be fully justified as the project uC part can be upgraded or replaced without concern for the USB adapter. And, if the USB adapter is damaged (step on the plug or squash it with a rolling chair) then this can be easily replaced.

It's a two-edged sword.

Ray
 
Top