Playing sounds and using buttons with Raspberry Pi - Problem

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Playing sounds and using buttons with Raspberry Pi - Problem

Postby raspberrypibeginners » 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

Postby raspberrypibeginners » 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

Postby The0001 » 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: 3
Joined: Thu Apr 25, 2013 3:39 pm

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

Postby tldr » 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: 346
Joined: Thu Aug 30, 2012 12:34 am

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

Postby The0001 » 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: 3
Joined: Thu Apr 25, 2013 3:39 pm

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

Postby The0001 » 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: 3
Joined: Thu Apr 25, 2013 3:39 pm


Return to General Project help

Who is online

Users browsing this forum: Google [Bot] and 6 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
Android[6]
 
BeagleBone[24]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]