Reading data from usb gamepad to control arduino.

Hello there.
I've made a lot of research on this but I still haven't found the info I need.
My idea is to use a usb wireless gamepad I have with the arduino to make some sort of wireless controlled car.
I was very thrilled when I saw lots of projects using a Wii nuchnuck to control the arduino, like in this pdf (after page 30)
I was hopping I could do the same thing with my gamepad, so I connected the usb receiver of the gamepad to the arduino inputs.
Now the hard part is understanding how can I read the data so I can use it to control the flow of the program.
I tried editing these pieces of code used in the pdf above but no luck so far, I cant read anything from it, even though it is powered and working (led on receiver of the gamepad blinks when I press a button).
I already found lots of tutorials for Wii nuchnucks but I cant find anything for general usb devices.
As I don't understand much of this, hopefully someone can tell me if what I'm trying to do is just impossible or if I just need the right code to be able to read the data.
From what I read there are some usb shields for arduino that would probably solve my problem but I'm not very interested in spending more money, so I'm looking for this kind of solution were I just plug it directly to the arduino.
I guess it doesn't make much of a difference but my gamepad is a logitech cordless rumblepad 2.
Thanks in advance for any help you can provide.

All I could tell you is that you need to know these things:

1.At what frequency/baud rate the receiver communicates with the computer and gamepad (almost certainly different)
2.The pin(s) on the receiver that communicates with the computer normally
3.The way in which the receiver communicates with the computer: for instance sending the byte 10011011 does this and that and receiving byte 11100110 tells the receiver this

You seem to have found out what pins are for +5V and GND, and USB pinouts are super-easy to find. The tricky part will be trying to get the arduino to tell the receiver what to do. I suggest finding a way to monitor the communication between your computer and the receiver:

A:when you are creating,have made,or lost a connection between the rec. and gamepad
B:what you receive when you press various buttons

if you can find out these things, your arduino can mimic your computer and act as a host for the receiver. All in all, it should cost close to nothing except solder and wire to hook stuff up.

Good luck with your project, hope I helped

and actually as i think about it, you should be able to use the tx and rx ports on the arduino to directly hook up to the tx and rx ports on the receiver...that would make it much much much simpler

I'm not sure if you're willing to buy another game controller, but I can confirm that it's definitely very easy and simple to interface the PS2 with the Arduino. A good library has been made for it with some good instructions :).

I've tested official PS2 controllers and also a variety of generic (non official) ones and they work too. If you want to go down this path I can help you :).

The USB game-pad is a USB slave device, as is the Arduino. You can't connect two slave USB devices together. You'll need a USB host device, which is available as an Arduino shield. If such a shield is too expensive, consider getting a game-pad for PlayStation 2.

Anachrocomputer:
The USB game-pad is a USB slave device, as is the Arduino. You can't connect two slave USB devices together. You'll need a USB host device, which is available as an Arduino shield. If such a shield is too expensive, consider getting a game-pad for PlayStation 2.

I'm not thinking about plugging the usb of the receiver to the usb of the arduino, instead I was thinking of connecting the data pins of the receiver to the analogue pins of the arduino and then try to understand what sequence of bits appear everytime I press each button, so I could use it to control the arduino. I guess it will be a lot of work but it's not impossible right?

Thank you all for the responses. I'll try to see if I can get it to work the way I wanted initially, if I fail then maybe I'm going to try to get some PS2 pad from a friend :slight_smile:

The arduino can act as a host without a shield.....but connecting to data pins would be much simpler

Dude i suggest u to use processing to read input from mouse (Example : U can wite a program suc as By moving your mouse from left to right U can adjust the brightness of an LED). Just research about using Processing with Arduino... I bet its a lot simpler than Decoding Data Pins to UART. Then u can calibrate your mouse to get desired output on your Robot. Or there is one another way which goe by using vPythn but that stuff requires a bit of coding skills... So proceed according to your conviiency.

hi everyone,

i have an usb gamepad and i can run correctly the examples USBHIDjoystick and le3dp and see the printed values.

The values are printed by some function not in the loop(). I know the values are stored in a STRUCT in some function. In the loop() is the function usb.task() only.

I need access to the values in the loop() to use them.

How can i do it? some example?

Thanks

In the function that prints the joystick values, store the x, y values into global variables. Global variables are accessible from the loop function.