OS Geek

RaspISK

What is this RaspISK?

After my second car stereo got stolen I decided not to use a commercial shiny and expensive equipment anymore, so lets have a hidden, cheap and fun solution for this daily pleasure that is listen to music or even news while driving.

 

Raspi_Colour_R So I already knew about Raspberry Pi board (rpi), I decided to make a try.(just a small “interlude”: I took advantage that I was traveling to São Paulo, and went straight to a region of cheap electronics in the city, and even then it cost me about $130, that has a $35 cost abroad, just for you see how are things here in Brazil )

 

I already had a amplifier from the first time that my stereo got stolen, spend 6 months using with a cable on the iphone, so I just took out of the box again and installed back. But why use a Raspberry if had working in the past without? The answer is CABLES, nobody likes them, so after trying to put a Airport Express inside the car, and failed, I met a project called shairport, that allows you to use Airplay (audio thru wi-fi from apple) in linux.

 

Someone can ask why not use bluetooth? My answer is: did you already compared listen to music with cables and then bluetooth? The quality is awful, all the lower frequencies are left out, and to anyone that likes music this is a great loss.

raspberry-pi-nano-wifi-dongle-3-800x800

 

So the Raspberry do all the job, has a analog audio output ( not that good, but I will talk about later ) just missing the wireless board, what you can solve with a small wi-fi dongle.

 

The software part is not that difficult to implement, basicaly you have to install the OS, make your rpi become a wireless hotspot, and then install the shairport that will broadcast to any iDevice connected to this network that is available to stream audio. The howto is down the hill. ( Lá vem o Marcos…)

 

You don´t need to cry if you don´t have/like an Apple device, there is some apps for android that allow you to stream to the Airplay service.

 

uca222

5HV2After get it to work I did two more hardware upgrades, first was to use an external usb sound card, as rpi use PWM to convert the digital stream into analog it comes with another cost to frequency response. I´m using a Behringer UCA222 (left) usb sound card, excellent quality, cheap (again, abroad) and work out of the box. Even have a volume control with you are using the headphones output. If you want to spend less use any usb sound card available, for example 5HV2  (right). Possible you will have to solve some poping problem on the audio, but this is easily solved on forums online.

 

The second upgrade was a small no-break circuit on the power supply. As I was using the car ignition signal to power the rpi I had two problems: stop the music when turn off the car, and having to wait the boot time to start listening the music when turn on, that could be up to 60 seconds after ignition. So I added a small circuit with a relay, a transistor buffer and a capacitor, with two inputs, one connected to the car ignition ( solving the turn off problem, keeping the sound on a few minutes after stop the car ) and the second input to the electric lock from the doors. no-break-rpi_schem You may wonder why this second option… when the car alarm is turn off, the electric locks opens. This signal will charge the no-break circuit and when I come in to the car the rpi is already on and waiting for the music to start. It is only a pulse that opens the locks, but I just have to start the car prior to the no-break wear off, and using 3 minutes as I´m doing looks enough. Just pay attention that there is two wires to the electric locks, one to open and another to close. I realized that at first by choosing the wrong one, not a big deal, just that my sound didn´t start early as I wanted and kept on long after I was gone. cell

 

But remember, you still have to use a DC-DC converter, with or without the no-break circuit, as the rpi runs on 5V, and your car battery provide 12V. You can use a cheap cellphone car charger, and it´s easy to take apart and event put together with the no-break in the same box.

 

I´m using this solution for 4 months already, works like a charme. Just keep a image of your SD card at home, because you will turn off hard your Raspberry Pi every time, and some day this will break your OS, or maybe not.

 

Hey, almost forgot, WTH is the ISK stands for? Nothing important, just the letters part from my car’s licence plate.

 

How-To ( software part )

OBS: I'm having trouble posting / etc / on WordPress, so every time you see and etc, just add a / before ;)

 

Raspbian

First we are goint to install the OS, in this case the Raspbian, that you can find on the Raspberry Pi website. This instructions are using OS X, but you can find the ways thru others systems.

1-Download & run SDFormatter in your SD Card

2-Download RaspBian

3-Install on SD Run dd to copy the image to the SD. You have to use the terminal, and find out which disk is your SD Card on /dev.

$ sudo dd if=2014-01-07-wheezy-raspbian.img of=/dev/disk1 bs=4m

After copy the image to the card insert into the board and turn it on to make the instalation, it’s pretty straightforward. You can use a keyboard and a monitor/tv or just ssh from a computer. But for the next step you will have to put your raspberry pi on the internet thru ethernet cable.

 

Wi-Fi Hotspot

