Automating the Subsystems (Scripting)

A project log for The Guitar Pedal Project: Multi-Effect Processor

A guitar multi-effect stompbox that allows musicians to create new and never-before-seen effect creations using their mobile phone.

ben-jacobsBen Jacobs 05/12/2020 at 16:370 Comments


In order for the pedal system to function with no human-interaction after booting the Raspberry Pi, some actions need to be automated with scripts. Namely:

Running Scripts with Crontab

To accomplish this list of tasks with automation, bash scripts were employed, in conjunction with a Linux tool called Crontab. Crontab allows editing a system file (also called crontab) which allows user entry in a specific format, which is then decoded by the OS into instructions for it to run certain terminal commands at certain times of day, or in our case, when certain events occur, like shutdown or boot. You can familiarize yourself with Crontab here: Ubuntu Cron How-To.

Below are the three entries in our team's Crontab file. The first line runs PureData and the second line runs the Human Interface Python script. Note the '@reboot' statement preceding every command. This says "run this line when the OS boots". Also notice the '&' character after every line. This says "do not wait for a return from this command, move on to the next one without hanging the terminal".

If you are duplicating this project for your own use, make sure to include the proper name and paths to these files- your file-paths or script names could be different.

@reboot sudo bash /home/patch/Scripts/ &

@reboot sudo python3 /home/patch/Scripts/ &

Script Spotlight:

The script handles opening the PureData DSP engine and starting audio processing. Below is the full code of this script.

sudo amixer -c 0 cset numid=4 on
sudo pd -rt -nogui -r 48000 /home/patch/Documents/Pd/effect.pd &

 In the code above, the first line tells the OS that this is a Bash Script. The second line is a call to alsamixer (the ALSA sound level and mixing tool). The option '-c 0' stands for "Use card #0", which should be the WM8731 Codec from the Audio Subsystem.

The option "cset numid=4 on" causes ALSA to enable control number 4 on card 0. In our case, this vaguely named control maps to the "Line Input Mux". This is a feature of the WM8731 card which allows a user to choose whether audio input comes from the microphone input, or the line level input. For our purposes, we want the line input, so we set this mux control to 'on'.

Finally, the third line opens PureData. Notice that it is prefaced with "sudo" to run as the root user. The '-rt' option stands for "real time audio", the '-nogui' option tells PureData to run without a graphical interface (you may wish to omit this option if you're still debugging using the desktop environment so that you can actually see the PureData window come up). Lastly, the file path to the effect that should be run is provided.

This script doesn't need to be run through crontab, either. It can be called manually from the terminal during a normal desktop session for debug purposes, too. In fact, it is encouraged to always launch PureData from this script, because the 'amixer' command preceding it ensures that the system audio is set up properly (avoids bugs).

Script Spotlight:

This is the Python script which handles the human interface, and links the physical knobs to the PureData DSP engine. This script is examined in detail under the Project Log for the Human Interface Subsystem.