Sound volume is always the same

I have Picar-X wit Robot Hat v4.
The sound works, all the tests in “3.tts_example.py” work fine.
The Music.play_tone_for() methods work too.

The issue is that executing set_volume() does not change the volume at all - no matter if it is set_volume(10) or set_volume(100) the volume is the same.
This applies to bot TTS and Music.

I get this when executing e.g. set_volume(10):

Simple mixer control 'PCM',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback -10239 - 400
  Mono:
  Front Left: Playback -5600 [10%] [-56.00dB] [on]
  Front Right: Playback -5600 [10%] [-56.00dB] [on]

so it does attempt to change the volume but the volume stays the same.

I did run sudo bash i2samp.sh, of course.
One curious thing is that, when it runs the testing part, only the sound “Front Right” is heard - as though it thinks that the Robot Hat speaker is a front-right speaker …
Shouldn’t it be a mono-speaker, i.e. all sound is directed to that single speaker?

Incidentally, there is a whole bunch of errors printed out in terminal when play_tone_for() is called the first time :

ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5703:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5703:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_a52.c:1001:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5670:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2 CARD 0}
ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2 CARD 0}
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream

Next call to play_tone_for() produces only this:
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)

Is there some fix/solution for setting the volume?

Oh, the music_set_volume() also does nothing.

I run alsamixer in a terminal on the GUI and run my code over SSH.
As soon as ˙set_volume(100)’ is executed in my code, the alsamixer’s volume bar jumps to maximum.

And yet the sound level remains the same.

While the “ALSA lib” errors are one-time and can be tolerated, the “XDG_RUNTIME_DIR” errors keep popping up by themselves every 3 to 4 seconds!
They mess up anything being shown in terminal :person_facepalming: :roll_eyes:

Thank you for reaching out.
I recommend providing us with a video of the issue to help us analyze the speaker volume problem more effectively.If the video file is too large, you can upload it to OneDrive and share the link with access enabled.
In the meantime, you can try executing the following command to adjust the volume:
sudo amixer -c 1 sset PCM 80%
Please let us know if you notice any changes.

Unfortunately, the amixer command did not change anything - the volume is the same a before.
When I run the sudo amixer -c 1 sset PCM 80% command I get this response:

Simple mixer control 'PCM',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 255
  Front Left: 204 [80%]
  Front Right: 204 [80%]

As I wrote before, all the software controls behave normally and show expected result, however, the sound volume coming from the speaker is very low.

Incidental, apart from low sound volume I have observed following 2 issues related to motors:

  1. Running motors interfere with ultrasound sensor readings (there is a lot of readings that differ from actual value by up to 50%, as opposed to same piece of code giving consistent results when motors are not running)

  2. Driving at the same power for the same time results in different travel distances. No wheel slipping, same battery level.
    The difference is mostly not in the consecutive drives, but happens every now and then (e.g. robot now drives for 1m consistently in 10 tests, and one hour later it suddenly drives 0.8m, consistently in repeated tests, then after half hour it starts driving 0.85m, 0.88m, 0.9m, 0.94m in consecutive drives and then drives 0.95m in 10 tests)

Not sure if these behaviors have anything to do with sound level, though, but point to some quality issues, which may be a common cause.

Could you please provide us with an image of the Robot Hat so we can confirm which version it is?
And contact service@sunfounder.com with your address for the replacement.

OK, here is the photo of my Robot Hat:

I have sent an email with my address as you instructed too.

Thank you!