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?
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.
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.
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 ?
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.
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.
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.
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.
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.