Pi 4 + LibreELEC + GPIO joystick - how?

  • Hi

    I am new to LE and the retro games it provides (but an old hand at Linux). I happen to have a generic DB9 joystick that I'd like to connect using the Pi GPIO lines. I'm using the latest LE and a Raspberry Pi 4.

    I've looked around the internet and found numerous discussions and instructions, all of them either old, not LE focussed or both. I see that the kernel has a DB9 joystick driver for connecting via the X86 parallel port, and I see various Python scripts that read GPIO changes and inject events into the Linux input stack.

    Can anyone point me in the direction of a set of current instructions that will work with LE (i.e. that don't start "apt install this that theother") and show me how to make this work, both in terms of driver software (kernel module or userspace), and in terms of what needs configuring where? I don't mind having to create a program or two to make it fly, but don't know enough about what the correct pattern is to follow.

    Thanks!

  • Chances are that the Python GPIO lib is missing. On LE you have to explicitly install that lib. It's contained at the "Raspberry Pi Tools" add-on. After add-on installation you can use the lib that way on your Python script:

    Code
    import sys
    sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
    import RPi.GPIO as GPIO
  • Hi

    Thanks for the response.

    I've installed that tools add-on already, but am not sure which python script to use from the internet, or whether I need to roll my own python script - there seem to be a multitude of approaches and it's not clear which is the correct one... or whether there's already something in LE/Kodi that already solves this without having to bounce up to userspace and back to kernel to create input events..

  • Hi

    Thanks for all the suggestions. Here are the pages I've seen which appear to give clues, but I'm not sure if they are leading me in the correct direction or not.

    The section "The right-ish approach" at Raspberry Pi GPIO Joystick | Chris Swan's Weblog appeared to be a reasonable approach but it's 8 years old and I don't know if the uinput and time Python libraries are available in LE.

    The joystick adapter at Using the Boffintronics C64 / Atari Joystick Adapter with a Raspberry Pi – Boffintronics uses a compiled program from Adafruit GitHub - adafruit/Adafruit-Retrogame: Raspberry Pi GPIO-to-virtual-keyboard utility for classic game emulators but I have no idea how it passes the inputs to retrogame or whether that is the game layer used by LE/Kodi. It also mentions that the C program is in maintenance mode and to use python scripting instead, again don't know if the uinput pattern used by these is how LE/Kodi expect input to be provided.

    The Adafruit guide linked to from there Overview | Retro Gaming with Raspberry Pi | Adafruit Learning System talks about using the Adafruit products with various retro gaming installs but I have no idea which is closest to the way LE/Kodi work.

    Having to create a program to make this work isn't a problem, I just want to be sure I understand what it has to do before I start!