noahkiser95
Posts: 4
Joined: Tue Jun 10, 2014 3:24 pm

Remotely triggering .wav sounds from another networked Pi

Sun Nov 08, 2015 6:29 pm

This is my first post and my first major Python program, and I have a few questions to ask.

I am trying to build an R2D2 and plan to use 2 Raspis, one for the brains of the robot and another for the controller. The pigpio daemon will be running on the robot-Pi, and I plan to use the pigpio python library to control the GPIO pins from the controller-Pi, using software PWM for motor and light control. The controller-Pi will be using pygame to read from a generic USB gamepad/joystick, and triggering robot-Pi GPIO events based on what buttons are pressed and the position of the analog sticks.

This all will probably work fine, and I foresee no conflicts between pygame and pigpio. But I would love my R2D2 to speak, and have found a bunch of .wav sounds of R2D2 speaking on the internet. I know that I can use pygame to play .wav sounds locally (on the controller-Pi), but I would like to have the .wav sounds stored and played from the robot-Pi, with playback triggered remotely from the controller-Pi. I would like, say, sound1.wav to be played on the robot-Pi when I press button9 on the gamepad connected to the controller-Pi, keeping in mind that I already have the gamepad being used by pygame to control GPIO via pigpio.

What is the best way to trigger the playback of .wav sounds via gamepad button presses on a 2 seperate Pi's?

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Remotely triggering .wav sounds from another networked P

Mon Nov 09, 2015 8:54 am

You can use SSH to remotely execute commands (e.g. start a mediaplayer)

https://stackoverflow.com/questions/185 ... te-command

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Remotely triggering .wav sounds from another networked P

Mon Nov 09, 2015 6:34 pm

noahkiser95 wrote:What is the best way to trigger the playback of .wav sounds via gamepad button presses on a 2 seperate Pi's?
omxplayer will run from a ssh and make sound on the machine you are ssh into. Other software will do this too but omxplayer is lightweight on the pi. So all you need to do is open up a ssh and then remotely run commands whenever R2D2 needs to beep and pop and snort like he always likes to do.

User avatar
rpdom
Posts: 17184
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Remotely triggering .wav sounds from another networked P

Mon Nov 09, 2015 7:00 pm

stderr wrote:
noahkiser95 wrote:What is the best way to trigger the playback of .wav sounds via gamepad button presses on a 2 seperate Pi's?
omxplayer will run from a ssh and make sound on the machine you are ssh into. Other software will do this too but omxplayer is lightweight on the pi. So all you need to do is open up a ssh and then remotely run commands whenever R2D2 needs to beep and pop and snort like he always likes to do.
I use aplay (part of the alsa-utils package) for playing .wav files on the Pi. It isn't exactly CPU intensive work. omxplayer is fine for mp3s and video.

noahkiser95
Posts: 4
Joined: Tue Jun 10, 2014 3:24 pm

Re: Remotely triggering .wav sounds from another networked P

Mon Nov 09, 2015 7:15 pm

Thanks so much for the feedback. How would I go about SSH'ing from Python code? I found the Paramiko library, would that work?

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Remotely triggering .wav sounds from another networked P

Tue Nov 10, 2015 10:57 am

You could simply use subprocess to call the ssh command :
https://gist.github.com/bortzmeyer/1284249

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

noahkiser95
Posts: 4
Joined: Tue Jun 10, 2014 3:24 pm

Re: Remotely triggering .wav sounds from another networked P

Wed Nov 11, 2015 9:33 pm

SSH-ing works great from Python now. I am using Paramiko to initiate the connection and send commands, and have figured out PyGame to work with my controller, and now pressing buttons on the controller connected to one Pi makes sounds play on the other Pi. :D

Now on to pigpio. I have the daemon installed on both Pi's and so far I am dealing locally. I can read and write digital, and that works great, but PWM is shooting errors at me.
Running this code:

Code: Select all

import pigpio
pi = pigpio.pi()
pi.set_PWM_dutycycle(2, 255)
which should set pin 2 to HIGH (basically), returns the error:

Code: Select all

AttributeError: 'NoneType' object has no attribute 'send'
I have Google'd this, but have not found any solution, what is going wrong?
I do not want to revert RPI.GPIO, because I will need to control the GPIO pins on a REMOTE Pi, which RPI.GPIO cannot do.

EDIT:
I did some more looking around, and FINALLY found some Python pigpio PWM example code....turns out it wants you to set the pin to OUTPUT before giving it PWM commands.

Return to “Python”