Playing sounds and using buttons with Raspberry Pi - Problem

by raspberrypibeginners on Sat Dec 01, 2012 1:29 pm

Hi guys,

I'm trying to run the example in "Playing sounds and using buttons with Raspberry Pi" and i'm finding that whenever i press the button it tries to play them MP3 over and over again within a few seconds and basically doesn't work. Any though?
raspberrypibeginners
 
Posts: 3
Joined: Sat Dec 01, 2012 12:57 pm

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by raspberrypibeginners on Fri Dec 21, 2012 7:47 am

Hey did anyone have any thoughts on this?
raspberrypibeginners
 
Posts: 3
Joined: Sat Dec 01, 2012 12:57 pm

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by The0001 on Thu Apr 25, 2013 3:50 pm

I am also having problems with this example... I followed the tutorial verbatim since I just received my Pi. I was able to successfully run the program and the buttons do appear to register properly for each GPIO, but instead of hearing an MP3 play, I get an error message that says:
tcgetattr(): Inappropriate ioctl for device
glad.mp3: Invalid argument


Since I am completely new to linux, I have absolutely no idea how to begin to fix the MP3 not playing issue.
I have the same hardware that everyone else has. I followed the instructions on how to set up the audio. The MP3's worked (on my Windows laptop) and they are not very big in size. I put them in the same directory as the button program as instructed. I have headphones plugged into the audio jack. Any suggestions on what can I do to make the sound work?
The0001
 
Posts: 4
Joined: Thu Apr 25, 2013 3:39 pm

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by tldr on Sat Apr 27, 2013 10:02 am

looks kind of like this is a problem in the process spawned to run mpg321.

which linux install are you using?

try

Code: Select all
mpg321 glad.mp3


from the shell. then try

Code: Select all
mpg321 glad.mp3&


show us the exact code you are running.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 465
Joined: Thu Aug 30, 2012 12:34 am

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by The0001 on Mon Apr 29, 2013 11:57 am

tldr,

The version reported when I boot up is Linux raspberrypi 3.2.27+
The tutorial is here: http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi

Here's the code, which is essentially the code copied from the tutorial with my mp3 filenames substituted in...

Code: Select all
#!/usr/bin/env python

from time import sleep
import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

while True:
        if ( GPIO.input(23) == False ):
                os.system('mpg321 hailed.mp3 &')
        if ( GPIO.input(24) == False ):
                os.system('mpg321 glad.mp3 &')
        if ( GPIO.input(25)== False ):
                os.system('mpg321 braincells.mp3 &')
        sleep(0.1);


I followed the tutorial step-by-step, but got no sound when I press the GPIO buttons. :(
I also tried your suggestions and typed
Code: Select all
mpg321 glad.mp3

Code: Select all
mpg321 glad.mp3&

Code: Select all
sudo mpg321 glad.mp3

Code: Select all
sudo mpg321 glad.mp3&

even tried
Code: Select all
sudo mpg321 glad.mp3 &

just in case spaces make a difference. (I'm a total noob at Linux, btw.)
No dice.
Every time I try running mpg321, it spits out the message, "glad.mp3: Invalid argument"

At least the GPIO buttons work.
I think I need to find a simple example that tests the audio functionality of the Pi.
The0001
 
Posts: 4
Joined: Thu Apr 25, 2013 3:39 pm

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by The0001 on Mon Apr 29, 2013 3:09 pm

I got my audio to work...
I followed the guide at this site to test my audio: https://sites.google.com/site/semilleroadt/home/raspberry-pi

I also learned that Midori doesn't allow file downloads. (Or at least it doesn't work for mp3's) Basically, my mp3's were invalid because I unsuccessfully tried downloading them with Midori. The filename shows up but upon closer inspection, its filesize was 0 bytes! (I only came to this realization after going through the audio test above and performing a command line download of their test audio file.)

I used a different browser to download mp3's and now the program works with sound. 8)

One minor potential issue with the code though...
I noticed that if you hold the button a little longer than your average button press, then the program seems to try to play multiple instances of the same sound clip simultaneously. The speed at which this appears to be controlled might be the "sleep" command? If set at 0.1, I assume it will loop through the polling loop quite fast and perhaps overwhelm the cpu?
Well, I seem to have locked up the Pi because I held the button down for a few seconds. In the amount of time it has taken me to type up this response, the Pi has not recovered, so it looks like it's time to yank the power.
I've got a lot to learn! Sigh.
The0001
 
Posts: 4
Joined: Thu Apr 25, 2013 3:39 pm

Re: Playing sounds and using buttons with Raspberry Pi - Problem

by dkj10738 on Tue May 28, 2013 2:48 am

Help, I am having a similar problem. My audio plays fine from the CL, but as soon as I run the code from the tutorial, it starts playing one of the MP3 files incessantly. This happens even if I don't connect a ribbon cable to the GPIO pins. I am stuck.
dkj10738
 
Posts: 1
Joined: Tue May 28, 2013 2:42 am

Re: Playing sounds and using buttons with Raspberry Pi - Pro

by ThirdRate on Sat Mar 29, 2014 9:41 pm

dkj10738 wrote:Help, I am having a similar problem. My audio plays fine from the CL, but as soon as I run the code from the tutorial, it starts playing one of the MP3 files incessantly. This happens even if I don't connect a ribbon cable to the GPIO pins. I am stuck.


So I'm a complete n00b at this but as far as I can tell the program actually works by playing the sound file when the circuit is broken by pressing the button... basically, pressing the button removes changes a given pin from receiving electricity to not receiving electricity. The status of not receiving electricity is what tells the program to play the music file.

If you're able to play the mp3 file fine from the command line but when you start the program it just starts playing instantly (and repeatedly) then it sounds like you might not have your circuit built right. Again, being completely new to this I may be way off track but here are a few things I noticed working on this myself:

1) if you got the opaque (not clear) breadboard with your starter kit, it is actually split two ways: long way for the middle part and short way for the outer (top and bottom) parts. There is a split along the channel that runs down the length of the board as far as the middle section is concerned, as well as a split between the left and right side where the red and blue lines on the top and bottom have a break in them. If your circuit is trying to pull voltage from one of the channels on the LEFT side of this break in the red/blue lines, but you actually plugged your ribbon/cobbler into the RIGHT side, then you need to use wires to bridge the gap between the left and right sides. A better solution IMO is just to make sure that all the wires/resistors that plug into the area between the blue and red lines are all on the same side of the middle split between these lines.

2) It made a difference for me which way the resistors were facing. Full disclosure, I might not have had them plugged in all the way to begin with, but I didn't get it to work until I had all the resistors facing the same direction and that means the brown stripe closer to the button and the gold stripe plugged into the voltage area (between red/blue lines)

3) this doesn't really apply to YOUR issue since you got the files to play on command line, but Midori, the built in browser on the GUI, does NOT download mp3 files correctly... this was my main issue. I went through the additional audio set-up recommended in one of the replies to the other issues but wanted to reiterate here that Midori browser does not download mp3 files correctly. I had to, from the command line, use the wget function: wget http:\\www.somewebsite.com\filename.mp3

Anyway, those were my big issues.
er... uhm... Please help?
ThirdRate
 
Posts: 2
Joined: Sat Mar 15, 2014 11:11 pm