0

Hiho, I'm trying to read an USB joystick attached to my Raspberry Pi with this python script:

import pygame
pygame.init()
print pygame.joystick.get_init()
print pygame.joystick.get_count()
j =  pygame.joystick.Joystick(0)
print j
j.init()
print j.get_init()
print j.get_id()
for i in range(0, j.get_numaxes()):
        j.get_axis(i)

pygame.quit()

all I get as output is this:

1
1
<Joystick object at 0xb6cb2120>
1
0
SDL_JoystickGetAxis value:0:
SDL_JoystickGetAxis value:0:
SDL_JoystickGetAxis value:0:
SDL_JoystickGetAxis value:0:

and I don't know why.

The values shouldn't be 0.

1 Answers1

0

The lines with SDL_ are produced by SDL. They are caused by a debug option which is still in the produced library and I don't know why.

However, to actually print the axis, you should write

print j.get_axis(i)

instead of

j.get_axis(i)

Finally, to be sure to get proper values, you should print the values in a loop (every second for example).

for j in range(10):
    for i in range(0, j.get_numaxes()):
        print j.get_axis(i)
        time.sleep(1)
  • now the output is SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 SDL_JoystickGetAxis value:0: 0.0 and so on – Markus Blechschmidt Oct 09 '13 at 15:39
  • I don't really know raspberry, but for my own scripts, as I don't display the console, I use pySide to show the axis values leaving all the SDL_ debug information behind. You should look for a way to display the values in an other way than through the console. – user2858494 Oct 10 '13 at 07:52