Pd on Raspberry Pi
Here is a quick tutorial on how to install and run Pure Data headless on a Raspberry Pi. The instructions assume you want to start with a new clean Raspbian system image and do it all from scratch.
The instructions also assume you have a Raspberry model B, a USB soundcard like Terratec's Aureon Dual USB and an ethernet cable with internet access (just connect the ethernet cable between your RPi and your home router).
What you get after following the below tutorial is an SD card with a Pd patch that automatically starts when the RPi is booted.
- Put the Raspbian image onto a +4GB SD card (it is easily done with balenaEtcher).
- On newer versions of Rasbian, activate SSH by creating an empty file called 'ssh' directly on the SD card
- Insert the SD card+ethernet+usbsoundcard and power up the RPi
- Open the terminal application on your laptop and type...
ssh email@example.com #password is 'raspberry'
See notes below if fail.
When successfully logged in run this on the RPi...
and do the following system configurations...
- Select expand filesystem (only needed on Wheezy and older versions of Raspbian)
- Change user password
- Optionally lower the GPU memory under advanced / memory split
- Select finish and reboot
Log in again from laptop with your new password...
ssh firstname.lastname@example.org sudo apt-get update #check for new updates sudo apt-get upgrade #update any old packages sudo apt-get dist-upgrade #update the distribution
lsusb #should list the USB soundcard aplay -l #should also list the soundcard sudo speaker-test -t sine -c 2 -Ddefault:CARD=Device #should sound if headphones connected. Stop with ctrl+c
Note: this assumes that your USB soundcard name is Device - check what the
aplay command posts and edit the
CARD= in the line above if needed.
Download and install Pure Data + required packages with...
sudo apt-get install puredata
Test Pd patches
Copy the following two example Pd patches (or download the attachments below) and save them on your laptop (here assume on the desktop). To copy Pd patches just paste the cryptic text into a plain text editor and save with .pd file extension.
#N canvas 1068 88 450 300 10; #X obj 238 159 dac~; #X obj 235 73 osc~ 400; #X obj 289 73 osc~ 404; #X msg 126 154 \; pd dsp 1; #X obj 126 83 loadbang; #X obj 126 123 del 100; #X text 42 122 important ->; #X obj 238 111 *~ 0.2; #X obj 280 111 *~ 0.2; #X connect 1 0 7 0; #X connect 2 0 8 0; #X connect 4 0 5 0; #X connect 5 0 3 0; #X connect 7 0 0 0; #X connect 8 0 0 1;
#N canvas 1068 88 450 300 10; #X obj 238 230 dac~; #X msg 126 154 \; pd dsp 1; #X obj 126 83 loadbang; #X obj 126 123 del 100; #X text 42 122 important ->; #X obj 238 24 adc~; #X obj 238 53 delwrite~ del1 500; #X obj 238 123 delread~ del1 500; #X obj 259 80 delwrite~ del2 750; #X obj 280 144 delread~ del2 750; #X obj 238 182 *~ 0.2; #X obj 280 182 *~ 0.2; #X connect 2 0 3 0; #X connect 3 0 1 0; #X connect 5 0 6 0; #X connect 5 1 8 0; #X connect 7 0 10 0; #X connect 9 0 11 0; #X connect 10 0 0 0; #X connect 11 0 0 1;
Copy Pd files to RPi like this (run this in the terminal on the laptop)...
scp ~/Desktop/testsines.pd email@example.com:/home/pi/ scp ~/Desktop/testmic.pd firstname.lastname@example.org:/home/pi/
This is also how you can transfer more Pd patches later on.
Run Pure Data
ssh email@example.com #log in from laptop again pd -stderr -nogui -verbose -audiodev 4 testsines.pd #stop with ctrl+c pd -stderr -nogui -verbose -audiodev 4 testmic.pd #stop with ctrl+c
Note: if no sound test with different audiodev - 4 is usually the USB soundcard. You will also need to connect headphones or speakers for the first example to work. And some kind of audio input (e.g. electret mic or line-in from an MP3 player) for the second example (testmic) patch to work.
Here is how to start Pd and run a patch at boot...
nano autostart.sh #creates a new file. Copy the two lines below into this new file. (save and exit with ctrl+o, return, ctrl+x) #!/bin/bash pd -nogui -audiodev 4 /home/pi/testsines.pd chmod +x autostart.sh #make the autostart.sh file executable crontab -e #and add at the end... (again save and exit with ctrl+o, return, ctrl+x) @reboot /bin/bash /home/pi/autostart.sh
After rebooting (with the
sudo reboot command) the sine tones patch should have started automatically.
ssh firstname.lastname@example.org #log in from laptop once more sudo pkill pd #stop Pd sudo halt -p #turn off the RPi safely
- If you cannot log in and you get
ssh: Could not resolve hostname raspberrypi.local, you might need to replace
raspberrypi.localwith the exact IP address of the RPi (e.g.
ssh email@example.com). The exact address will vary and can be found in your router setup.
- Note: if you get
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!then run the command
ssh-keygen -R raspberrypi.localto reset the SSH key.
- When ready with everything and you have the correct Pd patch autostarting you can (on the older RPi models with a full-sized SD card) physically lock the SD card. This will put it in no-write mode and possibly prolong its life (especially if you cut the power without properly turning off the system with
- If you experience audio dropouts you might try the suggestions here. Most important force USB1.1 and set CPU governor to performance mode.
- If you get
ALSA output error Device or resource busywhen trying to start Pd, then delay the
;pd dsp 1message in your Pd patch with about 100 milliseconds.
- To remove the autostart just delete the file autostart.sh and go into cron again and remove the last line you added with
- 160109: also works great on a Raspberry Pi 2 with 2015-11-21-raspbian-jessie.img
- 180102: updated for 2017-11-29-raspbian-stretch.img and 2017-11-29-raspbian-stretch-lite.img