19 raspberry pi
casey langen edited this page 2017-07-19 17:48:34 -07:00

intro

musikcube 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.

you can download both the raspberry pi build of musikcube, and the musikdroid android app from the releases page.

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

musikcube on a raspberry pi requires raspbian jessie. it also runs well on the upcoming stretch release.

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 musikcube.

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 vim /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 vim /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 musikcube can scan them during startup for new music. this is as easy as installing the usbmount package and configuring musikcube 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 musikcube

install musikcube binaries

  • download the musikcube_x.x.x_raspberry_pi_armhf.deb file from the releases page.
  • sudo dpkg -i ./musikcube_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)
  • musikcube (start it up to make sure it works)

configure music paths

with musikcube running you can configure paths on your system you want to be automatically scanned for music. if you installed usbmount above, you should have musikcube 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 musikcube on startup

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

  • sudo apt-get install tmux
  • sudo vim /etc/rc.local
  • add the following line: su - pi -c "tmux new -s musikcube -d musikcube"

note that the above will start musikcube in a detached tmux session as the pi user. that means you can always shell in and do a tmux attach -t musikcube to reattach to it to control playback from a computer.

enable 256 color mode for tmux and minimize input delay.

musikcube supports color palettes > 8 colors, and makes use of the ESC key for navigation. it's suggested to modify your ~/.tmux.conf as follows:

  • vim ~/.tmux.conf
  • add these lines:
    • set -g default-terminal "screen-256color"
    • set -s escape-time 0

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

troubleshooting / optional configuration

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

musikcube 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 the following:

  1. close musikcube
  2. vim ~/.musikcube/plugin_pulseaudioioutput.json
  3. change force_linear_volume to true
  4. restart musikcube

if this does not solve your issue, try changing your output device to the lower-level AlsaOut driver. you can do this in musikcube by pressing ESC, followed by s to enter settings, then pressing TAB until you get to output device. press enter and select AlsaOut.

also, on a fresh install of raspbian stretch (not jessie) i had issues with pulse audio not working properly out of the box. i did an apt-get install alsamixer and noticed the volume and balance for the audio device was wonky. after adjusting it things were fine from there on out.

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 musikcube 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-power off to each wifi adapter's configuration.

  • sudo vim /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 vim /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 vim /etc/crontab
    */1 * * * *     root    /usr/local/bin/wifi_rebooter.sh
    

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