This hasn’t been any where near as straightforward as I’d hoped, so here are some of the steps I’ve taken to try and make it happen.
The first problem is that Processing needs an window environment to operate, which means that it won’t run on a Pi which has no screen or keyboard attached. There is a hack for this, that fools Processing into thinking it has actual windows to work with. As recommended at this site (https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=86352), install matchbox-window-manager:
The steps, to paraphrase, are:
1 |
sudo apt-get install matchbox-window-manager |
Next, we need to get the Pi to automatically log in to a user. I’m using the default user here, and so followed the first part of the instructions at this site: http://www.akeric.com/blog/?p=1976
I quote:
Auto login to the Pi:
The first thing to solve is how to get the RPi to auto-login, thus removing the necessity of a connecetd keyboard & monitor (or ssh) to get things running. This doc completely covers it: http://elinux.org/RPi_Debian_Auto_Login. But to paraphrase, this is what you need to do:
Edit /etc/inittab , the file that controls the startup \ initialization process of the Pi. Do a “What is /etc/inittab” in Google for a far more robust answer on the specifics of what it does.
1 |
$ sudo nano /etc/inittab |
In that file, comment out this line:
1 |
1:2345:respawn:/sbin/getty 115200 tty1 |
Like so:
1 |
#1:2345:respawn:/sbin/getty 115200 tty1 |
And place this line under it:
1 |
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1 |
Replacing “pi” with the user you want auto-logged on on power-up. Reboot the Pi, and watch it auto-login. Magic.
Next we need to make a script to set up the phony window environment and open our Processing app. I’ve exported my app from the Processing environment already, and it’s saved in my home folder. You can copy and paste the path to your own app into these instructions.
So, to make the script (called script_auto_run), we follow these instructions from this web page: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/scripts
Create a folder to store the script in
1 2 3 |
mkdir ./bin cd ./bin |
Create the script using the nano text editor
1 2 |
sudo nano script_auto_run |
In the nano editor, type this script:
1 2 3 4 5 |
#!/bin/bash # off we go echo "Starting window manager" matchbox-window-manager & /home/pi/sketchbook/RUI/FinalTap/application.linux32/FinalTap |
Note that when executing a command without logging is as a user you can’t depend on any path or environment variables so you must provide full paths to everything. This is important, as any paths to external data files in your Processing sketch need to be absolute.
Save it by pressing Ctrl+X, ” Y”, ENTER
This script needs to be made executable by typing this :
1 2 |
sudo chmod 755 script_auto_run |
Test it in terminal:
1 |
xinit /home/pi/script_auto_run |
And for me, this works!
Now to get it to run on startup. Instructions now are from this site:
Using sudo nano, make a script called
1 |
script_autostart |
in the /home/pi/bin/ folder (or, anywhere, I think). The code for this is here:
1 2 3 |
#!/bin/bash echo "starting xinit" xinit /home/pi/script_auto_run |
We then make this new script_autostart executable
1 |
sudo chmod 755 script_autostart |
Then we set this script to start up on boot. Instructions here are from http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/scripts:
Setting it to be run
To launch the script at start-up edit the “rc.local” file needs to be edited.
1 2 |
sudo nano /etc/rc.local |
Amend to say the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi # Auto run our application /home/pi/bin/script_autostart exit 0 |
So, on startup, the Pi automatically logs in, then script_autostart gets called which initiates the window environment and starts up our app.
Considering I’m a complete and utter Pi newb, this feels like a significant victory! Thanks so much to the various authors of the instructions I followed – I’m very grateful for your help!