Posts: 2
Joined: Tue Jun 26, 2018 9:40 pm

Joystick problems

Tue Jun 26, 2018 9:51 pm

Hi there!

I recently purchased the sense hat with the intent to play around with it a little bit, but I am having trouble with the joystick.

I have a raspberry pi 3 B running osmc v2018.06-1 and I also installed python-sense-hat. The problem is, that I can not, with any joystick program, get the joystick to work.

There is however a "Raspberry Pi Sense HAT Joystick" in /sys/class/input/ which I suppose means that the joystick is indeed being recognized.

One of the programs for example is this one:

Code: Select all

from sense_hat import SenseHat

sense = SenseHat()
while True:
    for event in sense.stick.get_events():
        print("The joystick was {} {}".format(event.action, event.direction))
But it does not work.

I'm kinda stuck and don't know what to search for anymore, since no one seems to have this problem.

If anyone could help me out I'd really appreciate it!

Posts: 2308
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Joystick problems

Sat Jun 30, 2018 12:51 pm

It's not actually a joystick, not an analog one anyway. It's more of a hat switch, a 5 way switch. I'm using mine Ok in python using the sense hat code. If that helps.
This partial code from my full file.

Code: Select all

import os
import time, datetime
sense = SenseHat()
sense.set_imu_config(False, False, False)
sense.low_light = True

def pushed_up(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = True
def pushed_down(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = False

def pushed_left(event):
    global w
    if event.action == ACTION_PRESSED:
        w = (255)
def pushed_right(event):
    global w
    if event.action == ACTION_PRESSED:
        w = (0)

Return to “Astro Pi”