1

I am using Ubuntu 18.0.4.4 LTS with a home-brew Arduino-based USB joystick attached.

The OS sees the device at both /dev/input/js0 and /dev/input/event5 and jstest works with it:

$ jstest /dev/input/js0 
Driver version is 2.1.0.
Joystick (Arduino LLC Arduino Micro) has 6 axes (X, Y, Z, Rx, Ry, Rz)
and 0 buttons ().
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0  2:     0  3:     0  4:     0  5:     0 ^C

evtest also works, as root:

$ sudo evtest /dev/input/event5 
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x2341 product 0x8037 version 0x101
Input device name: "Arduino LLC Arduino Micro"
Supported events:
  Event type 0 (EV_SYN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 1 (ABS_Y)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 2 (ABS_Z)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 3 (ABS_RX)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 4 (ABS_RY)
      Value      0
      Min     -100
      Max      100
      Flat      12
    Event code 5 (ABS_RZ)
      Value      0
      Min     -100
      Max      100
      Flat      12

Yet, SDL2's SDL_NumJoysticks() always returns 0, despite initializing SDL2 with joystick and gamepad support:

        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_AUDIO );

Why can't SDL2 not use a working /dev/input/js0 device on Ubuntu?

4
  • 1
    Self-built SDL2 or binaries from Ubuntu's repos?
    – genpfault
    May 5, 2020 at 13:18
  • These were from Ubuntu repo.
    – Bram
    May 5, 2020 at 16:36
  • 2
    @Bram what are your /dev/input/event* permissions? I suppose you need at least read permissions (and probably write too if you have force feedback). Check output of strace -e file ./your_test_program.
    – keltar
    May 5, 2020 at 16:51
  • @keltar When running as root, the joystick is found. If you write it up, I will mark it as the answer. Thanks.
    – Bram
    May 6, 2020 at 2:40

2 Answers 2

2

SDL2 uses /dev/input/event* device files to access joysticks/gamepads, so you need read (and in some cases write) permissions for that files. Most linux distros use special user group for that files, e.g. input group on debian or gentoo; check what's your permissions are and make your user member of appropriate group (and re-login after that).

1

I'm working with pygame and a raspberry Pi 4. Since pygame hides a lot of error messages it took me quite a long time to find the culprit. The solution proposed by @keltar worked for me. For the sake of completeness I share the command:

$ sudo usermod -aG input username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.