<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gomgom</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gomgom"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Gomgom"/>
	<updated>2026-05-01T15:15:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_Bluetooth_Speaker&amp;diff=22965</id>
		<title>Raspberry Pi Bluetooth Speaker</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_Bluetooth_Speaker&amp;diff=22965"/>
		<updated>2023-02-04T13:27:53Z</updated>

		<summary type="html">&lt;p&gt;Gomgom: Add hint to packages bluez-alsa-utils bluez-alsa-openrc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=How To Build a Raspberry Pi Bluetooth Speaker=&lt;br /&gt;
&lt;br /&gt;
This articles describes how to build a Bluetooth speaker. This article is being actively written. Currently it is full of bugs but will provide some useful pointers.&lt;br /&gt;
&lt;br /&gt;
=Before You Start=&lt;br /&gt;
You’ll need:&lt;br /&gt;
* A Raspberry Pi&lt;br /&gt;
* A Bluetooth USB dongle (if your Pi doesn’t have Bluetooth on board)&lt;br /&gt;
* Sound card and speaker(s)&lt;br /&gt;
&lt;br /&gt;
=Article Completion=&lt;br /&gt;
# Test everything&lt;br /&gt;
# Turn every background task into a service&lt;br /&gt;
# More investigation on Bluetooth pairing&lt;br /&gt;
&lt;br /&gt;
=Getting the Speaker(s) Working=&lt;br /&gt;
To get the best results, you&#039;ll need an dedicated audio add-on board and matching speakers. Higher end passive speakers need a proper amplifier (e.g. HiFiBerry Amp2 or IQaudIO IQaudIO DigiAMP+).&lt;br /&gt;
&lt;br /&gt;
I&#039;ve used the whole range of IQaudio audio boards with different speakers and headphones. I&#039;d also recommend a dedicated USB Bluetooth dongle (don&#039;t get the cheapest versions of these). It is possible to test by using the on-board Bluetooth and the on-board audio with headphones but because of dropped packets, the audio quality isn&#039;t great.&lt;br /&gt;
&lt;br /&gt;
Once the speakers and audio card are connected to the Raspberry Pi, it&#039;s time to install a fresh version of Alpine Linux.  The armv7 version from the [https://alpinelinux.org/downloads/ Downloads] page works on almost all Pis. This Wiki has several articles about installing Alpine on a Raspberry Pi.&lt;br /&gt;
&lt;br /&gt;
Enable writing to the boot media:&lt;br /&gt;
&lt;br /&gt;
  mount /media/mmcblk0p1 -o rw,remount&lt;br /&gt;
&lt;br /&gt;
Then, either enable the on board sound:&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;dtparam=audio=on&amp;quot; &amp;gt;&amp;gt; /media/mmcblk0p1/usercfg.txt&lt;br /&gt;
&lt;br /&gt;
or your sound card (e.g. IQaudIO):&lt;br /&gt;
&lt;br /&gt;
  echo &amp;quot;dtoverlay=iqaudio-dacplus,unmute_amp&amp;quot; &amp;gt;&amp;gt; /media/mmcblk0p1/usercfg.txt&lt;br /&gt;
&lt;br /&gt;
reboot.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/ALSA these instructions] to enable ALSA. In summary&lt;br /&gt;
  &lt;br /&gt;
  apk add alsa-utils alsa-utils-doc alsa-lib alsaconf # the required software for sound&lt;br /&gt;
  aplay -l # should display a List of PLAYBACK Hardware Devices&lt;br /&gt;
&lt;br /&gt;
In my case my list is:&lt;br /&gt;
&lt;br /&gt;
  **** List of PLAYBACK Hardware Devices ****&lt;br /&gt;
  card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]&lt;br /&gt;
    Subdevices: 8/8&lt;br /&gt;
    Subdevice #0: subdevice #0&lt;br /&gt;
    Subdevice #1: subdevice #1&lt;br /&gt;
    Subdevice #2: subdevice #2&lt;br /&gt;
    Subdevice #3: subdevice #3&lt;br /&gt;
    Subdevice #4: subdevice #4&lt;br /&gt;
    Subdevice #5: subdevice #5&lt;br /&gt;
    Subdevice #6: subdevice #6&lt;br /&gt;
&lt;br /&gt;
Before you play anything from your speakers, I recommend turnong down the volume.&lt;br /&gt;
&lt;br /&gt;
  amixer&lt;br /&gt;
&lt;br /&gt;
displays a list of &amp;quot;simple controls.&amp;quot; For my headphones and the on-board sound, the output looks like this:&lt;br /&gt;
&lt;br /&gt;
  Simple mixer control &#039;Headphone&#039;,0&lt;br /&gt;
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined&lt;br /&gt;
    Playback channels: Mono&lt;br /&gt;
    Limits: Playback -10239 - 400&lt;br /&gt;
    Mono: Playback 0 [96%] [0.00dB] [on]&lt;br /&gt;
