Zombeatle
Posts: 26
Joined: Wed Jun 03, 2020 8:43 pm

How do you tell SenseHAT to stop?

Mon Aug 03, 2020 2:28 pm

I just got started with the Pi, started using the SenseHAT.

In the accompanying intro package, there are several small python programs. When you go to open them, they will ask if you want to execute the program, execute the program in terminal, or open python.

For any choice other than just opening python, the program runs and keeps running.

Is there a basic, simple command that I can enter into the terminal that will tell the SenseHAT to stop doing what it’s doing? Otherwise, the only option I normally have is a complete shut down each time, which of course is annoying.

Thanks

User avatar
bensimmo
Posts: 4654
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: How do you tell SenseHAT to stop?

Mon Aug 03, 2020 2:32 pm

CTRL+C if it is the currently running program in the terminal.


or
killall python3
will stop *all* python3 programs running

others will be along with other probably better, ways.

Zombeatle
Posts: 26
Joined: Wed Jun 03, 2020 8:43 pm

Re: How do you tell SenseHAT to stop?

Mon Aug 03, 2020 4:06 pm

bensimmo wrote:
Mon Aug 03, 2020 2:32 pm
CTRL+C if it is the currently running program in the terminal.
I’ve tried ctrl-c: it may or may not have stopped the program, but it left the led display lit up (it was some basic show-the-colors program). Any way to get it to stop that? Or does it just need to have another program run to supersede it?

I ran the program, then opened it in Python, hit stop (which didn’t clear out the LEDs), then ran it again. It did a kind of strobe effect, with the LEDs flashing back and forth, but once done it left the display lit. Hitting stop did nothing, neither did quit.

I’m getting the idea that it basically left things at telling the HAT to light up, and needed some sort of counter-command, sound about right?

Not that I expect to be using that program a whole lot, but it and others tend to leave some or all LEDs lit up, usually staying that way until another program runs.

trejan
Posts: 2234
Joined: Tue Jul 02, 2019 2:28 pm

Re: How do you tell SenseHAT to stop?

Mon Aug 03, 2020 4:39 pm

Zombeatle wrote:
Mon Aug 03, 2020 4:06 pm
I’ve tried ctrl-c: it may or may not have stopped the program, but it left the led display lit up (it was some basic show-the-colors program). Any way to get it to stop that? Or does it just need to have another program run to supersede it?
It will continue to show whatever was last set to be displayed so you need to run something to turn them all off. It isn't automatic.

User avatar
bensimmo
Posts: 4654
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: How do you tell SenseHAT to stop?

Mon Aug 03, 2020 6:19 pm

yes that can be a bit of a pain, but without anything to tell it to turn all the LEDs off, then it is just left as it was.

.clear is the easiest method, by default it sets them all 'off'

Have a look, I often out this at the stat of the program, so next time it is run, it clears them all.
https://pythonhosted.org/sense-hat/api/#led-matrix

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

Re: How do you tell SenseHAT to stop?

Mon Aug 03, 2020 8:06 pm

sense.clear() followed by an os.system("sudo shutdown now -P") is what I code into my Sense Hat python files.
Both of mine run headless and are shut down via a button connected to a GPIO pin.
If you terminate a running python file from terminal etc, what was last displayed is left in memory and will just remain frozen on the LED matrix. Running that same example again or running another example usually clears it out if new data is written to the LED matrix.

Return to “Beginners”