Skip to content

raspberry pi

casey langen edited this page Feb 21, 2017 · 19 revisions

intro

musikbox runs great on a raspberry pi when properly configured. it can be plugged directly into your home stereo system and controlled remotely, both via ssh and a companion android app called musikdroid.

it's highly recommend to invest in a third party sound card. the built-in one sounds terrible and has tendency to get sick and stop working properly. i personally recommend the iqaudio pi-dac+. it sounds great. the behringer uca222 is a cheaper, bulkier alternative. if you're on a super tight budget, a sabrent au-emcb will get the job done.

operating system setup

musikbox on a raspberry pi requires raspbian jessie.

if you already have a functioning system you can skip ahead to the installation section. these first few steps document how to get a freshly installed pi ready for musikbox.

reconfigure your keyboard

by default the raspberry pi comes configured with a GB keyboard layout. depending on where you live, this can cause problems. the first order of business is to reconfigure your keyboard.

  • sudo vi /etc/default/keyboard
  • set: XKBLAYOUT="us" (or other country code, as appropriate)
  • sudo reboot

setup wifi

let's get wifi up and running by connecting to the access point.

  • sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

    adjust your country as necessary, then add access point info to the bottom of the file. the entire file should look something like this:

    country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
      ssid="ACCESS_POINT_NAME"
      psk="WIFI_PASSWORD"
    }
    
  • sudo reboot (or you can try playing with ifconfig to bring the interface down, then up; i ended up rebooting)

update your system

this will update all software on the system to the latest available versions.

  • sudo apt-get update
  • sudo apt-get dist-upgrade
  • sudo reboot (maybe not necessary)

automatically mount USB drives

you can configure the operating system automatically mount USB disk drives to a known location so musikbox can scan them during startup for new music. this is as easy as installing the usbmount package and configuring musikbox to index the /media/ directory on the filesystem.

  • sudo apt-get install usbmount

important note: usbmount is unable to mount userspace filesystems like exfat. if you want to use usbmount, ensure your drive is formatted as vfat (fat32), ext2/3/4, or other type of another natively supported filesystem.

using musikbox

install musikbox binaries

  • download the musikbox_x.x.x_raspberry_pi_armhf.deb file from the releases page.
  • sudo dpkg -i ./musikbox_x.x.x_raspberry_pi_armhf.deb (this will likely fail due to missing packages...)
  • sudo apt-get install -f (this will install the missing packages, and finish the installation)
  • musikbox (start it up to make sure it works)

configure music paths

with musikbox running you can configure paths on your system you want to be automatically scanned for music. if you installed usbmount above, you should have musikbox index /media/usb0 through /media/usb7.

  • important: do not add /media/usb! usbmount appears to set this up as a symlink to /media/usb0; doing so will result in duplicate music in your library.

run musikbox on startup

it's useful to have musikbox start whenever the pi boots so it's always running.

  • sudo apt-get install screen
  • sudo vim /etc/rc.local
  • add the following line: su - pi -c "screen -dmS musikbox musikbox"

note that the above will start musikbox in a screen session as the pi user. that means you can always shell in and do a screen -r musikbox to reattach to it to control playback from a computer.

enable 256 color mode for screen

musikcube supports color palettes > 8 colors. if you want more than 8 colors when running musikcube in screen during startup, do the following:

  • vim ~/.screenrc
  • add this line: term screen-256color

note you'll need to reboot/restart musikbox for this to take effect.

troubleshooting / optional configuration

you probably shouldn't do any of this unless you are having problems!

crossfade and volume-related issues

musikbox uses the PulseAudio output device by default. some sound cards don't seem to play nice with PulseAudio, especially with crossfading enabled. if you are having problems with crossfading or volume, try changing to the lower-level AlsaOut driver.

you can do this in musikbox by pressing ESC, followed by s to enter settings, then pressing TAB until you get to output device. press enter and select AlsaOut.

integrated sound card setup

the built-in card is pretty bad -- it produces a lot of noise and sounds very thin and tinny. if possible, try to invest a few dollars and get a third party DAC. however, if you must use the built-in card and things aren't working, you probably need to switch to the analog output:

  • sudo raspi-config
  • advanced options
  • audio
  • force 3.5mm ('headphone') jack

disabling the integrated card

so you already have a third party sound card? good for you! the easiest way to get musikbox to play through that device is to simply disable the integrated one.

  • sudo vim /boot/config.txt
  • change dtparam=audio=on to #dtparam=audio=on
  • sudo reboot

disable wifi power saving

i had an older raspberry pi that seemed to put the wifi card into powersave mode very frequently, making connecting to the device annoying. if you have this problem you can try to disable power saving mode by adding wireless-poweroff to each wifi adapter's configuration.

  • sudo vi /etc/network/interfaces
    ...
    allow-hotplug wlan0
    iface wlan0 inet manual
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
      wireless-power off
    
    allow-hotplug wlan1
    iface wlan1 inet manual
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
      wireless-power off
    ...
    

make wifi reconnection more aggressive

my old wifi router was pretty unstable, and the Pi wasn't good about reconnecting automatically. you can setup a cron job to test the connection and automatically reconnect every couple minutes.

first, create a script to test the connection and bring the interface down, then back up if there are problems:

  • sudo touch /usr/local/bin/wifi_rebooter.sh
  • sudo chmod +x /usr/local/bin/wifirebooter.sh
  • sudo vi /usr/local/bin/wifi_rebooter.sh
    #!/bin/bash
    # http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/
    
    # The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
    SERVER=8.8.8.8
    
    # Only send two pings, sending output to /dev/null
    ping -c2 ${SERVER} > /dev/null
    
    # If the return code from ping ($?) is not 0 (meaning there was an error)
    if [ $? != 0 ]
    then
        # Restart the wireless interface
        ifdown --force wlan0
        ifup wlan0
    fi
    

second, add a cron job to run every minute (or whatever) that invokes the script from above:

  • sudo vi /etc/crontab
    */1 * * * *     root    /usr/local/bin/wifi_rebooter.sh
    

(note: replace "1" above with the desired interval, in minutes.)

Clone this wiki locally