Instructions for getting your Raspberry Pi working with the sensor code.

The software setup for the Raspberry Pi is moderately complex. It requires some decent knowledge of Linux environments. The code to operate the sensors on the Raspberry Pi is available publically on GitHub and is released under the GNU GPL license. The Git repository containing this code can be found here: This guide was written by Avriel Harvey.

The software referenced on this page is consolidated into the list below for your convenience.

External software

Guide overview

This guide will walk you through the setup of a Raspberry Pi model B+ and the installation of the code that will operate the sensors. There is a list of requirements, a guide for the initial setup of the Raspberry Pi, and finally, steps to download, compile, and run the sensor code on the Raspberry Pi.


Setting up the Raspberry Pi

Raspberry Pi Quick Start and OS installation

The Raspberry Pi Foundation has compiled a great quick-start guide: You should follow this guide understand the initial operating system set up. The NOOBS operating system setup is the easiest to use. The guide for NOOBS can be found here: The operating system you need to install using NOOBS is Raspbian. After installation of the operating system onto the microSD card, continue to the next portion of this guide.

Getting remote access with SSH

After Raspbian is installed, power on your Raspberry Pi with the ethernet cable connected to your router. At the login prompt, sign in as pi with the password raspberry. To install the SSH server, execute the following commands at the shell prompt:

sudo apt-get update
sudo apt-get install openssh-server

If the installation completes successfully, you should now have a SSH server running on your Raspberry Pi. Next, get the IP address of the Pi using the following command:


Now that you have the IP address, you can SSH into your Raspberry Pi from any other computer on the same network. Linux and Macs come with SSH clients by default. Windows computers can use PuTTY or some similar tool as an SSH client.

Installing Git

The source code for our team is stored in a public Git repository. In order to be able to download this to your Pi, you need to install Git using the following command:

sudo apt-get install git

Real-time kernel

In order to get the most accurate results from the sensors, it is strongly recommended that you run a real-time kernel on the Raspberry Pi. Real-time kernels can significantly reduce latency for user code in the operating system. This is particularly important for this challenge due to the real-time constraints of the system. There are two options that you have:

  1. Download a precompiled real-time kernel from a third-party and install it
  2. Compile and install a real-time kernel yourself

Option 1 probably takes significantly less time than option 2, but we did not choose this option. Option 2 requires compiling the operating system kernel from scratch. This guide only covers option 2. This can be achieved by using the Raspberry Pi’s 3.12.28 kernel source and applying the rt patch available from The version of the kernel we had success with is 3.12.28-rt40+.

The kernel compilation will take place on the Raspberry Pi.

  1. Install dependencies
    sudo apt-get install bc build-essential libqt4-dev pkg-config
  2. Get the 3.12.28 kernel source from Git
    git clone
    cd linux
    git checkout rpi-3.12.28
  3. Get the toolchain from Git
    git clone
  4. Download the rt kernel patch
  5. Patch the source
    xzcat patches-3.12.26-rt40.tar.xz | patch -p1
  6. Copy the configuration in
    cp /proc/config.gz ./
    zcat config.gz > .config
  7. Setup your environment variables
    export ARCH=arm
    export CROSS_COMPILE=/home/$USER/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
    export INSTALL_MOD_PATH=/home/$USER/raspi-image
  8. Configure the kernel
    make oldconfig | yes
    make xconfig
  9. A window should appear with options to set in the kernel. Search for the PREEMPT_RT option and enable it. Save the configuration and close the window.
  10. Compile the kernel. This step will take a very long time (hours).
    make bzImage
    make modules
    sudo make modules_install
  11. Copy linux/arch/arm/boot/zImage to /boot/zImage-3.12.28-rt40.
  12. Copy raspi-image/lib/modules/3.12.28-rt40+ to /lib/modules preserving symlinks (cp -rp).
  13. Edit /boot/config.txt. Comment out any line starting with 'kernel' and append the following:
  14. Edit /boot/cmdline.txt and append the following:
  15. The kernel install is complete! Restart your Pi and run the following command to verify you are running the 3.12.28-rt40+ kernel:
    uname -r

Congratulations! Your Pi is now ready for the sensor code.

Running the sensor code

The sensor package code is stored in a public Git repository.

  1. The first step is dependency installation. You will be installing the pigpio library.
    cd PIGPIO
    sudo make install
  2. Now you are ready to download the code that will operate the sensors. First, clone the repository
    git clone
  3. You now have a folder containing the sensor code. Go to the directory containing the Makefile
    cd turbo-sense/hcsr04/raspberry-pi
  4. Compile the code
  5. (Optionally) modify the sensor.cfg file to match your desired parameters
  6. You now need to set up the input pipe
    cd pipe_sample
  7. Compile the input pipe code
  8. Open another terminal session in this same directory and execute the following command to open the input pipe
    sudo ./pipe_in
  9. You are now ready to run the sensor code. If you completed steps 5-7, go back to your original terminal session.
    sudo ./multisense_rt
  10. Press <ENTER> at the prompt and the sensors will start outputting distances!