Skip to content

Running Puredata on the Raspberry Pi

2012 June 1
by Tedb0t

I’m thrilled to say that today I succeeded in getting Puredata running on my Raspberry Pi. Here’s how!

First, follow this guide to get your Pi set up for the first time.  Make sure your Pi is connected to the internet, and now we can install Puredata.  We’ll start with Vanilla, since pd-extended is not maintained for ARM (as far as I can tell).  I’ll explore getting pd-extended working in a future post (hopefully very soon).

sudo apt-get update
sudo apt-get install puredata

Easy. What’s not easy is getting sound working. This took me about half the day but here’s what worked:

sudo apt-get install alsa-utils
sudo modprobe snd_bcm2835

Note that the modprobe line needs to be run every time the Pi is booted, so you can add it to an .rc file if you want.  Now connect some speakers, turn them down for safety, and run this to make sure sound works:

sudo aplay /usr/share/sounds/alsa/Front_Center.wav

If it works, good! You can now run a Pd patch like so:

pd -nogui -noadc -alsa testPatch.pd

For convenience, here’s my test patch (testPatch.pd) that outputs an LFO’d sine wave. *Important!* Notice in the patch that the loadbang is delayed by 100ms! This is deliberate to avoid a bug in Pd regarding ALSA.

Please let me know if this worked for you.  Happy hacking!  Next up, I’ll be trying to build Pd-extended and then tackling the Raspberry Pi’s General Purpose I/O.

UPDATE:

You’ll notice that the sound quality out of the 1/8″ jack is messed up in some cases (most in my experience).  I’ve heard from various sources that the R-Pi does not use a “real” DAC (Digital-to-Analog-Converter) and that you should get better sound from a USB adapter or from the HDMI output.  Still following up on this.

Related Posts:


33 Responses leave one →
  1. Knud Riishøjgård permalink
    June 2, 2012

    Great, thank you. My Pi is on its way :)

  2. newdendrite permalink
    June 4, 2012

    PD is running on my RPi after following your instructions.  Many thanks!

    You might want to let users know that this command is required after every reboot:

    sudo modprobe snd_bcm2835I wasn’t savvy enough to know that. The PD-extended version will be great.

    • Ted Hayes permalink
      June 4, 2012

      Excellent point, I updated the post! Thanks!

    • Rich permalink
      June 7, 2012

      Did you get audio to play from the pd command? I wasn’t able to. :(

  3. newdendrite permalink
    June 5, 2012

    Is there any chance you might be willing to take a look at PD under Raspian?  The Raspian build offers hardware math and would probably allow more to be done with PD on the RPi.  I’ve tried to run PD with the current build, but there are problems.   Running aplay to test alsa gives errors.  The new patcher window for PD shows no menus.  Thanks!

    • Ted Hayes permalink
      June 5, 2012

      I’d like to check out Raspian, not sure when I’ll get a chance to though.  It sounds like you’ll want to recompile Pd for that OS.  I’m working on a tutorial for building pd-extended that should apply, so stay tuned!

      • newdendrite permalink
        June 5, 2012

        If I read the documentation correctly, the repository contains Rasbian builds for both PD and alsa-utils.  Apparently they built without errors, but they do not function in Rasbian in the same way they do in Debian Squeeze.  (In fact, they don’t function well enough to use.)

  4. Rich permalink
    June 7, 2012

    I couldn’t get this working. It looks like it is working but no sound comes out. I am able to play the test wav file without problem.

    richc@raspberrypi:~$ pd -nogui -noadc -alsa testPatch.pd
    Running: bang
    ^CPd: signal 2
    richc@raspberrypi:~$ sudo pd -nogui -noadc -alsa testPatch.pd
    priority 6 scheduling enabled.

  5. June 11, 2012

    yeah so how do i run it and start patching?

    • Ted Hayes permalink
      June 11, 2012

      These instructions are for headless systems (without a monitor).  To run the Pd GUI I believe you need to start XWindows (startx), but I haven’t tried this.  Check the Raspberry Pi wiki to be sure.

      Otherwise, the last command (pd -nogui -noadc -alsa yourPatch.pd) IS how you run a patch.

  6. tobie permalink
    June 13, 2012

    hi,

    hmm, everything seems ok, though I hear no sound and see this output:

    pi@raspberrypi:~$ pd -nogui -noadc -alsa testPatch.pdcouldn’t open MIDI input device 0couldn’t open MIDI output device 0opened 0 MIDI input device(s) and 0 MIDI output device(s).Running: bang
    Any thoughts about next steps?

    bests,
    Tobie

  7. tobie permalink
    June 13, 2012

    sorry, lost line breaks:

    pi@raspberrypi:~$ pd -nogui -noadc -alsa testPatch.pd
    couldn’t open MIDI input device 0
    couldn’t open MIDI output device 0
    opened 0 MIDI input device(s) and 0 MIDI output device(s).
    Running: bang

  8. leolodreamland permalink
    June 13, 2012

    Remember the headphones out is not enabled if the hdmi cable is attached.

    • tobie permalink
      June 15, 2012

      Yup, the following line produces sound through speakers connected to headphones out:
      sudo aplay /usr/share/sounds/alsa/Front_Center.wavBut when I run the patch there is no sound.

      Do I need to set up PD so that it is using a particular device? I noticed “ALSA Midi” amongst others, as discussed here:

      http://en.flossmanuals.net/pure-data/ch010_configuring/

  9. Jethro permalink
    June 23, 2012

    Thanks for the walkthrough! Although I can get the test patch to work through XWindows, running it from the shell doesn’t produce any sound for me. Any idea what might be getting in the way? Interestingly, when I run the patch from the desktop I get the
    recurring error message ‘DAC blocked’ in the display, despite the
    program functioning correctly. Any help would be greatly appreciated.

    Thanks,
    Jethro

  10. ian permalink
    July 5, 2012

    I needed the following to get it going:
    pd -nogui -alsa -audiodev 1 -outchannels 2 -noadc testPatch.pd

    Use for linux beginners (like me) you can use Finder to transfer files:
    sudo apt-get install netatalk

    • ian permalink
      July 5, 2012

      PS many thanks for the guide!!

    • ian permalink
      July 5, 2012

      but.. the audio is glitchy. I tried various buffer sizes (-audiobuf), no dice! Did anyone get clean audio working?

      • Didier permalink
        February 14, 2013

        Hi, add -rt to puredata command line and works great using audio port !!

  11. anechoic permalink
    July 15, 2012

    fantastic! thanks for posting this info! :)

  12. September 2, 2012

    Can i use te TUIO protocol with the raspberry PI? I usually use Reactivision and Pure Data Extended altotogether, and thats so easy to run in my mac mini, but wath about using a rasberry pi? it is possible? Please,
    hurry up with the pd extended.

  13. brandotan permalink
    September 6, 2012

    i still have some problems with the audio quality. it is sounds a little bit distorted. any suggestions?

  14. September 27, 2012

    Excellent tutorial. I ran everything you have here and had it running in a few minutes. I’m now going to try some more complex patches and see if I can get it going.

    The analog out worked first time, even with hdmi attached. I’ll have a look at triggering by midi soon.

    Thanks a lot!

  15. schanq permalink
    October 18, 2012

    Great Tutorial Thanks. The newer versions of Rasperian Wheezy come with modprobe snd_bcm2835 already added to an .rc file. Also anyone struggling to get sound running properly should check out the magpi issue 03 page 04 for instructions on how to get sound setup: http://issuu.com/themagpi/docs/the_magpi_issue_3_final?mode=window.

    As it stands the audio jack output is terrible. Hdmi is ok but still produces some glitches and I constantly have an audio IO error warning in the PD window. Is this common or is my installation dodgy?

  16. javimm permalink
    November 16, 2012

    I managed to get this working.

    At first I was having crappy sound quality, but by running “pd -nogui testPatch.pd” with no -alsa nor -noadc, got it sounding perfectly.
    A hint for those without sound. Try alsamixer and rising the volume. Worked for me.

  17. ebster permalink
    December 30, 2012

    how do you add it to a rc. file?

  18. January 21, 2013

    Here’s an update about the sound from Miller Puckette on the Pd list: “I just now tried again (after some months of not fooling with it) and got audio in+out working with no trouble at all… from a clean and recently updated Raspian install (i.e. ‘apt-get update; apt-get upgrade) I just deleted pulseaudio: apt-get remove pulseaudio and then slowed my USB down to 1.1 speed by adding the setting:
    dwc_otg.speed=1
    to the file /boot/cmdline.txt
    plugged in a Griggin iMic (bout $25 I think) and immediately got full-duplex audio. I’m running only one channel in and tried it with an electric guitar with the iMic switched to ‘mic in’ and all worked. I was able to get audio latency down to 10, didn’t try any lower than that.
    This is all without any mouse, keyboard or video monitors connected to the pi – I’mm SSH-ing in. Last time I got up to this point, things started to degrade when I put other USB devices on so I’ll try that now…”

  19. Peter Gardner permalink
    February 15, 2013

    I had problems just playing the wav file (from analog out, I never tried HDMI). Everything seemed to be working, but no sound would come out. Eventually, I found this page:

    http://www.raspberrypi.org/phpBB3/viewtopic.php?t=27213&p=243634

    which is about HDMI audio but one of the comments mentions the analog out. Malakai said :

    To get sound out the headphone jack type:
    sudo modprobe snd_bcm2835
    sudo amixer cset numid=3 1

    This solved my problems.

  20. Mikkel Gravgaard permalink
    March 14, 2014

    Got it working today with newest Raspbian and on-board analog audio without any glitches, even though I’m running with GUI over VNC.

    So it seems something got optimized. Though my patch only consists of an osc~ connected to a dac~ ;-)

    I had to select the analog output with

    sudo amixer cset numid=3 1

    but that was it. No other hacking needed.

    Also, don’t go over dB gain 0 in alsamixer, else you’ll get distortion.

Trackbacks and Pingbacks

  1. How to build Pd-extended on the Raspberry Pi | Limina.Log
  2. van der Kwast Sébastien » Pure-data : ressources diverses

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS