Connecting a Bluetooth Speaker (ssh/command line)

119 views
Skip to first unread message

Marcus Fehn

unread,
Feb 18, 2021, 1:07:49 PM2/18/21
to PicoChess
Hi. :)

I’m running Picochess on a Raspberry Pi 4. I have a Bluetooth speaker setup, i.e. it’s trusted, paired and connected. I can also play sounds using aplay /some.wav

However, there is no sound when playing with Picochess, e.g. no voice, so I guess I’m missing something. Via web server I have "System > Sound > Always" as well as "System > Voice > Pico/User Voice > On > Christina".

Any hints?
Thank you...

RandyR

unread,
Feb 18, 2021, 1:25:13 PM2/18/21
to PicoChess
Hi Marcus,

I'm not sure how much I can help but there are a couple things you can look at. Can you test if sound is available from the audio jack on the RPi4? What do you see when you run alsamixer in Terminal? Finally, check sound options in raspi-config.

What image are you using?

Randy

Marcus Fehn

unread,
Feb 18, 2021, 2:00:12 PM2/18/21
to PicoChess
alsamixer shows a volume level, I guess, red/white/green, 100<>100 Master.
raspi-config > System > Sound only allows HDMI/3.5mm jack – and I get sound output via a headphone connected to my Raspberry Pi.
I get sound to play via aplay, so the speaker is connected via bluetooth and generally works.

Is there anything I need to set with regards to which output picochess uses?

Thanks

RandyR

unread,
Feb 18, 2021, 2:24:57 PM2/18/21
to PicoChess
Picochess uses SoX for audio. I suspect the default output device is not the BT speaker. Try playing a sound file using 'play' from the command line. What happens?

Marcus Fehn

unread,
Feb 18, 2021, 2:56:52 PM2/18/21
to PicoChess
pi@picochess:~ $ play /usr/share/sounds/alsa/Front_Center.wav
play WARN alsa: can't encode 0-bit Unknown or not applicable

/usr/share/sounds/alsa/Front_Center.wav:

File Size: 137k Bit Rate: 768k
Encoding: Signed PCM
Channels: 1 @ 16-bit
Samplerate: 48000Hz
Replaygain: off
Duration: 00:00:01.43

In:100% 00:00:01.43 [00:00:00.00] Out:68.5k [ | ] Clip:0
Done.
pi@picochess:~ $



Hm. Not sure what's happening here…
I checked the man page for SoX, but I don’t understand what to do, hehe. I guess you're right, though, that the output is set to the 3.5.
I now hooked up the speaker to audio-out, and for the time being, this will work, but I'd like to go wireless at some point. 

Thanks for you time. 

Randy Reade

unread,
Feb 18, 2021, 2:58:52 PM2/18/21
to pico...@googlegroups.com
What does 'pactl list sinks' show?

--
You received this message because you are subscribed to the Google Groups "PicoChess" group.
To unsubscribe from this group and stop receiving emails from it, send an email to picochess+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/picochess/b4451144-8df2-4a7c-9cae-38b4fca62381n%40googlegroups.com.

Marcus Fehn

unread,
Feb 18, 2021, 3:06:38 PM2/18/21
to PicoChess

pi@picochess:~ $ pactl list sinks
Sink #0
State: SUSPENDED

Name: auto_null
Description: Dummy Output
Driver: module-null-sink.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 13
Mute: no
Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
        balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: auto_null.monitor
Latency: 0 usec, configured 0 usec
Flags: DECIBEL_VOLUME LATENCY
Properties:
        device.description = "Dummy Output"
        device.class = "abstract"
        device.icon_name = "audio-card"
Formats:
        pcm
pi@picochess:~ $         

Randy Reade

unread,
Feb 18, 2021, 3:10:38 PM2/18/21
to pico...@googlegroups.com
That doesn't look right. Here is what I see on the RPi4b:

$ pactl list sinks
Sink #0
State: SUSPENDED
Name: alsa_output.platform-bcm2835_audio.digital-stereo
Description: Built-in Audio Digital Stereo
Driver: module-alsa-card.c

Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 6

Mute: no
Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
       balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.platform-bcm2835_audio.digital-stereo.monitor

Latency: 0 usec, configured 0 usec
Flags: HARDWARE DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "bcm2835 HDMI 1"
alsa.id = "bcm2835 HDMI 1"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "bcm2835 HDMI 1"
alsa.long_card_name = "bcm2835 HDMI 1"
alsa.driver_name = "snd_bcm2835"
device.bus_path = "platform-bcm2835_audio"
sysfs.path = "/devices/platform/soc/fe00b840.mailbox/bcm2835_audio/sound/card0"
device.form_factor = "internal"
device.string = "hw:0"
device.buffering.buffer_size = "10576"
device.buffering.fragment_size = "2640"
device.access_mode = "mmap"
device.profile.name = "digital-stereo"
device.profile.description = "Digital Stereo"
device.description = "Built-in Audio Digital Stereo"
alsa.mixer_name = "Broadcom Mixer"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card"
Ports:
hdmi-output-0: HDMI / DisplayPort (priority: 5900)
Active Port: hdmi-output-0
Formats:
pcm

Sink #1
State: SUSPENDED
Name: alsa_output.platform-bcm2835_audio.analog-stereo
Description: Built-in Audio Analog Stereo
Driver: module-alsa-card.c

Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 7

Mute: no
Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
       balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.platform-bcm2835_audio.analog-stereo.monitor

Latency: 0 usec, configured 0 usec
Flags: HARDWARE DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "bcm2835 Headphones"
alsa.id = "bcm2835 Headphones"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "1"
alsa.card_name = "bcm2835 Headphones"
alsa.long_card_name = "bcm2835 Headphones"
alsa.driver_name = "snd_bcm2835"
device.bus_path = "platform-bcm2835_audio"
sysfs.path = "/devices/platform/soc/fe00b840.mailbox/bcm2835_audio/sound/card1"
device.form_factor = "internal"
device.string = "hw:1"
device.buffering.buffer_size = "10576"
device.buffering.fragment_size = "2640"
device.access_mode = "mmap"
device.profile.name = "analog-stereo"
device.profile.description = "Analog Stereo"
device.description = "Built-in Audio Analog Stereo"
alsa.mixer_name = "Broadcom Mixer"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card"
Ports:
analog-output: Analog Output (priority: 9900)
Active Port: analog-output
Formats:
pcm

What picochess image are you using?

RandyR

unread,
Feb 18, 2021, 3:29:58 PM2/18/21
to PicoChess
Marcus,

I just paired my BT headset (Bose Quietcomfort 35 II) and selected Bose QC35 II under Audio Output using the speaker icon on the Desktop. I rebooted, it reconnected, and I have audio from picochess.

Perhaps you should try reflashing with the latest image.

Randy

RandyR

unread,
Feb 18, 2021, 4:34:12 PM2/18/21
to PicoChess
Ok. I think you disabled the built-in audio by editing /boot/config.txt. That's what I just did and I get the auto_null sink. There is probably a '#' in front of:

dtparam=audio=on

At any rate, I think I see the issue you are having. With the above line uncommented (no '#') I rebooted and had problems reconnecting to the BT headphones. Then, I tried leaving them off until the RPi booted and turning them on. This allowed them to connect, but there was no audio output from picochess. Note that I start picochess manually via ssh on my RPi4. I stopped picochess, logged in via VNC and started picochess via a Terminal. The sound worked. I'll re-enable the picochess.service and do some more tests.

Randy

RandyR

unread,
Feb 18, 2021, 5:26:44 PM2/18/21
to PicoChess
It seems to work for me now, at least most of the time.

If I start picochess at boot (sudo systemctl enable picochess), which is the default behaviour of the Desktop and Lite images, the BT reconnects and picochess sounds work. I miss a bit of audio when picochess starts since BT is still connecting. If I shutdown (using the 2 white queens on d1,e1) and restart the RPi4, BT reconnects and sounds work. If I leave the BT headphones off, start up the RPi4, wait until I can access the webserver, then turn my BT headphones ON, they pair and picochess sounds work. However, sometimes BT won't reconnect and I have to power cycle my headphones. I didn't test the Lite image. And dtparam=audio=on is still uncommented, so I'll go back to using a little speaker, which works all of the time.

Also, playing sounds as root will not work, which is why running picochess manually via sudo did not work for me.

BT seems really flakey, though. I hope they sort it out.

Randy

RandyR

unread,
Feb 18, 2021, 7:05:54 PM2/18/21
to PicoChess
I should clarify that last post - playing sound as root via sudo over ssh on a headless Pi does not work. So starting picochess manually via sudo python3 picochess.py does not have sound (nor does sudo play <sound file>). However, if you log in via VNC and start picochess, sound will work. As will playing sound as root. If someone can explain this, or let me know how to make it work, I'd be happy to apply the solution to my images.

Randy

Marcus Fehn

unread,
Feb 18, 2021, 11:14:45 PM2/18/21
to PicoChess

Actually, this is what's in /boot/config.txt

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
audio_pwm_mode=2

So I guess I’m safe here.
I’m on the desktop image, but running the Pi headless (couldn't get my screen to work, so I’m ssh'ing over Terminal).

What I don’t understand: How do you even get the speaker to automatically connect after a boot? I need to manually enter bluetoothtcl and then "connect [MAC address]".

RandyR

unread,
Feb 19, 2021, 10:03:59 AM2/19/21
to PicoChess
Marcus,

Since you are using the Desktop version, try using RealVNC Viewer on your PC and use the Bluetooth icon to scan/pair the device (perhaps remove the device first if it's showing), and the Speaker icon to select the Audio Output device. I wasn't testing using bluetoothctl, although that should work as well (scan/pair/trust).

Randy

Reply all
Reply to author
Forward
0 new messages