I have a Raspberry Pi 5 4Gb. I am trying to run a Python script on boot which will allow me to control the volume of my default amixer device (Master) through a slider switch. The script works perfectly fine when I run it manually.
However, I am unable to access the "Master" device via amixer when running the script on boot.
When I run the
amixer controls
command via SSH while logged into userpi
(or running the Python script), I get this output:numid=4,iface=MIXER,name='Master Playback Switch' numid=3,iface=MIXER,name='Master Playback Volume' numid=2,iface=MIXER,name='Capture Switch' numid=1,iface=MIXER,name='Capture Volume'
However, when I run the same script on reboot, I get this output instead:
numid=1,iface=CARD,name='HDMI Jack' numid=5,iface=PCM,name='ELD' numid=4,iface=PCM,name='IEC958 Playback Default' numid=3,iface=PCM,name='IEC958 Playback Mask' numid=2,iface=PCM,name='Playback Channel Map'
Note that I get this same second output if I run the command
sudo amixer controls
.I've tried running the script via
crontab -e
and I've also tried putting this line into myrc.local
file:su -u pi -c "python /home/pi/scripts/volume.py > /home/pi/scripts/volume.log 2>&1" &
However, both of these result in the same second output.
I believe getting the first output has something to do with running the script under the correct user or setting my environment variables correctly, but I have no idea how to do it.
Would someone be able to help me here?