Ctpelnar1988
Ctpelnar1988

Reputation: 1255

pygame.error: Invalid joystick device number

import pygame

pygame.init()
j = pygame.joystick.Joystick(0)
j.init()

When I run this code on my Raspberry-Pi I am getting back the following error:

  j = pygame.joystick.Joystick(0)
pygame.error: Invalid joystick device number

This code was working a couple months ago, but something has clearly changed and I can not figure out what since the documentation is exactly the same as before. Any help or knowledge on the issue would be extremely appreciated.

Upvotes: 2

Views: 2552

Answers (1)

Ctpelnar1988
Ctpelnar1988

Reputation: 1255

I didn't have a controller connected to the Pi.

In my case, I wasn't running ds4drv.

In another terminal window run:

sudo ds4drv

and connect your DS4 controller.

https://github.com/chrippa/ds4drv

Upvotes: 2

Related Questions