cmlop02
Posts: 1
Joined: Sat Oct 03, 2015 3:30 pm

pi button audio not working

Sat Oct 03, 2015 3:42 pm

i've been trying to do this project https://learn.adafruit.com/playing-soun ... i/overview my wireing is right but when i push the button i get
[mpg123.c:629] error: Cannot open
binary-language-moisture-evaporators.mp3: File access error. (code 22)

I put a working mp3 in the home folder with the .py named binary-language-moisture-evaporators.mp3 and gpio pin 23. help!

smarz2
Posts: 5
Joined: Sun Feb 14, 2016 5:54 am

Re: pi button audio not working

Sun Feb 21, 2016 1:48 am

I have a python script which plays an mp3 file using mpg123. When I run the python script from a command line, the mp3 file plays. When I place the python script in /etc/rc.local to run the python script on R-Pi bootup, most of the script runs perfectly except the mp3 file does not play, and I receive the error

[mpg123.c:xxx] error: cannot open memo.mp3: File access error(code 22)

I have a Raspberry Pi 2 connected to a Samsung Syncmaster 205BW using an HDMI to DVI cable.

I changed the /boot/config.txt to add hdmi_drive=2, and the audio works (finally) when I run the rc.local in a test mode, but then the R-Pi won't bootup.It flashes an error: Optimum Resolution 1680x1050 60 Hz. I changed the parameters below to set the config.txt for my monitor:

hdmi_group=2
hdmi_mode=58 1680x1050 60 Hz

It is only on boot that the audio doesn't work. When I change hdmi_drive=2, then I get the monitor resolution error that keeps flashing, and it won't boot up. Can anyone please help?

smarz2
Posts: 5
Joined: Sun Feb 14, 2016 5:54 am

Re: pi button audio not working

Sun Feb 21, 2016 8:17 am

I figured out my problem, My python script had the line below:

os.system('mpg123 -q Memo.mp3 &')

This code worked great from a command line while I was logged in as"pi", but when the script is run on boot from /etc/rc.local, the file takes on root's environment variables, and the Memo.mp3 file which is located in a folder under pi's home folders is not found. When I run from a command promptas pi user, the foldersunder pi's home directory are in the pi user's PATH. Therefore, the script runs fine since the file is found.

I want to thank the soapBAR2's post which led me to my solution: http://ubuntuforums.org/showthread.php?t=1313921

When I changed my code to add the full path to my mp3 file, as shown below, the mp3file plays on R-Pi boot up. I changed the code as shown below:
os.system('mpg123 -q /home/pi/Desktop/Current_software/good/Memo.mp3 &')

I hope this helps someone else with this problem. I incorrectly thought my problem was a monitor setting which was a red herring.

neurosynapse
Posts: 1
Joined: Sat Jun 04, 2016 9:53 pm

Re: pi button audio not working

Sat Jun 04, 2016 9:55 pm

Thanks so much for posting your solution, I had a similar problem and it's fixed now!

Return to “Troubleshooting”