Skip to content

Instantly share code, notes, and snippets.

@caiogallo
Created April 22, 2021 02:23
Show Gist options
  • Save caiogallo/7f48a659ae911e0c37fac8e7661d6905 to your computer and use it in GitHub Desktop.
Save caiogallo/7f48a659ae911e0c37fac8e7661d6905 to your computer and use it in GitHub Desktop.
xbox one bluethooth controller on raspberry pi 4
# python3
# apt install python-pip
# apt install python3-evdev
# pip install evdev
#
# list devices
# ls /dev/input/
#
# https://diyprojects.io/python-library-evdev-raspberry-pi-use-gamepad-diy-projects-servomotor-games/#.Xa8ZR-gzaUl
#
from evdev import InputDevice, categorize, ecodes
gamepad = InputDevice('/dev/input/event2')
print(gamepad)
for event in gamepad.read_loop():
if event.type == ecodes.EV_KEY:
print(event)
elif event.type == ecodes.EV_ABS:
absevent = categorize(event)
print(ecodes.bytype[absevent.event.type][absevent.event.code], absevent.event.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment