lmoss30
Posts: 66
Joined: Mon May 28, 2012 11:45 am

Buttons

Sat Sep 26, 2015 7:53 pm

The buttons on the flight Astros Pis how are they wired, do they come of the sense hat direct?sorry if this has been asked before

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2070
Joined: Thu Jul 11, 2013 2:37 pm

Re: Buttons

Sat Sep 26, 2015 8:18 pm

There is an interstitial board fitted to the AstroPi flight models that brings 6 GPIOs through some hardware debounce to the case-mounted buttons.

The button-GPIO mapping is as follows:
UP = 26
DOWN = 13
LEFT = 20
RIGHT = 19
A = 16
B = 21

We actually use a gpio-keys devicetree overlay to implement these buttons. They map to keyboard keys u / d / l / r / a / b respectively, which allows us to use Linux standard event drivers to respond to button presses.

The SenseHAT joystick maps the canonical direction keys (Up/Down/Left/Right) and centre push (Enter) in the same fashion.
Rockets are loud.
https://astro-pi.org

User avatar
dliloch
Posts: 168
Joined: Wed Jun 27, 2012 6:28 pm
Location: cleveland, ohio usa

Re: Buttons

Sat Oct 10, 2015 1:33 am

I have a python script in a @reboot user crontab. The pygame command to look for a down joystick works fine when running in a command window but not in crontab.(if event.type == pygame.KEYDOWN). so could I test gpio pin 13 instead? I need someway to have the sensehat run a shutdown command since it will be run headless.. If I just pull the power I am worried that I will corrupt the sd card.
thanks...

AndersM
Posts: 33
Joined: Sun Sep 06, 2015 1:18 pm

Re: Buttons

Sun Oct 11, 2015 9:39 am

I need someway to have the sensehat run a shutdown command since it will be run headless
Have you tried this new stick class?

EDIT:
Made a test script called stickpoweroff.py based on the new class:

Code: Select all

from sense_hat import SenseStick
import os

stick = SenseStick()

for event in stick:
        if event.key == stick.KEY_ENTER :
            os.system("poweroff")
        elif event.key == stick.KEY_UP :
            os.system("reboot")
And ran it by adding this line in rc.local

Code: Select all

python3 /home/pi/stickpoweroff.py &
It seems to work. :)

User avatar
dliloch
Posts: 168
Joined: Wed Jun 27, 2012 6:28 pm
Location: cleveland, ohio usa

Re: Buttons

Sun Oct 11, 2015 3:46 pm

thanks so much! It worked! :-)
-don

AndersM
Posts: 33
Joined: Sun Sep 06, 2015 1:18 pm

Re: Buttons

Sun Oct 11, 2015 4:07 pm

:)

Hm ... how do I turn it on again? ;)

The lack of on/off switch is a bit annoying.

Return to “Astro Pi”