Page 1 of 1

Joystick Problems

Posted: Sun May 24, 2015 2:09 pm
by OllieT
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

Re: Joystick Problems

Posted: Sun May 24, 2015 6:10 pm
by Davespice
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.

Re: Joystick Problems

Posted: Mon May 25, 2015 4:35 pm
by OllieT
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

Re: Joystick Problems

Posted: Wed May 27, 2015 11:24 am
by Joseph Burrell
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:

Re: Joystick Problems

Posted: Wed May 27, 2015 2:45 pm
by Davespice
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

Re: Joystick Problems

Posted: Sat Jun 13, 2015 8:45 pm
by ThomasS
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.

Re: Joystick Problems

Posted: Sun Jun 14, 2015 8:59 am
by Davespice
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.

Re: Joystick Problems

Posted: Sun Jun 14, 2015 9:01 am
by ThomasS
Thanks! I'll give it a try. :D