OllieT
Posts: 4
Joined: Sun May 24, 2015 1:33 pm

Joystick Problems

Sun May 24, 2015 2:09 pm

The joystick on my astro pi hat doesn't seem to be working at all. Neither the example script ('pygame_joystick.py') nor any scripts I write myself work. All other parts of the board work correctly. I had to reinstall the AstroPi library via 'wget -O - https://www.raspberrypi.org/files/astro ... install.sh --no-check-certificate | bash' if that makes any difference. Is my joystick just broken?

Thanks,
Ollie

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Joystick Problems

Sun May 24, 2015 6:10 pm

Hi there, the Astro Pi joystick is mapped to the four keyboard cursor keys, with the middle-click being mapped to the Return key. This means that moving the joystick has exactly the same effect as pressing those keys on the keyboard.

So does the pygame joystick example work if you use the cursor keys on the main keyboard?

The only thing I can suggest is to wipe the SD card and do a complete reinstall from scratch. Don't ever do a sudo apt-get upgrade as this downgrades the kernel. Something we will fix in due course but for now just reinstall Raspbian and run the install script again as per this topic.

If it still doesn't work after that then yes you may have a broken joystick, have a close look and see if there are any cracks on it.

One thing you can be sure of though, if you write code the responds to the cursor keys and Return you'll know that it will work on Tim's Astro Pi on the ISS (if that's any conciliation). You may also be able to return the board to the UK Space Agency and get a replacement.

OllieT
Posts: 4
Joined: Sun May 24, 2015 1:33 pm

Re: Joystick Problems

Mon May 25, 2015 4:35 pm

Hi thanks for the reply.

Just realised that the reason the script wasn't working was because I was running it through SSH and so pygame wasn't able to create a display! It all works fine if I actually have a monitor. Is there any way to get the controls to work with pygame when using SSH/ no screen, or should I just use a different method for input (e.g. raw_input())?

Thanks

Joseph Burrell
Posts: 7
Joined: Mon May 25, 2015 6:23 pm

Re: Joystick Problems

Wed May 27, 2015 11:24 am

Hi

I have just set-up my Astro Pi! However, I do not know how to use the joystick in my program. What is the code for when i move it one way, it does something. Eg. If the joystick is pressed down, start a game.

Thanks! :D :geek:

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Joystick Problems

Wed May 27, 2015 2:45 pm

Joseph Burrell wrote:Hi

I have just set-up my Astro Pi! However, I do not know how to use the joystick in my program. What is the code for when i move it one way, it does something. Eg. If the joystick is pressed down, start a game.

Thanks! :D :geek:
Have a read of this guide: https://www.raspberrypi.org/learning/as ... oystick.md

ThomasS
Posts: 118
Joined: Thu Jan 23, 2014 7:05 pm
Location: Leeds
Contact: Website

Re: Joystick Problems

Sat Jun 13, 2015 8:45 pm

I have the same issue. I'm using XRDP Remote Desktop and the program works fine with the keyboard but not with the Astro Pi joystick. I've also tried the example program but to no avail.
ThomasS

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Joystick Problems

Sun Jun 14, 2015 8:59 am

You have to think of it as a keyboard plugged only into the Astro Pi. When you use Remote Desktop software the keyboard and mouse events from the client / viewing computer are sent over the network to the server which then actions them.

If you were to type on a keyboard plugged into the Astro Pi you wouldn't see anything on your Remote Desktop screen because it's not looking for events coming from that device.

Get a screen and keyboard directly on the Astro Pi and you will see that it does work.

If this is not possible then you can try running your program by putting it into /etc/rc.local just before the exit 0 line. This is like autoexec.bat in DOS.

This will be the same as running it on the Astro Pis local screen.

ThomasS
Posts: 118
Joined: Thu Jan 23, 2014 7:05 pm
Location: Leeds
Contact: Website

Re: Joystick Problems

Sun Jun 14, 2015 9:01 am

Thanks! I'll give it a try. :D
ThomasS

Return to “Astro Pi”