Fresh Pi Please

The Easter Trail will run again at St. David’s over the week 12th to 16th March 2018, with evening openings on Monday and Thursday evenings. So I am in the middle of setup week again. Not a huge amount is being changed, but one of the things which does need doing is an new microSD card image for the Raspberry Pi which controls the lights in Gethsemane. The previous card had been used for doing other development work and is now two years out of date, so we needed a clean start with up to date packages. Note I am still using a Pi 2 Model B, and there will be some differences if you have a Pi 3 because of the on-board wireless hardware.

Foundations: Operating System

I 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 upgrade
After 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 vim
I 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-config
In 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
Next we want to make sure that we don’t get stuck when there isn’t internet access in the venue. Go to Boot Options and select Wait for Network at Boot. The answer to
  • “Would you like boot to wait until a network connection is established?” is No.

Infrastructure: Power Control

My 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.zip
and rename it something more constructive
$ mv master.zip pi-play-scripts_master.zip
then 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-scripts
Next we need to add the scripts to rc.local so that they are run on boot.
$ sudoedit /etc/rc.local
and add
# script to make power off button work
/home/pi/pi-play-scripts/shutdown.sh &
# 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: OLA

We 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.
At the command line we list what plugins OLA has:
$ ola_plugin_info
Id Plugin Name
1 Dummy
2 ArtNet
3 ShowNet
4 ESP Net
5 Serial USB
6 Enttec Open DMX
7 SandNet
8 StageProfi
9 Pathport
11 E1.31 (sACN)
12 USB
14 OSC
15 SPI
16 KiNET
17 KarateLight
18 Milford Instruments
19 Renard
20 UART native DMX
21 Open Pixel Control
This looks good, what is the status of the UART?
$ ola_plugin_state --plugin-id 20
UART native DMX
Enabled: False
Active: False
Conflicts with:
OK, enable it:
$ ola_plugin_state --plugin-id 20 --state enable
Whilst 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 disable
Next 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.conf
device = /dev/ttyACM0
enabled = true
So we need to fix that, because the Pi serial port is showing up as /dev/ttyAMA0. It should read
device = /dev/ttyAMA0
enabled = true
Now we can patch universe zero to the UART output (see also OLA documentation)
There are quite a lot of interfaces showing (because we haven’t been round disabling them all)
$ ola_dev_info
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
So I must patch device 10, port 0, your numbers may differ. You should patch to universe zero as this is what the scripts use.
$ ola_patch -d 10 -p 0 -u 0
This 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 Files

Load 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: Notes

Depending 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.

No comments:

Post a Comment