When you have your raspbian up and runing you can start to install the services that you will need. First lets turn your rpi in a wireless router. Airplay needs a network to run, and your iDevice needs to connect to your rpi, so you need to install two services: adp and dhcp. For now on you must have your wi-fi dongle plugged.

$ sudo apt-get update
$ sudo apt-get install hostapd udhcpd

First lets configure the dhcp (you can use vi,vim,ed… I like nano). Remember to put a / before etc, or you can use a cd / once for most commands.

$ cd /
$ sudo nano etc/udhcpd.conf

You can use any network range, I like the 10.1.1.x because is easier to type

start 10.1.1.5
end 10.1.1.20
interface wlan0
remaining yes
opt dns 8.8.8.8 4.2.2.2
opt subnet 255.0.0.0
opt router 10.1.1.1

But even that I create a DHCP config file, I choose not to use

$ sudo nano etc/default/udhcpd

comment

DHCPD_ENABLED=“no”

And now set the wlan0 ip address and fix for every boot

$ sudo ifconfig wlan0 10.1.1.1
$ sudo nano etc/network/interfaces

comment:

iface wlan0 inet dhcp
allow-hotplug wlan0
wpa-roam / etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual

add:

iface wlan0 inet static
address 10.1.1.1
netmask 255.0.0.0

After configuring the wifi interface lets make it a hotspot.

$ sudo nano etc/hostapd/hostapd.conf

Add

interface=wlan0
ssid=ISK
hw_mode=g
channel=2
auth_algs=1
wmm_enabled=0
ignore_broadcast_ssid=1

On ssid you will choose the name of the network. For channel you can change it if you are getting too much interference on your daily path. First I was using the ignore_broadcast_ssid=0, so my network would not appear, but after upgrading my iPhone to iOS 7 I had to start broadcasting again, or the phone would not connect :(

Put the path of daemon to work:

$ sudo nano etc/default/hostapd

from

#DAEMON_CONF=“”

to

DAEMON_CONF="/ etc/hostapd/hostapd.conf"

And now comes the network routing part

$ sudo sh -c "echo 1> /proc/sys/net/ipv4/ip_forward"
$ sudo nano etc/sysctl.conf

add at the end

net.ipv4.ip_forward=1

And the famous iptables

$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

$ sudo sh -c "iptables-save > / etc/iptables.ipv4.nat"
$ sudo nano etc/network/interfaces

add at the end

up iptables-restore < / etc/iptables.ipv4.nat

Start and add to boot the just installed and configured services, and than reboot

$ sudo service hostapd start
$ sudo service udhcpd start

$ sudo update-rc.d hostapd enable
$ sudo update-rc.d udhcpd enable

$ sudo reboot

SHAIRPORT

Wheezy comes with installed audio drives, but you have to change the audio output to ‘Audiojack’ instead of HDMI

$ amixer cset numid=3 1

Install essential packages and dependencies

$ sudo apt-get install git

$ sudo apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config

$ sudo aptitude install libmodule-build-perl

$ sudo git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp
$ cd perl-net-sdp
$ sudo perl Build.PL
$ sudo ./Build
$ sudo ./Build test
$ sudo ./Build install

Download and install shairport

$ sudo git clone https://github.com/hendrikw82/shairport.git shairport
$ cd shairport
$ sudo make install
$ sudo cp shairport.init.sample etc/init.d/shairport
$ sudo insserv shairport
$ sudo service avahi-daemon start
$ sudo etc/init.d/shairport start

Add it to the boot

$ sudo nano etc/init.d/cron -e

add after

test -f $DAEMON || exit 0
. /lib/lsb/init-functions

this

service avahi-daemon stop

rm /var/run/avahi-daemon/disabled-for-unicast-local
service avahi-daemon start
/ etc/init.d/shairport start 

To change the Airplay ID

$ sudo nano /usr/local/bin/shairport.pl

comment:

#my $apname = "ShairPort $$ on " . `hostname`;

And type your own

my $apname = "WISK";

Than just reboot

$ sudo reboot

At this point you should be ready to go, just start your Raspberry Pi, plug into your stereo, pickup your iDevice, connect to your personal Wi-Fi and start streaming your music.

If you have any problems, just let me know. But if you want to share your success, let me know also.

 

References - You can find it as links during the post, but here are also:

https://www.sdcard.org/

http://www.raspberrypi.org/

http://elinux.org/RPI-Wireless-Hotspot

http://pi-raspberry.blogspot.de/2012/08/shairport-raspberry-pi.html

https://github.com/hendrikw82/shairport

Powered by: Wordpress