Problems with Sense Hat Joystick

Hi there!

I’ve recently purchased a sense hat and forever since tried to get it to work. After some tinkering, as can seen in my previous posts, I got everything to work except one thing: the joystick

In advance I apologize for the lengthy post, but I am just kinda stuck because I tried basically everything to my knowledge.

The stick.py file, which is supposed to control the joystick of the sense-hat imports the joystick in the following manner:

        for evdev in glob.glob('/sys/class/input/event*'):
            try:
                with io.open(os.path.join(evdev, 'device', 'name'), 'r') as f:
                    if f.read().strip() == self.SENSE_HAT_EVDEV_NAME:
                        return os.path.join('/dev', 'input', os.path.basename(evdev))
            except IOError as e:
                if e.errno != errno.ENOENT:
                    raise
        raise RuntimeError('unable to locate SenseHAT joystick device')

As you can see it tries to import the event-handler from /sys/class/input/event* where the name matches SENSE_HAT_EVDEV_NAME which is Raspberry Pi Sense HAT Joystick as defined in the stick.py code earlier.

Now if I manually search for this event-handler everything is fine because as I can see it is in /sys/class/input/event0/device where cat name results in Raspberry Pi Sense HAT Joystick.

Therefore I can conclude that the joystick is recognized by the OS.

But in any program that I try to run (even with sudo), the joystick does exactly nothing - but the implementation is correct.

Now to my knowledge, there are only 2 things that could possibly be wrong:

  • The joystick doesn’t work and I need to get a new sense-hat

  • OSMC somehow blocks the joystick to actually to something

And this is where I ask: Does someone know if there is a possibility that osmc ignores or blocks input events from the joystick?

Here are my logs: https://paste.osmc.tv/atowuzevul

Thanks in advance!

These things are very difficult to debug from a distance, since very few of us will have a sense hat to play with, myself included.

My first port of call was Raspberry Pi Documentation - Sense HAT which almost immediately says that you should have installed a package called sense-hat, yet the log doesn’t show it to be installed (though I do see python-sense-hat and python3-sense-hat). Home - Sense HAT also says that the package sense-hat should be installed.

Further down on the raspberrypi.org page, there is a section that says:

The joystick comes up as an input event device named “Raspberry Pi Sense HAT Joystick”, mapped to the arrow keys and Enter. It should be supported by any library which is capable of handling inputs, or directly through the evdev interface. Suitable libraries include SDL, pygame and python-evdev. The included ‘snake’ example shows how to access the joystick directly.

but I can find no mention of pygame or python-evdev being installed. The evdev kernel module does exist in OSMC but the log shows no mention of it having been loaded.

On a wider note, I see that you have instaled piHole, Tor, Raspotify and something called remot3.it. Trying to squeeze so many additional packages onto a small device like a Rasperry Pi is certainly going to increase the possibility of complications occurring.

I’d suggest a re-install, as PiHole is known to cause major problems by messing up connman.

I don’t think Pi-hole is the issue in this case. Apparently dhcpcd isn’t critical to its operation and can be disabled:

First of all, thanks for your answer.

For sense-hat: I did not install the package, because as inferred from this post Sense Hat how to - #4 by sam_nazarko it is mentioned that you should not install it and rather use python-sense-hat.

For pygameand python-evdeva new update New release of Sense HAT Python library v2.2.0 - Raspberry Pi Forums mentions the removal of the dependency of those above.

I mainly use pi-hole, raspotify and remot3.it (to access it from everywhere) while also running a twitch chat bot and I did not really run into issues yet (apart from the joystick thing).

Are there any additional things I can provide to help you debug ? :confused:

I see. AFAICT, installing sense-hat will cause the following package to be installed:

