Display-o-tron HAT - Silly question. . . .how to turn off?

Newbie to Python and any GPIO activity…Just got my DOTHAT and it’s brilliant…but how do I get it to turn off the display-o-tron when I close a program?

I can start the example codes fine, but when I ctrl-c it stays lit and displaying the last information before I ctrl-c’d it - how can I turn off the display-o-tron in this scenario - am I missing something obvios?

Any help appreciated.

I think you might have to create a shutdown script that kills the running Python program, then clears the display and turns off the backlight (and graph LED’s on the HAT)

The same for when you shut the Pi down, make a script that does the same as above and then finally shuts down the Pi.

I don’t have an example script yet but it is on my to-do list…

[edit for grammar]

You can trap CTRL+C in Python:

    # Do Stuff
except KeyboardInterrupt:
    # Clean up

Or use atexit:

import atexit

def clean_up():
    # Do clean up here


thanks both - was just coming to reply that I worked out the atexit method of doing it - thanks for your assistance.

1 Like