&lt;br /&gt;
In this case, there is only 1 control, &#039;Headphone&#039;, so I issue this command to lower the maximum volume to a comfortable level. (50%)&lt;br /&gt;
&lt;br /&gt;
  amixer sset Headphone 50%&lt;br /&gt;
&lt;br /&gt;
The IQaudIO DAC that I use has a much larger set of controls. I issued this command to set the volume:&lt;br /&gt;
&lt;br /&gt;
  amixer sset &#039;Digital&#039; 50 # quotes may be required if there are spaces in the control name&lt;br /&gt;
&lt;br /&gt;
Note: there can be several interlinked controls, some of which are muted by defualt. ALSA (and other audio software on Linux) is notoriously under-documented, try `man amixer` for more information. Sometimes it is easier to use a more visual control to change the configuration:&lt;br /&gt;
&lt;br /&gt;
  alsamixer&lt;br /&gt;
&lt;br /&gt;
Finally, if you issue this command:&lt;br /&gt;
&lt;br /&gt;
  speaker-test -t wav -c 2&lt;br /&gt;
&lt;br /&gt;
Then you should hear &amp;quot;Front Left, Front Right&amp;quot; repeating from your chosen speakers. Now it&#039;s time to setup Bluetooth. Don&#039;t forget to save your changes (lbu commit).&lt;br /&gt;
&lt;br /&gt;
=Bluetooth=&lt;br /&gt;
I used [https://wiki.alpinelinux.org/wiki/Raspberry_Pi_3_-_Setting_Up_Bluetooth Raspberry Pi 3 - Setting Up Bluetooth] as a reference with some slight modifications as I am using a Pi 4.&lt;br /&gt;
&lt;br /&gt;
Raspberry Pi 4&lt;br /&gt;
&lt;br /&gt;
  apk add bluez&lt;br /&gt;
  btattach -B /dev/ttyAMA0 -P bcm -S 3000000 &amp;amp;&lt;br /&gt;
  # btattach -B /dev/ttyAMA0 -P bcm -S 115200 -N &amp;amp; # Pi 3 - not tested by me&lt;br /&gt;
  rc-service bluetooth start&lt;br /&gt;
&lt;br /&gt;
edit {{Path|/etc/mdev.conf}} and enable bluetooth. We&#039;re using `sed`, where &#039;&#039;&#039;s/#rpi bluetooth/rpi bluetooth/&#039;&#039;&#039; means replace &#039;&#039;&#039;#rpi bluetooth&#039;&#039;&#039; with &#039;&#039;&#039;rpi bluetooth&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
  sed -i &#039;s/#rpi bluetooth/rpi bluetooth/&#039; /etc/mdev.conf&lt;br /&gt;
  sed -i &#039;s/#ttyAMA0         root:tty 660 @btattach -B \/dev\/$MDEV -P bcm -S 115200/ttyAMA0         root:tty 660 @btattach -B \/dev\/$MDEV -P bcm -S 3000000/&#039; /etc/mdev.conf&lt;br /&gt;
&lt;br /&gt;
Note: the last command uncomments the &#039;&#039;btattach&#039;&#039; command and changes it to work with the Pi 4. &lt;br /&gt;
&lt;br /&gt;
Changes to {{Path|/etc/bluetooth/main.conf}}&lt;br /&gt;
&lt;br /&gt;
  Name = Pi-Bluetooth-Speaker   # This is what you&#039;ll see when connecting &lt;br /&gt;
  Class = 0x41C                 # Adding audio playback and recording to this Bluetooth device&lt;br /&gt;
  DiscoverableTimeout = 0       # Always discoverable&lt;br /&gt;
  AlwaysPairable = true         # Always pairable&lt;br /&gt;
  PairableTimeout = 0           # no time limit&lt;br /&gt;
  AutoEnable=true               # starts Bluetooth when Linux &#039;sees&#039; the Bluetooth device at boot&lt;br /&gt;
&lt;br /&gt;
Ensure that Bluetooth is started at boot:&lt;br /&gt;
&lt;br /&gt;
  rc-update add bluetooth&lt;br /&gt;
&lt;br /&gt;
Bluetooth&#039;s state, including paired devices, in held in {{Path|/var/lib/bluetooth}} so you&#039;ll need to add this to `lbu` state:&lt;br /&gt;
&lt;br /&gt;
  lbu include /var/lib/bluetooth&lt;br /&gt;
  lbu commit &amp;amp;&amp;amp; reboot&lt;br /&gt;
&lt;br /&gt;
Manual device pairing&lt;br /&gt;
&lt;br /&gt;
  bluetoothctl&lt;br /&gt;
&lt;br /&gt;
  [bluetooth]# discoverable on&lt;br /&gt;
  [agent] Confirm passkey 627133 (yes/no): yes&lt;br /&gt;
  [agent] Authorize service 0000110e-0000-1000-8000-00805f9b34fb (yes/no): yes&lt;br /&gt;
&lt;br /&gt;
Device pairing:&lt;br /&gt;
&lt;br /&gt;
  apk add python3 py3-dbus py3-gobject3&lt;br /&gt;
&lt;br /&gt;
Getting this to work currently involves running the bluez-simple-agent after having edited it to always return sucessful. You&#039;ll need to comment out some lines (by adding &amp;quot;#&amp;quot; at the beginning):&lt;br /&gt;
&lt;br /&gt;
  vi /usr/bin/bluez-simple-agent&lt;br /&gt;
&lt;br /&gt;
  #import bluezutils&lt;br /&gt;
&lt;br /&gt;
        def RequestConfirmation(self, device, passkey):&lt;br /&gt;
                #print(&amp;quot;RequestConfirmation (%s, %06d)&amp;quot; % (device, passkey))&lt;br /&gt;
                #confirm = ask(&amp;quot;Confirm passkey (yes/no): &amp;quot;)&lt;br /&gt;
                #if (confirm == &amp;quot;yes&amp;quot;):&lt;br /&gt;
                set_trusted(device)        &lt;br /&gt;
                return        &lt;br /&gt;
                #raise Rejected(&amp;quot;Passkey doesn&#039;t match&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
And then running the revised agent in the background, and pair your devices:&lt;br /&gt;
&lt;br /&gt;
  bluez-simple-agent &amp;amp;&lt;br /&gt;
  lbu include /usr/bin/bluez-simple-agent&lt;br /&gt;
  lbu commit&lt;br /&gt;
&lt;br /&gt;
Notes: [https://www.kynetics.com/docs/2018/pairing_agents_bluez/ Pairing Agents in BlueZ stack]&lt;br /&gt;
[https://stackoverflow.com/questions/59214524/since-bluez-5-48-iphones-require-pairing-when-connecting-on-a-ble-gap-periphera Since Bluez 5.48, iPhones require pairing when connecting on a BLE GAP peripheral, why?]&lt;br /&gt;
[https://gist.github.com/mill1000/74c7473ee3b4a5b13f6325e9994ff84c Headless A2DP Audio Streaming on Raspbian Stretch ]&lt;br /&gt;
&lt;br /&gt;
=bluez-alsa=&lt;br /&gt;
At the time of writing this article, bluez-alsa is only found in the community repositories, so you need to edit your repository list:&lt;br /&gt;
&lt;br /&gt;
  vi /etc/apk/repositories&lt;br /&gt;
&lt;br /&gt;
remove the &amp;quot;#&amp;quot; from the community repository, mine is:&lt;br /&gt;
&lt;br /&gt;
  http://uk.alpinelinux.org/alpine/v3.14/community&lt;br /&gt;
&lt;br /&gt;
This is the final stretch.  We&#039;ve got bluetooth working and now we want to link bluetooth to the speakers&lt;br /&gt;
&lt;br /&gt;
  apk add bluez-alsa bluez-alsa-utils bluez-alsa-openrc&lt;br /&gt;
  rc-update add bluealsa&lt;br /&gt;
  service start bluealsa&lt;br /&gt;
  bluealsa-aplay &amp;amp;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Arkq/bluez-alsa Bluetooth Audio ALSA Backend]&lt;br /&gt;
[https://github.com/Arkq/bluez-alsa/tree/master/doc bluez-alsa doc]&lt;br /&gt;
[https://manpages.debian.org/unstable/bluez-alsa-utils/bluealsa.8.en.html man bluealsa]&lt;br /&gt;
[https://manpages.debian.org/unstable/bluez-alsa-utils/bluealsa-aplay.1.en.html man bluealsa-aplay]&lt;br /&gt;
[https://panther.kapsi.fi/posts/2018-11-17_linux_bluetooth_audio Bluetooth audio in Linux: ALSA and LDAC]&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
Raspberry Pi&#039;s blog on [https://www.raspberrypi.org/blog/how-to-play-sound-and-make-noise-with-your-raspberry-pi/ How to play sound and make noise with your Raspberry P]&lt;br /&gt;
&lt;br /&gt;
There are lots of speaker and amplifier options:&lt;br /&gt;
* Raspberry Pi&#039;s [https://www.raspberrypi.org/blog/iqaudio-is-now-raspberry-pi/ IQaudIO boards]&lt;br /&gt;
* Pimoroni&#039;s [https://shop.pimoroni.com/products/audio-amp-shim-3w-mono-amp Audio Amp SHIM (3W Mono Amp)] and [https://shop.pimoroni.com/products/mini-speaker-4-3w Mini Speaker 4Ω (3W)]&lt;br /&gt;
* The Pi Hut offers this [https://thepihut.com/products/adafruit-i2s-3w-stereo-speaker-bonnet-for-raspberry-pi Adafruit I2S 3W Stereo Speaker Bonnet for Raspberry Pi (Mini Kit)] and the [https://thepihut.com/products/stereo-enclosed-speaker-set-3w-4-ohm Stereo Enclosed Speaker Set - 3W 4 Ohm]&lt;/div&gt;</summary>
		<author><name>Gomgom</name></author>
	</entry>
</feed>