Inst libblas-common (3.7.0-2 Debian:9.4/stable [armhf])
Inst libgfortran3 (6.3.0-18+deb9u1 Debian:9.4/stable, Debian-Security:9/stable [armhf])
Inst libblas3 (3.7.0-2 Debian:9.4/stable [armhf])
Inst liblapack3 (3.7.0-2 Debian:9.4/stable [armhf])
Inst librtimulib7 (7.2.1-4 Raspberry Pi Foundation:stable [armhf])
Inst librtimulib-dev (7.2.1-4 Raspberry Pi Foundation:stable [armhf])
Inst python-numpy (1:1.12.1-3 Debian:9.4/stable [armhf])
Inst python-rtimulib (7.2.1-4 Raspberry Pi Foundation:stable [armhf])
Inst python-sense-hat (2.2.0-1 Raspberry Pi Foundation:stable [armhf])
Inst python3-numpy (1:1.12.1-3 Debian:9.4/stable [armhf])
Inst python3-pil (4.0.0-4 Debian:9.4/stable [armhf])
Inst python3-rtimulib (7.2.1-4 Raspberry Pi Foundation:stable [armhf])
Inst python3-sense-hat (2.2.0-1 Raspberry Pi Foundation:stable [armhf])
Inst raspberrypi-bootloader (1.20180417-1 Raspberry Pi Foundation:stable [armhf])
Inst sense-hat (1.2 Raspberry Pi Foundation:stable [all])

and it is rasperrypi-bootloader that will cause problems with OSMC. The dependencies for sense-hat are:

raspberrypi-bootloader (>= 1.20150820-1), librtimulib-dev, python-sense-hat, python3-sense-hat

so you might want to ensure that librtimulib-dev is also installed.

The thread you linked to starts off with:

We have just done a new release of the Sense HAT python library. Version 2.2.0.
It’s planned to go ino the next Raspbian image however, if you want it now, you can install it using pip.

sudo apt-get remove python-sense-hat python3-sense-hat
sudo pip install sense_hat
sudo pip3 install sense_hat

The two APT packages are still installed. Have you tried to install sense-hat using pip?

I installed librtimulib-dev like you said, but rebooting with it installed and additionally adding it to /etc/modules did not help sadly.

The version from the thread is about the sense hat python library version 2.2.0, but the package python-sense-hat which is already installed via apt-get also has version 2.2.0-1.

Do you recommend uninstalling the apt packages and doing it via pip? From what I can tell the packages are(should be) identical.

  • 1st Edit

Since I just tried removing the two packages, it’s shown that one dependency is python-rtimulib, which I guess is librtimulib-dev just for python (?). Maybe this helps.

  • 2nd Edit

Installing sense_hat via pip did not help sadly.

  • 3rd Edit:

Since I’m out of ideas here, do you know of anything else I could do? I already posted in the official forum but got zero replies.

Since you mentioned that SENSE_HAT_EVDEV_NAME is Raspberry Pi Sense HAT Joystick it might be more appropriate to add evdev to /etc/modules. If you added librtimulib-dev to /etc/modules you should remove it, since it is not a kernel module.

I added evdev to /etc/modules but again no luck with sudo reboot even though it’s in lsmod

If I start a program, the number of programs that use evdev goes up by 1 though (with lsmod), but nothing is printed with a program that should work.

e.g.

from sense_hat import SenseHat
from time import sleep

sense = SenseHat()
event = sense.stick.wait_for_event()
print("The joystick was {} {}".format(event.action, event.direction))
sleep(0.1)
event = sense.stick.wait_for_event(emptybuffer=True)
print("The joystick was {} {}".format(event.action, event.direction))

That looks like example code from API Reference - Sense HAT. You said in your first post that you “got everything to work except one thing: the joystick”. Can you confirm that other non-joystick code examples from the same site do work?

As I mentioned at the beginning, these things are very difficult to debug from a distance without having the relevant hardware available. It is possible that, despite what has been written elsewhere, the python evdev code is still required in order to talk with the kernel module. That post you linked to was from 2016 and the situation might have changed several times since then, so taking it to be definitively true is always gong to be risky. As you’ve already mentioned, your joystick might be incompatible or faulty. Ultimately, you will need to experiment through trial and error to see what works, and what doesn’t work. I can offer no simple solution.

