Turn your Raspberry Pi into a Portable Bluetooth Speaker

Leave a comment

July 14, 2014 by aubreykloppers

http://www.instructables.com/id/Turn-your-Raspberry-Pi-into-a-Portable-Bluetooth-A/?ALLSTEPS

http://rpiexperimenter.blogspot.com/2013/06/setting-up-bluetooth-audio-server-on.html

Another interesting one is PiFidelity:

 Adding VU Meters/LED:

http://freshfoo.com/blog/raspberry_pi_vu_meter

https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/ and

http://www.thirdeyevis.com/pi-page-2.php

 Build on XBMC:

http://www.raspbian.org/RaspbianXBMC

XBMC users are asking for it:

http://forum.xbmc.org/showthread.php?tid=194367&pid=1753255#pid1753255

My Testing:

First I changed my /etc/network/interfaces to the following format:

iface eth0 inet static
address 192.168.1.81
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
Then I ran the following commands:
apt-get update
apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools
apt-get install rpi-update
BRANCH=next rpi-update
usermod –a –G lp pi
———————————————————————————————
vi /etc/bluetooth/audio.conf
Add the follow text under
[General]:
Enable=Source,Sink,Media,Socket
———————————————————————————————
vi /etc/pulse/daemon.conf
; resample-method = speex-float-3
resample-method = trivial
———————————————————————————————
vi /etc/bluetooth/main.conf
Name = PiBlueTooth
Class = 0x20041C
———————————————————————————————
vi /var/lib/bluetooth/<bluetooth mac address>/config
name PiBlueTooth
class 0x20041C
———————————————————————————————
vi /etc/udev/rules.d/99-input.rules
Add under:
KERNEL==”input[0-9]*”, RUN+=”/usr/lib/udev/bluetooth”
———————————————————————————————
mkdir /usr/lib/udev
———————————————————————————————
vi /usr/lib/udev/bluetooth
#!/bin/bash
#change if you don’t use default analog audio out.
#THIS DIDN’T WORK FOR MY PI SO I ADDED A amixer COMMAND BELOW
AUDIOSINK=”alsa_output.platform-bcm2835_AUD0.0.analog-stereo”
echo “Executing bluetooth script…|$ACTION|” >> /var/log/bluetooth_devACTION=$(expr “$ACTION” : “\([a-zA-Z]\+\).*”)
if [ “$ACTION” = “add” ]
then# Turn off BT discover mode before connecting existing BT device to audio
hciconfig hci0 noscan# set the audio output to the analog
# COMMENT THIS LINE OUT IF YOU WANT TO OUTPUT AUDIO THROUGH HDMI
amixer cset numid=3 1# Set volume level to 100 percent
amixer set Master 100%
pacmd set-sink-volume 0 65537for dev in $(find /sys/devices/virtual/input/ -name input*)
do
if [ -f “$dev/name” ]
then
mac=$(cat “$dev/name” | sed ‘s/:/_/g’)
bluez_dev=bluez_source.$macsleep 1

CONFIRM=`sudo -u pi pactl list short | grep $bluez_dev`
if [ ! -z “$CONFIRM” ]
then
echo “Setting bluez_source to: $bluez_dev” >> /var/log/bluetooth_dev
echo pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
sudo -u pi pactl load-module module-loopback source=$bluez_dev sink=$AUDIOSINK rate=44100 adjust_time=0 >> /var/log/bluetooth_dev
fi
fi
done
fi

if [ “$ACTION” = “remove” ]
then
# Turn on bluetooth discovery if device disconnects
sudo hciconfig hci0 piscan
fi

———————————————————————————————
chmod 774 /usr/lib/udev/bluetooth
———————————————————————————————
vi /etc/init.d/bluetooth-agent
### BEGIN INIT INFO
# Provides: bluetooth-agent
# Required-Start: $remote_fs $syslog bluetooth pulseaudio
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Makes Bluetooth discoverable and connectable to 0000
# Description: Start Bluetooth-Agent at boot time.
### END INIT INFO
#! /bin/sh
# /etc/init.d/bluetooth-agent
USER=root
HOME=/root
export USER HOME
case “$1” in
start)
echo “setting bluetooth discoverable”
sudo hciconfig hci0 piscan
start-stop-daemon -S -x /usr/bin/bluetooth-agent -c pi -b — 0000
echo “bluetooth-agent startet pw: 0000”
;;
stop)
echo “Stopping bluetooth-agent”
start-stop-daemon -K -x /usr/bin/bluetooth-agent
;;
*)
echo “Usage: /etc/init.d/bluetooth-agent {start|stop}”
exit 1
;;
esac
exit 0
———————————————————————————————
chmod 755 /etc/init.d/bluetooth-agent
update-rc.d bluetooth-agent defaults
———————————————————————————————
vi /etc/inittab
#1:2345:respawn:/sbin/getty 115200 tty1
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
———————————————————————————————
reboot
———————————————————————————————
LCD:
apt-get install lcdproc
modified LCDd.conf (in /etc)
Driver=hd44780
## Hitachi HD44780 driver ##
[hd44780]
ConnectionType=lcd2usb
Contrast=1000
Brightness=300
Keypad=no
Backlight=no
Size=16×2
—————————————————————————————-
lcd clock script:
#!/usr/bin/perl -w
# vim: set sw=4 ts=4 et: 
# lcddate.pl - display time and day on an external LCD display
# Copyright GPL  2005, Guido Socher
use IO::Socket;
use Fcntl;
use strict;
#
my $remote = IO::Socket::INET->new(
    Proto     => "tcp",
    PeerAddr  => "localhost",
    PeerPort  => 13666)|| die "Cannot connect to LCDd\n";
$remote->autoflush(1);
sleep 1; # give the server time to notice us...
print $remote "hello\n";
# we must read the response even if we ignore it:
my $lcdresponse = <$remote>;
# Turn off blocking mode...
fcntl($remote, F_SETFL, O_NONBLOCK);
# Set up some screen widgets...
print $remote "client_set name lcdtime\n";
print $remote "screen_add scr1\n";
print $remote "widget_add scr1 str1 string\n";
#
my $date;
my @ltime;
while(1)
{
    $lcdresponse = <$remote>;
    #$date = scalar localtime; # this is 24 char long. The following is bettter:
    @ltime = localtime;
    #return a date in yyyy-mm-dd hh:mm format
    $date = sprintf("%04d-%02d-%02d %02d:%02d",
          1900+$ltime[5],$ltime[4]+1,$ltime[3],$ltime[2],$ltime[1],$ltime[0]);
    print $remote "widget_set scr1 str1 1 1 \"$date\"\n";
    sleep 10;
}

—————————————————–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: