Following are my notes on getting a v1.0 RadioShark and a 808 Bluetooth speaker working on a Raspberry Pi 3, running 2017-11-19-raspbian-stretch-lite. Installation of the OS is considered outside of the scope of these notes. Following steps are performed as root, unless otherwise noted.
-
Find a copy of the older libhid. I'd searched Google and found a copy at: http://sources.openelec.tv/mirror/libhid/
-
Download the libhid code
wget http://sources.openelec.tv/mirror/libhid/libhid-0.2.16.tar.gz
- Untar the libhid tarball and cd into it
tar xvfz libhid0.2.16.tar.gz
cd libhid-0.2.16
- edit test/lshid.c and comment out line 41 so that it looks like:
//len = *((unsigned long*)custom);
- Immediately after the above line, add:
len=len;
custom=custom
Note: The above is needed because the compiler see that those two variables are declared but never used.
- Install the development package for libusb
apt-get install libusb-dev
- Run configure
./configure
The tail end of the output should look something like:
.-------------------------------------------------
| Configuration to be used:
|
| CPP : gcc -E
| CPPFLAGS: -DNDEBUG
| CC : gcc
| CFLAGS : -O2 -Wall -W -Werror
| CXX : g++
| CXXFLAGS: -O2 -Wall -W -Werror
| LD : /usr/bin/ld
| LDFLAGS : -L/usr/lib/arm-linux-gnueabihf -lusb
`--------------------------------------------------
Note: If the last line is only "LDFLAGS: " (with nothing following it), you've likely missed something.
- Build and install the binary via:
make
make install
- Cd back to home and get the shark code:
cd
wget http://www.productivity.org/projects/shark/download/shark-1.0.tar
- Untar the shark tarball and cd into it:
tar xvf shark-1.0.tar
cd shark-1.0
- Using your favorite editor, edit the Makefile and cause the line after the "shark:" tag to look like:
shark:
${CC} -L/usr/local/lib/ -lusb -lhid -o shark shark.c
- Build and install the shark binary by running:
make
make install
- Plug in your RadioShark and run the following:
/usr/local/bin/shark -red 1
/usr/local/bin/shark -red 0
The above should cause the red LEDs in the RadioShark to come on and go off.
Note: If the above complains about not being able to find libhid.so.0, run "ldconfig".
- Install various packages via:
apt-get install pulseaudio pulseaudio-module-bluetooth bluez bluez-firmware mplayer
- Add root to the pulse permissions
adduser root pulse-access
Note: if you're intending to include Node-Red controls for shark, be sure to figure out which user the binary runs as and also run "adduser" for that user.
- Create /etc/dbus-1/system.d/pulseaudio-bluetooth.conf so that it contains:
<busconfig>
<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>
</busconfig>
- Append the following to the end of /etc/pulse/system.pa
#
# Bluetooth support #
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
#
- Create /etc/systemd/system/pulseaudio.service so that it contains:
[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
[Install]
WantedBy=multi-user.target
- Run the following to cause PulseAudion to start at boot:
systemctl daemon-reload
systemctl enable pulseaudio.service
- Restart Bluetooth via:
systemctl restart bluetooth
Note: you can check to see if it's running via:
systemctl status bluetooth
Note: Ignore the complaints about the SAP driver and server.
-
Reboot your system and log back in as root
-
Pair up the speaker by running:
bluetoothctl
power on
agent on
default-agent
scan on
Note: Pause at this point, until the MAC address for "[808]" shows up, then run the following:
pair MAC_ADDRESS
trust MAC_ADDRESS
connect MAC_ADDRESS
scan off
exit
Output from the connect instruction should look like:
[bluetooth]# connect FC:58:FA:B8:C4:B4
Attempting to connect to FC:58:FA:B8:C4:B4
[CHG] Device FC:58:FA:B8:C4:B4 Connected: yes
Connection successful
[CHG] Device FC:58:FA:B8:C4:B4 UUIDs:
00001101-0000-1000-8000-00805f9b34fb
00001108-0000-1000-8000-00805f9b34fb
0000110b-0000-1000-8000-00805f9b34fb
0000110c-0000-1000-8000-00805f9b34fb
0000110e-0000-1000-8000-00805f9b34fb
0000111e-0000-1000-8000-00805f9b34fb
- Run the following
pactl list short|grep bluez
The output should look something like what's starting on line 201 at: https://github.com/davidedg/NAS-mod-config/blob/master/bt-sound/bt-sound-Bluez5_PulseAudio5.txt On mine, it looks like:
root@snipsbox:~# pactl list short|grep bluez
X11 connection rejected because of wrong authentication.
xcb_connection_has_error() returned true
12 module-bluez5-discover
13 module-bluez4-discover
14 module-bluez5-device path=/org/bluez/hci0/dev_FC_58_FA_B8_C4_B4
1 bluez_sink.FC_58_FA_B8_C4_B4 module-bluez5-device.c s16le 2ch 44100Hz SUSPENDED
2 bluez_sink.FC_58_FA_B8_C4_B4.monitor module-bluez5-device.c s16le 2ch 44100Hz SUSPENDED
2 bluez_card.FC_58_FA_B8_C4_B4 module-bluez5-device.c
- Test the config by running:
mplayer -ao pulse a.mp3
- Run the following:
pactl list |more
Make note of the index number for the source and sink that you want to use (for me it was source=0 and sink=1)
- set the proper source and sink
pactl load-module module-loopback source=0 sink=1
- Tune the RadioShark to a local station by running:
shark -fm 98.7
- adjust the volume (on the sink and source) to suit, by running:
pactl -- set-sink-volume 1 50%
pactl -- set-sink-volume 1 -5%
pactl -- set-source-volume 0 80%
Get the current volume by running:
pactl list sinks|perl -000ne 'if(/#1/){/(Volume:.*)/;print "$1\n"}'
- You may need to add the following to /etc/pulse/daemon.conf:
resample-method = trivial
- I've experience periodic failures (where nothing goes to the Bluetooth audio).
Also, the kernel log was full of "FIQ reported NYET" errors. The Interwebs recommended editing the tail end of /boot/config.txt and making it look like the below. It appears to work. Will provide updated status later.
# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
dwc_otg.fiq_fsm_mask=0xf
Note: other recommendations include setting the value to 0x5, 0x7, or 0xd. 0xf appears to work for me.
Note: you must reboot the RPi once you've made this change.
Update (16 Jan 2018): Making the above change (in the long run) had little effect. I was more successful with adjusting the sample rate in /etc/pulse/daemon.pa. I changed it from 44100 to 32000. The line should look like:
default-sample-rate=32000
The above appears to fix both the "FIQ reported NYET" errors and the periodic crashing of the audio. As of this update, the radio has been playing for a little over 2 days, with an average load of about 0.20. Node-Red and LMS are also running on the same RPi.
- The libhid repair: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=21932
- The older libhid code: http://sources.openelec.tv/mirror/libhid/
- The shark code: http://www.productivity.org/projects/shark/
- Richard MacCutchan's hint for fixing the shark.c Makefile: https://www.codeproject.com/Questions/529381/GetplusUSBplusdeviceplusinformationplususingplusli
- hints for setting up Bluetooth: https://github.com/davidedg/NAS-mod-config/blob/master/bt-sound/bt-sound-Bluez5_PulseAudio5.txt
- hints for determine which sink and source: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=88418
- Code for RadioShark v2: http://hoop.euqset.org/archives/2015_11.html