Yeah I already tried other code examples from the page - I’ve finished a little snake program where the last step would be to move the snake with the joystick (which does not work).

I figured it would be hard to debug, but I am thankful anyway for your help. I’ll probably try the sense-hat with a different OS/sd-card to rule out either the OS fault or the joystick fault.

Thanks :slight_smile:

Absolutely. Raspbian would be the best alternative OS, IMO.

Good luck!

1 Like

Just installed Raspbian lite and the joystick works on it.

This is honestly the worse outcome :confused:

Anything I could look into on the new OS to find out whats wrong or should I just suck it up?

Difficult to say, but it might be down to one or two of the kernel compile options. Right now, I’m away from home and am unable to access my OSMC Pi, but that might be an avenue worth investigating.

Alright no problem - I’m trying to collect as much detail as possible right now from the current os to compare them later

One thing that just occured to me is that I installed sense-hat on raspbian while I’m using python-sense-hat on osmc.

I’ll try a fresh install of raspbian with python-sense-hat instead and report back with results.

The sense-hat packag contains remarkably little. It has the following files:

/etc/RTIMULib.ini
/usr/src/sense-hat/examples/python-sense-hat/space_invader.py
/usr/src/sense-hat/examples/python-sense-hat/colour_cycle.py
/usr/src/sense-hat/examples/python-sense-hat/rotation.py
/usr/src/sense-hat/examples/python-sense-hat/pygame_joystick.py
/usr/src/sense-hat/examples/python-sense-hat/space_invader.png
/usr/src/sense-hat/examples/python-sense-hat/text_scroll.py
/usr/src/sense-hat/examples/python-sense-hat/rainbow.py
/usr/src/sense-hat/examples/python-sense-hat/compass.py
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive10/Makefile
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive10/RTIMULibDrive10.cpp
/usr/src/sense-hat/examples/RTIMULib/python/InjectIMU.py
/usr/src/sense-hat/examples/RTIMULib/python/Fusion11.py
/usr/src/sense-hat/examples/RTIMULib/python/Fusion10.py
/usr/src/sense-hat/examples/RTIMULib/python/Fusion.py
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive/RTIMULibDrive.cpp
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive/Makefile
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive11/Makefile
/usr/src/sense-hat/examples/RTIMULib/RTIMULibDrive11/RTIMULibDrive11.cpp
/usr/src/sense-hat/examples/snake/snake.c
/usr/src/sense-hat/examples/snake/Makefile
/usr/share/doc/sense-hat/changelog.gz

of which only /etc/RTIMLib.ini seems to be of much use, plus it will comment out a blacklist of module i2c-bcm2708 if found and add i2c-dev to /etc/modules.

I recall from a very recent post that i2c-dev must be explicitly loaded, so that might have been a significant omission.

Yup I remember the post as well, sadly I am the author and already added i2c-dev.

Do you think that maybe missing rasperrypi-bootloader could be the cause for my problem?

From my own investigation not much can be concluded by navigating through files onraspbian.
The event/input folders look the same, so it should be a module which doesn’t load (for whatever reason).

Shouldn’t I be able to see which modules are loaded on raspbian to listen to the joystick with lsmod?

Then I could compare the two results of lsmod and see if there is any difference.

Just weighing in quickly:

lsmod when working on Raspbian vs lsmod when not working on OSMC should give clues.
As would dmesg output from both distributions

I don’t expect much differentiation in config.txt but that would also be good to see.

Sam

It’s possible but I listed what files it would install and most are example code, except for /etc/RTIMULib.ini. The postinst code in the .deb package also doesn’t do very much, other than add i2c-dev to /etc/modules and stop i2c-bcm2708 from being blacklisted.

Adding the ini file would certainly be a worthwhile step, as would comparing the loaded kernel modules. If you want to compare the kernel configurations, the file is no longer visible in Raspbian and needs to be extracted from /proc/config.gz – but first run sudo modprobe configs to create it.