Category Archives: Raspberry Pi

PHP 5.5 on Raspbian Raspberry Pi

php 5.5.8

Raspberry pi runs Debian Wheezy, but with just one quick line change we can upgrade to Debian Jessie which is a newer version and provides PHP 5.5 binaries (5.5.8 at the time of this blog post.)

Start out by editing the APT sources:

vim /etc/apt/sources.list

Change wheezy to jessie, so that it looks like this:

deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi

(Don’t add or remove any lines, just change the one above)

Now run:

apt-get update && apt-get upgrade && apt-get autoremove

If you havent aready installed PHP, you can do it now via:

apt-get install php5 php5-cli

Finally, confirm your PHP version:

php -v

This should result in:

PHP 5.5.8-2 (cli) (built: Jan 18 2014 07:39:52)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

Increase volume over analogue output in Raspbmc

If you are using Raspbmc with analogue audio out you may notice the volume is too low on certain video files.

This can be fixed for most videos* by setting the speaker configuration to “2.0”, activating “Boost volume level on downmix”, (in XBMC audio settings) and then editing the gain value for this setting using the XBMC advancedsetting.xml file. (This is not possible to do via the GUI)

To get started, run:

cd /home/pi/.xbmc/userdata/
touch advancedsetting.xml
nano advancedsetting.xml

Paste the following into the editor:

<advancedsettings>
  <audio>
    <ac3downmixgain>18.0</ac3downmixgain>
  </audio>
</advancedsettings>

Save the file and reboot. The volume should now be increased on video files with 5.1 audio tracks. Note that high values for ac3downmixgain will cause distortion. Try a loud scene to see if you get any.

Note
The default value for ac3downmixgain is 12.0. I found 18.0 works for my needs.
*Videos with a stereo track will not have their volume increased.

Source

Raspberry Pi Shairport build instructions

2013-08-31
This post has been updated with new build instructions.

Below you will find instructions on how to build the Preconfigured Airplay speaker (Shairport) image. You may also find a thread about this build in the Raspberry Pi Forums.

The image assumes you’re starting out with the the standard Raspbian install. If you are starting out with Raspbmc as a base, read this additional information when you get stuck.

Note
This tutorial will be run as root. Log in using the pi user and then do:

Standard configuration

apt-get update && apt-get upgrade
raspi-config

Important
Make sure to run expand_rootfs and reboot, otherwise you will run out of free space!

Prequisites

apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git chkconfig libssl-dev libavahi-client-dev libasound2-dev pcregrep pgrep

In case you are having issues with the prequisites, there is som help here:
https://github.com/abrasive/shairport/blob/1.0-dev/README.md

Make sure to update the firmware, this will avoid popping noise when starting the speaker

git clone git://github.com/Hexxeh/rpi-update.git
rpi-update/rpi-update

We need to change the ALSA config slightly, otherwise Shairport will output an error – “Unknown PCM cards.pcm.front”

nano /usr/share/alsa/alsa.conf

Change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”
Source

We need to fix issues with avahi-daemon, which will return the error “avahi-daemon disabled because there is a .local domain” on many networks:

The solution is to modify the avahi-daemon init.d script.

nano /etc/init.d/avahi-daemon

Find the line starting witH DISABLE_TAG and change the filename to an invalid file, like this:

DISABLE_TAG="/var/run/avahi-daemon/disabled-for-unicast-local-DISABLED"

(Note DISABLED at the end)

Restart avahi-daemon and make sure it is run on boot

service avahi-daemon restart
chkconfig avahi-daemon on

Source (original issue)

Now we’re going to test the audio:

wget https://snippets.khromov.se/wp-content/uploads/2013/04/piano2.wav
aplay piano2.wav

You should hear audio through your speakers. Audio file credit

Installing Shairport

git clone -b 1.0-dev git://github.com/abrasive/shairport.git
cd shairport
./configure
make
make install

Start it to see if everything is working:

./shairport -a 'Shairport 1'

Volume levels are a bit low, raise the volume with the following command:

alsamixer

Keep it at about 85. (0 or negative gain). Going close to 100 will distort the audio output.

Autostarting Shairport on boot

We can use the included boot script, but we need to fix some issues with the script related to ALSA permissions and install paths.

Use this script, which changes the running user (for ALSA permissions) and removes some faulty install detection:

Download the modified startup script here. (GitHub gist)

Paste the contents of the script above in a new file:

touch /etc/init.d/shairport

Toggle the script on and off again. (We will see why below)

chkconfig shairport on
chkconfig shairport off

Watchdog

Starting shairport on boot turns out to be very tricky – sometimes shairport starts before avahi-daemon, which makes shairport fail.

To fix this we make a tiny watchdog script that makes sure shairport is always running.

Create a new text file named shairport-watchdog.sh in /root:

touch /root/shairport-watchdog.sh

Paste the following:

# find service pids
pgrep shairport

#if we get no pids, service is not running

if [ $? -ne 0 ]
then
 service shairport start
 echo "shairport started or restarted."
fi

Edit the file /etc/crontab and add the following line:

* * * * * root /bin/sh /root/shairport-watchdog.sh > /dev/null

The script will now check if shaiport is running every minute, and if not start it. This has the added benefit of restarting shairport if it crashes.

If you know of a cleaner way to declare avahi-daemon dependency in the init.d script for shairport, drop me a comment! There is an ongoing thread on Github about that here. Shairport Issues have been removed from GitHub

Some final cleanup:

chown -R pi:pi /home/pi/

And we’re done!

USB Sound Cards

Check out this tutorial, which has instructions for using Shairport with USB sound cards.

Setting up Wifi

Although it’s not provided in the image, it is possible to set it up with conventional means. Link

Preconfigured Airplay speaker (Shairport) – Downloadable Raspberry Pi image

Update 2013-08-31
New image available for download with updates of Shairport, raspi kernel and better startup/watchdog scripts.

This is a preconfigured Raspberry Pi Debian build with Shairport. – Thread on Raspberry Pi forums

Write the image to a SD card (4GB or larger), plug in speakers and network, and an AirPlay-capable player will show up on your network once you boot the Pi up.

Build instructions
Detailed build instructions can be found here

Latest version:
2013-08-31

Download:
Mirror 1

Release notes
2013-08-31 – Updated of Shairport, raspi kernel and better startup/watchdog scripts.
2013-04-21 – First release

Login

Username: pi
Password: raspberry

Misc
Tested with Airfoil (PC/Mac) and Honey Player (Android).
Additional testing welcome. (In particular actual iOS devices!)
More stable builds will be available shortly.

Old versions download:
2013-08-31 (Current version)
2013-04-21