I heard this forum was a wonderful place to ask programming related questions. So here I am, I'd like to know if anybody has a solution to a problem I'm having.

I'm currently planning on creating a game on Python, and I've decided to make use of a joystick in this particular game. I've downloaded/installed Pygame so that I may capture buttons and events from the joystick. The problem I'm encountering is obtaining the axis values from the motion sensing component within the PS3 6-Axis controller. I'd like to know if there is possibly an existing module I can use? Or even a native method of doing this in Python without any 3rd party programs? I am fully prepared to use any method possible no matter how daunting the task.

Lastly, If anyone happens to come across any 3rd party programs that are usable in python I'd truly appreciate it. As this would be my option if I am left with no other choices.

My plan is to use these values to control objects within my game.

Dani AI

Generated

Short summary and a practical path forward for the PS3 Sixaxis issue (building on ’s report that pygame didn’t see the motion sensors and ’s pointer to pygame.joystick).

Pygame (SDL) usually only exposes whatever the OS joystick driver maps as standard axes. The Sixaxis/DS3 IMU often arrives as raw HID reports or a separate input device, so the accelerometer/gyro bytes never get surfaced to pygame.joystick on many systems. That is why you saw no motion values even though the controller is working for buttons/sticks.

Two reliable approaches:

  • Work at the HID/input level and decode the controller’s reports in Python (cross-platform). Use hidapi/pyusb (or pywinusb on Windows, python-evdev/hidraw on Linux) to enumerate the device, dump raw reports, and identify which bytes change when you tilt/rotate the pad. Once you know the offsets, scale and map them into your game.
  • If you prefer an existing solution, search for platform-specific daemons/drivers (e.g., Linux sixad/qtsixa-era tools, Windows toolkits that create virtual XInput devices). These can expose either decoded axes or block access, so be prepared to disable them while debugging raw HID access.

Quick debug workflow (safe, immediate steps):

  1. Connect by USB for stable debugging.
  2. Enumerate HID devices and dump reports while you move the controller.
  3. Find the three accel bytes by watching which report bytes change with tilt.
  4. Feed decoded values into your game loop (or post a custom pygame event).

Example: raw-read loop (inspect bytes, then adapt to your OS/library)

import hid, time

# enumerate to find vendor/product, then open
dev = hid.device()
dev.open(vendor_id, product_id)
dev.set_nonblocking(True)

while True:
    data = dev.read(64)
    if data:
        print(data)   # inspect which indices change when you move the controller
    time.sleep(0.01)

Integration tip: run HID reads in a background thread and pygame.event.post() custom USEREVENTs with decoded (ax,ay,az) so your main loop stays clean. Avoid closed-source drivers while debugging (they often claim exclusive access). If performance becomes critical you can wrap a small C decoder and call it from Python, but most projects work fine with hidapi + a bit of byte-parsing.

Recommended Answers

All 2 Replies

Have you tried pygame.joystick.

Wheres the code?

Cheers and Happy coding

I truly apologize for the long due response. This project was at a halt, and I have gotten rid of all previous code related to it. Mainly due to the fact that I had no idea in which direction I should turn. I tried Pygame. It was amazing learning Pygame, but it did not solve my problem. Pygame wasn't able to receive the values of the accelerometers inside of the controller. All hope seems to be lost on this subject, but if anyone has a solution, or a reference of where this may have been done before. It would really be appreciated. I may start looking into writing a C module. This may be the answer, {sigh} I really don't know. (My 4 most hated words)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.