Autostart ScratchGPIO projects

Sometimes it can be useful to make your Pi autorun something when it is switched on.

With ScratchGPIO, you can autorun a Scratch program (it doesn’t have to be one controlling the GPIO pins but ScratchGPIO is needed to make it autorun

There are 3 steps – create a launchscript, create a shortcut to it and finally create a Scratch script that autoruns its GreenFlag event on startup

Create Linux Script

Run LX Terminal

mkdir -p  /home/pi/.config/autostart

nano scratchauto.sh

then type in following

cd /opt/scratchgpio8
sudo python scratchgpio_handler8.py &
scratch “/home/pi/Documents/Scratch Projects/autostart.sb”

CTRL-X then Y to save

chmod +x scratchauto.sh

Create shortcut to Launch the Script

Simply right-click on ScratchGPIO8 and select Open With then Text Editor

Then simple change the Exec and Name lines to:

Exec=/home/pi/scratchauto.sh

Name=Scratch Auto Start

then save the modified desktop shortcut as:

/home/pi/.config/autostart/scratchauto.desktop

Create a Scratch Autostart script

Make the Scratch script include the following in its On Green Flag Event

autostart

Then press the Green Flag to set AutoStart to True and save it as autostart in the normal /home/pi/Documents/Scratch Programs folder

Reboot your Pi and it should automatically run the Scratch autostart.sb file

Dealing with the Remote sensor connections pop-up

This information now superceded if using NuScratch – see https://www.raspberrypi.org/forums/viewtopic.php?f=77&t=128979&p=862545#p862121

Old info left below as its still applies to all other Scratch 1.4 edidtions (PC/Mac/Intel Linux)

(Information from http://www.penguintutor.com/news/raspberrypi/scratchautostart)

There is one further issue which may or may not cause a problem with your script.

When ScratchGPIO runs, a pop-up message “Remote sensor connections enabled” appears and prevents Scratch from receiving keyboard events until it is dismissed.   This may or may not be an issue for you.  It it is then it needs to be turned off within the Scratch application, which is one of the hidden settings within Scratch.

After launching Scratch shift left-click on the R in the Scratch logo (top left) and choose “turn fill screen off”. Click on the white area to the right or bottom of the screen and choose “Open” and “Browser”. Navigate to the section Scratch-UI-Panes -> ScratchFrameMorph -> menu/button actions -> enableRemoteSensors and remove the line:

Dialogboxmorph Inform: 'Remote Sensor Connections Enabled' Localized

This can be seen in the screen shot below.

Disable Remote sensor connection enabled message in Scratch

Then click with the centre mouse button (or Ctrl and left button) and choose Accept (s).

You can now remove the white space in Scratch by shift left click on the R in Scratch logo and choose Turn Fill screen on. Finally shift left click on the logo again and choose “save image for end-user”

Simon