Raspberry Pi on a hot day


Whatever is causing my Pi to crash corresponds with a spike in heat, but I now suspect it’s not caused by the heat, but rather the heat is generated by whatever is crashing it. The pi is meant to deal with heat problems on it’s own. I’m leaving this up because parts of it are interesting, like suspending processes, writing functions, etc

A specific case

Let’s say you want to build the latest version of inkscape on your raspberry pi computer. And let’s say you want to install it via dpkg. You may find it crashes from overheating.

Fortunately, I’ve got a script for you.

Before running the script, do the following:

  • sudo nano /etc/apt/sources.list
    • Uncomment the line with deb-src in it
  • sudo apt-get update && sudo nice apt-get upgrade -y
  • sudo apt-get build-dep inkscape -y
  • sudo apt-get install build-essential dpkg-dev fakeroot cmake bzr dh-make -y
  • sudo apt-get remove inkscape
  • sudo apt-get autoremove

Then, when it’s done:

./pi_build_inkscape.sh && cd ~Downloads/ && sudo dpkg -i inkscape*.deb

The General Principle

What you need for any overheating for of problem is the ability to check the temperature and then pause processes until it falls. First, how do we check the temperature? Bash functions can’t return values, so we’ll write a global variable.



function get_temp {

echo "$deg c"

That’s good. We can do some testing with $deg and put a process to sleep and wake it up again. But we also need to do subprocesses! We’ll do some recursion.

function pause_proc {
  #renice -n 15 $1
  kill -TSTP  $1
  for i in `ps -ef| awk '$3 == '$1' { print $2 }'`
    #echo "pausing $i"
    pause_proc $i

function resume_proc {
  kill -CONT $1
  for i in `ps -ef| awk '$3 == '$1' { print $2 }'`
    #echo "restarting $i"
    resume_proc $i

Now we just need some way to track if a process is still running, and to sleep between temperature checks etc etc

function run_proc {

  echo "$deg c " `date +%X`

  while kill -0 "$1"; do #run this loop while the process is running


    if [ $deg -ge 49 ] ; then # high temperature is 49
      echo "too hot! $deg c " `date +%X`

      pause_proc $1 # Do this every time in case we missed some last time
      if [ $sleep -eq 5 ] ; then
      elif [ $sleep -eq 10 ] ; then
      elif [ $sleep -lt 5 ] ; then
    if [ $stopped -eq 1 ] ;then
      if [ $deg -le 47 ] #Ok temperature is 47
        echo "cool enough $deg c " `date +%X`
        resume_proc $1

    sleep $sleep


I picked the temperatures of 47 and 49 based on when my pi tends to crash. theoretically, it should be ok up through the 60’s. If you don’t know what’s going on with your pi getting too warm, you can also set a loop in another window to print out the temperature in a loop.

So if we want to use this for some intense process in a script, we could put those functions at the top (under the #!/bin/bash ), and run our command like:

nice -n 15 some_command arg1 arg2 &
run_proc $!

Or if you want to make this a script you can run from the command line with your intense command:

nice -n 15  $@ &
run_proc $!

To add extra resilience to my poor pi, I’ve also put a heat sink on the CPU and, right now, it’s sat in a dry bowl which is sat in another bowl which is full of ice. It’s like one of those old Supercomputers, except probably faster.

Publishing Live Notation

My piece Immrama is a live notation piece. A python script generates image files, as the performance is happening, which are put on a web page. Performers connect via any wifi device with a web browser to see the notation. It uses really simple technologies, so nearly any device should work. A Newton won’t (I made enquires) but an old Blackberry will.
Setting it up requires python and a web server and a lot of faff. It could be packaged into a mac app, but I’m working on linux and it seems like more and more people in the arts are turning to windows, as Apple increasingly ignores their former core audience of artists and designers. It runs fine on my laptop, of course, but I don’t want to have to provide that to anybody who wants to do the piece. Nor do I want to force ensembles to have IT people on hand. Fortunately, I think I’ve stumbled on how to package this for the masses.
I’m working right now to get it all running on a Raspberry Pi. This is a tiny, cheap computer. Instead of having a hard drive, it uses SD cards. This means that I can set everything up to run my piece, put it all on an SD card, and then anybody can put that SD card into their Raspberry Pi and the piece will be ready to go! …In principle, at least.
This piece needs wifi, which does not come with the Pi. Pi owners who want wireless networking get their wifi dongles separately. I got mine off a friend who didn’t need it any more. And while setting up the networking bit, I found at least three different sets of instructions depending on what dongle people have. I could try to detect what dongle they have and then auto-install needed software to match, but, yikes, there are many things I would rather do with my life. I think instead, if you order an SD card, by default, it should come with a dongle – the buyer can opt out, but not without understanding they may need to install different libraries and do some reconfiguring.
Or, I dunno, if you want to run the piece and don’t want to buy a dongle, send me yours and I’ll get it working and send it back with an SD card?
My last software job was doing something called being a release engineer – I took people’s stuff that worked on their own machine and packaged it so the rest of the world could use it. I wanted to be a developer, but that was the job I could get. It seems like I’m still release engineering, even as a composer.
Anyway, this is all very techy, but the point here is to prevent end users from having to do all this. When I’m done, I’ll make an image of the card and use that to make new cards, which I can post to people, saving them my woe. Or, even better, some publishing company will send them to people, so I don’t need to do my own order fulfilment, because queuing at the post office, keeping cards and dongles on hand, etc gets very much like running a small business, which is not actually the point.

Tech Notes so far

Later, I’m going to forget how I got this working, so this is what I did:

  1. Get Raspian wheezy, put it on a card.
  2. Boot the Pi off the card
    1. Put the card in the Pi
    2. Plug in the HDMI cable to the monitor and the Pi
    3. Connect the Pi to a powered USB hub
    4. Put the dongle on the powered hub.
    5. Plug in a mouse and keyboard
    6. Connect your Piu to the internet via an ethernet cable
    7. Turn on the HDMI monitor and the hub
    8. Plug in the Pi’s power cable (and send electricity to the Pi). Make sure you do this last.
  3. On the setup screen, set it to boot to the desktop and set the locale. then reboot
  4. Open a terminal and run:

    sudo apt-get update
    sudo apt-get install aptitude
    sudo aptitude safe-upgrade
    sudo apt-get autoremove
    sudo apt-get clean
    sudo aptitude install rfkill hostapd hostap-utils iw dnsmasq lighttpd

  5. Using your regular computer (not the Pi), Find the wifi channel with the least traffic and least overlap

    sudo iwlist wlan0 scan | grep Frequency | sort | uniq -c | sort -n

  6. Try to find out what dongle I have
    1. run: iw list
    2. That returns ‘nl80211 not found’
    3. run: lsusb
    4. That says I have a RTL8188CUS 802.11n adaptor
  7. Use this script for a rtl8188CUS dongle
    1. For future, it would be nice to get the location from the system locale
    2. Autoset the SSID to he name of the piece
    3. Autoset a default password
    4. Indeed, remove all interactivity from the script
  8. Reboot

It might not seem like much, but that was all day yesterday. The first step alone took bloody ages.

To Do

  • Install needed fonts, etc.
  • Try to ensure that the internet remains available over ethernet, but if this isn’t possible, You can still chekc out a github repo to a USB stick and move data that way…
  • Find out what wifi dongle would be best for this application – ideally it has a low power draw, decent range, cheap and commonly owned among people with Pis
  • Set it to hijack all web traffic and serve pages but not with apache! Use the highttpd installed earlier

Building SuperCollider 3.6 on Raspberry Pi

Raspberry Pi Wheezy ships with SuperCollider, but it ships with an old version that does not have support for Qt graphics. This post is only slightly modified from this (formerly) handy guide for building an unstable snapshot of 3.7 without graphic support. There are a few differences, however to add graphic support and maintain wii support.
This requires the Raspbian operating system, and should work if you get it via NOOBs. I could not get this to fit on a 4 gig SD card.
Note: This whole process takes many hours, but has long stretches where it’s chugging away and you can go work on something else.


  1. log in and type sudo raspi-config, select expand file system, set timezone, finish and reboot
  2. sudo apt-get update
  3. sudo apt-get upgrade # this might take a while
  4. sudo apt-get remove supercollider # remove old supercollider
  5. sudo apt-get autoremove
  6. sudo apt-get install cmake libasound2-dev libsamplerate0-dev libsndfile1-dev libavahi-client-dev libicu-dev libreadline-dev libfftw3-dev libxt-dev libcwiid1 libcwiid-dev subversion libqt4-dev libqtwebkit-dev libjack-jackd2-dev
  7. sudo ldconfig

Build SuperCollider

  1. wget http://downloads.sourceforge.net/project/supercollider/Source/3.6/SuperCollider-3.6.6-Source.tar.bz2
  2. tar -xvf SuperCollider-3.6.6-Source.tar.bz2
  3. rm SuperCollider-3.6.6-Source.tar.bz2
  4. cd SuperCollider-Source
  5. mkdir build && cd build
  6. sudo dd if=/dev/zero of=/swapfile bs=1MB count=512 # create a temporary swap file
  7. sudo mkswap /swapfile
  8. sudo swapon /swapfile
  9. CC=”gcc” CXX=”g++” cmake -L -DCMAKE_BUILD_TYPE=”Release” -DBUILD_TESTING=OFF -DSSE=OFF -DSSE2=OFF -DSUPERNOVA=OFF -DNOVA_SIMD=ON -DNATIVE=OFF -DSC_ED=OFF -DSC_EL=OFF -DCMAKE_C_FLAGS=”-march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp” -DCMAKE_CXX_FLAGS=”-march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp” ..
    # should add ‘-ffast-math -O3’ here but then gcc4.6.3 fails
  10. make # this takes hours
  11. sudo make install
  12. cd ../..
  13. sudo rm -r SuperCollider-Source
  14. sudo swapoff /swapfile
  15. sudo rm /swapfile
  16. sudo ldconfig
  17. echo "export SC_JACK_DEFAULT_INPUTS="system"" >> ~/.bashrc
  18. echo "export SC_JACK_DEFAULT_OUTPUTS="system"" >> ~/.bashrc
  19. sudo reboot

Test SuperCollider

  1. jackd -p32 -dalsa -dhw:0,0 -p1024 -n3 -s & # built-in sound. change to -dhw:1,0 for usb sound card (see more below)
  2. scsynth -u 57110 &
  3. scide
  4. s.boot;
  5. {SinOsc.ar(440)}.play
  6. Control-.

Optional: Low latency, RealTime, USB Soundcard etc

  1. sudo pico /etc/security/limits.conf
  2. and add the following lines somewhere before it says end of file.
  3. @audio – memlock 256000
  4. @audio – rtprio 99
  5. @audio – nice -19
  6. save and exit with ctrl+o, ctrl+x
  7. sudo halt
  8. power off the rpi and insert the sd card in your laptop.
  9. dwc_otg.speed=1 # add the following to beginning of /boot/cmdline.txt (see http://wiki.linuxaudio.org/wiki/raspberrypi under force usb1.1 mode)
  10. eject the sd card and put it back in the rpi, make sure usb soundcard is connected and power on again.
  11. log in with ssh and now you can start jack with a lower blocksize
  12. jackd -p32 -dalsa -dhw:1,0 -p256 -n3 -s & # uses an usb sound card and lower blocksize
  13. continue like in step5.2 above


This post is licensed under the GNU General Public License.