Foundations: Operating SystemI know that I want to run Raspbian, and that I won’t have a graphical user interface, so I opted to install Raspbian Lite directly. The download page has the links to the latest version of Raspbian Stretch Lite, at the time of writing 2017-11-29. It also links to the Installation Guide, which takes you through creating your card image.
As we won’t have a user interface, it would be nice to be able to go straight in using SSH, without having to worry about connecting up a keyboard and monitor. Helpfully the Raspberry Pi Foundation have documentation for that as well – see section 3. To find out what IP address your Pi has received, see here.
So at that point you should be able to get a shell session on your newly created Pi first time. Change the password like it tells you to! Next install all the updates since the image was created. This is somewhat tedious, but gives us an up to date starting point:
$ sudo apt update && sudo apt upgradeAfter the updates have been installed, reboot the system before continuing.
You need to install some packages we need, all are in the Raspbian repositories and so can be installed with apt:
$ sudo apt install screen ola wiringpi mplayer vimI have installed the vim editor here and will use it later on, but feel free to substitute whatever editor you can work and are comfortable driving, and amend the commands as required.
If you want to change the timezone, language support and so on, then you can do so using raspi-config now.
Next we will use raspi-config to set up the serial port (which is a lot easier than editing configuration files by hand). So run:
$ sudo raspi-configIn the menus, use the arrow keys to move up and down, then press Enter to select and option. Go to Interfacing Options, then choose Serial. The answer to the questions are:
- “Would you like a login shell to be accessible over serial?” No
- “Would you like the serial port hardware to be enabled?” Yes
- “Would you like boot to wait until a network connection is established?” is No.
Infrastructure: Power ControlMy Raspberry Pi has a custom power supply setup which means it can do a proper shutdown to no power consumption, like a real PC. There is some extra configuration to do for this, which you will have to skip until I get round to writing up how the PSU works. If we do not configure the raspberry pi at all, the system will boot up, because the power control pin is configured as an input, and we have a pull-up which keeps the power supply on.
To switch the power supply off when the system has shut down, the power control GPIO pin must be set up in the Device Tree.
There are a bunch of device tree blobs for this in /boot/overlays/, documented in the README. The one you want is /boot/overlays/gpio-poweroff.dtb so we add a line in /boot/config.txt
but we also need to select which GPIO pin to use (4) with the gpiopin parameter, and choose active low operation, so the final line is
note the use of active_low=y is important – just active_low doesn't work here.
Now the system turns off the power supply at the bottom of the shutdown cycle, as we wanted it to.
User Interface: GPIO scripts.I’m not going to bother installing git just to fetch one repository, so instead head over to my scripts repo on Github in a web browser on another computer. Click on the green “Clone or download” button, locate the “Download Zip” link copy the link. On your Pi, download it with wget, e.g.
$ wget https://github.com/richardash1981/pi-play-scripts/archive/master.zipand rename it something more constructive
$ mv master.zip pi-play-scripts_master.zipthen unpack the archive. This will create the directory pi-play-scripts-master/ containing the files. This also needs to be renamed to match the internal paths (which also rely upon you using the pi user).
$ mv pi-play-scripts-master pi-play-scriptsNext we need to add the scripts to rc.local so that they are run on boot.
$ sudoedit /etc/rc.localand add
# script to make power off button work
# scripts for lighting control
su pi -c '/home/pi/pi-play-scripts/stop.sh' &
su pi -c '/home/pi/pi-play-scripts/play.sh' &
Control: OLAWe have installed the Open Lighting Architecture package, but it will need some configuration. This can be done from the command line, or via the web interface on port 9090, e.g. http://192.168.0.147:9090
At the command line we list what plugins OLA has:
$ ola_plugin_infoThis looks good, what is the status of the UART?
Id Plugin Name
4 ESP Net
5 Serial USB
6 Enttec Open DMX
11 E1.31 (sACN)
13 FTDI USB DMX
18 Milford Instruments
20 UART native DMX
21 Open Pixel Control
$ ola_plugin_state --plugin-id 20OK, enable it:
UART native DMX
$ ola_plugin_state --plugin-id 20 --state enableWhilst we are here, turn off the USB Serial plugin because it spams the logs and we do not use it.
$ ola_plugin_state --plugin-id 5 --state disableNext we need some configuration. The configuration file for this plug-in lives at /etc/ola/ola-uartdmx.conf in the Raspbian package.
$ cat /etc/ola/ola-uartdmx.confSo we need to fix that, because the Pi serial port is showing up as /dev/ttyAMA0. It should read
device = /dev/ttyACM0
enabled = true
device = /dev/ttyAMA0Now we can patch universe zero to the UART output (see also OLA documentation)
enabled = true
There are quite a lot of interfaces showing (because we haven’t been round disabling them all)
$ ola_dev_infoSo I must patch device 10, port 0, your numbers may differ. You should patch to universe zero as this is what the scripts use.
Device 1: Dummy Device
port 0, OUT Dummy Port, RDM supported
Device 2: OSC Device
Device 10: UART native DMX
port 0, OUT /dev/ttyAMA0
$ ola_patch -d 10 -p 0 -u 0This should now have the output set up. To make sure these settings are saved, reboot the Pi as the shutdown will get OLA to save it’s settings.
Content: Show FilesLoad up the audio file, default lighting state file and lighting show file into the home directory (or change buttonsets.sh to reflect where they are).
$ scp gethsemene2.flac gethsemene2v4.olar default.olar lpi:You should now be good to go – press the buttons and see what happens!
Epilogue: NotesDepending on how your sound is connected you may have to use raspi-config to direct default ALSA output audio to your output device – it worked for me first time, so I haven’t included it in the instructions here, but you can force either the analogue output connector or the HDMI port as default audio destination.
It’s worth noting that I didn’t have to mess around changing the UART clock (which was originally needed) on this install – either the driver takes care of it, or the default is now high enough to make it work out of the box.