2

I want to read the values of an Logitech Logitech Extreme 3D Pro with a Raspberry Pi. I'm using the pygame library

The script:

import pygame
import sys
import time

pygame.joystick.init()

print pygame.joystick.get_count()

_joystick = pygame.joystick.Joystick(0)
_joystick.init()
print _joystick.get_init()
print _joystick.get_id()
print _joystick.get_name()
print _joystick.get_numaxes()
print _joystick.get_numballs()
print _joystick.get_numbuttons()
print _joystick.get_numhats()
print _joystick.get_axis(0)

The ouput:

1
1
0
Logitech Logitech Extreme 3D Pro
4
0
12
SDL_JoystickNumHats value:1:
1
SDL_JoystickGetAxis value:0:
0.0

There are 4 axes and I turned all of them.

I can't find the problem. I already tried using other axes.

Thanks for help.

2
  • What is the expected output? Commented Oct 5, 2013 at 23:38
  • 1
    Have you tried looping over get_axis, or handling JOYAXISMOTION events instead of polling? It's possible that with your joystick, it always treats the initial position as 0, so calling get_axis immediately after get_init will always return 0.0. Commented Oct 5, 2013 at 23:41

3 Answers 3

3

If the problem is that the value is always 0, then try to do pygame.event.pump() before reading the values. I've had a similar problem and this helped.

Sign up to request clarification or add additional context in comments.

Comments

3

I ran into the same problem. You have to write pygame.event.get() in order to read information from the joystick. Otherwise it never updates.

Comments

0

I'd rather wait (even more in a thread) for example :

    axes = [ 0.0 ] * your_joystick.get_numaxes()
    buttons = [ False ] * your_joystick.get_numbuttons()

    while self.keep_alive:
        event = pygame.event.wait()
        if event.type == pygame.QUIT:
             self.keep_alive = False
        elif event.type == pygame.JOYAXISMOTION:
            e = event.dict
            axes[e['axis']] = e['value']
        elif event.type in [pygame.JOYBUTTONUP, pygame.JOYBUTTONDOWN ]:
            e = event.dict
            buttons[e['button']] ^= True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.