MicrodotPhat - dumb Python question

I’m building a retropie console inside an old Atari 2600 case. I’ve set up my MicrodotPhat as a mini-screen inside the old cartridge port. I’m very new to Python and Raspian and right now I’d be happy just to have the MicrodotPhat permanently display the word “Atari”.

I’ve followed the docs and can get the microdotphat to display what I want within a Python session, but the microdotphat turns blank as soon as I exit() from Python. I can also tweak the python scripts in the microdotphat examples folder to display what I want, but the script either exits immediately and blanks the screen, or if I use ‘time’ it locks up the Raspberry Pi until I ctrl-c (and then blanks the screen).

Please can someone help out this poor noob and let me know how to keep the screen display on without locking up the Raspberry Pi in a Python session (i.e., so that it can display “Atari” while Retropie continues running?). Thank you!!!

You could likely call up your python file on boot up via crontab, and run it as a service in the background.
run sudo crontab -e
then add the following line to that file and save it.
@reboot python3 /home/pi/atari.py &
Change the atari.py to the file you want to run.
The code you want to repeat should be in the “while true” section.

Thank you lots! I’m still working on this, but at least now I’m going in the right direction :)

No problem, if your like me, its one long never ending learning experience.;)
It can be very rewarding and a lot of fun though, you just have to keep at it. =)

I’ve now realised that there is a simple way of doing this - the microdotphat python library has a command

set_clear_on_exit (False)

that leaves the screen on when the Python script terminates. Doh!

I usually have just the opposite issue. The screen doesn’t blank when my file terminates and my Pi shuts down. I have a couple of headless setups with Sense Hats and LED Shims. I shut down but leave them powered so I can boot back up with a button press. I display info in a scrolling message on the LED matrix, I want that off on shutdown. I end up adding extra code to turn all the LED’s off on the LED Shim and Sense Hat, then do the shut down.
Anyway, glad you sorted it out, and thanks for posting the answer. =)

I actually have the same issue on shutdown (sigh). My microdotphat continues to display whatever is on its screen. I’ve prepared a simple python script to blank out the screen (it’s still technically on, but with no pixels lit up - which is good enough for me).

When I press the fan shim button, I can see that it runs some kind of bash (?) script to shut the system down safely. I’d like to launch my short python script from the shutdown script, but embarrassingly I have no idea where to find the shut down script!

Do you know what script the fan shim button calls when you press it to shut down?

No I don’t. So far I haven’t had to go looking for it. There are ways around it though. The fan shim can be run without the Pimoroni software, and still have temperature control.
There is a dtoverlay entry you can add to the config.txt file.
dtoverlay=gpio-fan,gpiopin=18,temp=55000 will turn it on at 55c and back off at 45c.
Just change the 55000 to what you want it to turn on at.
The fan shim button will still boot the Pi up if it was shutdown and left powered.
It won’t do a shutdown without another overlay though.
I have tested both and they work. Instead of the second overlay you could use that GPIO to execute your turn off and shut down.
I have used os.system("sudo shutdown now -P") in my python files. Put it after the led clear statements. The python code will be something like this.

import RPi.GPIO as GPIO

GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

def Shutdown(channel):  
    your clear and shutdown code here    

EDIT: forgot to mention, if you want to try the above you’ll want to turn off and disable the fan shim service.

cd fanshim-python
cd examples
sudo systemctl stop pimoroni-fanshim.service
sudo systemctl disable pimoroni-fanshim.service

to turn it back on its

cd fanshim-python
cd examples
sudo systemctl enable pimoroni-fanshim.service
sudo systemctl start pimoroni-fanshim.service

Thank you very much for taking the time to give me such a detailed and helpful response! I really appreciate it. It’s 2am here now, but I’m going to have fun playing with this in the morning…

I’ve done it both ways, with the fan shim service and with the dtoverlays. For me it kind of depends on what else that Pi is doing. I also modified my fan shim so the fan goes off when I do a shutdown. No having to unplug the power supply.
I press the button Pi shuts down, fan turns off.
Press it again and Pi boots up, fan turns on when turn on temp is reached.

You can also load the service with a --noled and or a --nobutton option.
sudo ./install-service.sh --on-threshold 55 --off-threshold 40 --delay 2 --noled --nobutton
I turn the led off.