Control With buttons or screen?

So, what would be the best way to have a GPIO button play a certain web stream? Should command gstreamer with os in python, or is it better to command mopidy?

Iā€™m unfamiliar with other methods but here is the section of code to play a specific Spotify playlist if the ā€œplayā€ button is pressed and nothing is loaded already:

if pad2pressed and not pad2alreadyPressed:
            print "Pad 2 pressed // Play/Pause"
            mpcstatus = subprocess.check_output("mpc status", shell=True, stderr=subprocess.STDOUT)
            match = re.search(r'\[p', mpcstatus)
            print(mpcstatus)
            print(match)
            if match: 
                os.system("mpc toggle")
            else: 
                os.system("mpc clear")
                os.system("mpc add spotify:user:michaellunzer:playlist:53WupSpTZzYgLhG5wYPZ6t")
                os.system("mpc play")
        pad2alreadyPressed = pad2pressed

If you just want a playlist to play when a button is pressed, maybe make it look like this:

if pad2pressed and not pad2alreadyPressed:
        print "Pad 2 pressed // Play/Pause"
        mpcstatus = subprocess.check_output("mpc status", shell=True, stderr=subprocess.STDOUT)
        match = re.search(r'\[p', mpcstatus)
        print(mpcstatus)
        print(match)
        if match: 
            os.system("mpc clear")
            os.system("mpc add spotify:user:michaellunzer:playlist:53WupSpTZzYgLhG5wYPZ6t")
            os.system("mpc play")
    pad2alreadyPressed = pad2pressed

This is untested, but it should clear whatever is playing, add the playlist and play it. But consider, it will probably start the playlist from the beginning each time the button is selected.

Maybe you can explain exactly what you are trying to accomplish and we can figure out what needs to be done.

  • Lunz

OK. I meant having preset internet radio channels buttons. So, you toggle it and it starts to play the radio channel. A live stream, therefore does not matter if from beginning every time. But I think that mpc cannot do this, so using os module to control mpc canā€™t be done?

To use mpc to play a live radio station, when using a remote and LIRC, I get the relevant info from Tunein (tunein:station:s83012) then paste into a notepad file, save as a .m3u file in the playlists directory.
then use mpc load ā€˜name of file hereā€™; mpc play
So the actual instruction would look like
button = KEY_3
config = mpc stop; mpc clear; echo ā€œBBC Radio Five Liveā€ | festival --t$
config = mpc load Radio5; mpc play

Did you remove some code examples?

I think you are correct, and this didnā€™t come to my mind. At least it is true that .m3u playlists can have streams in them and that they can be put in the playlist directory. If mpc can then play these, then any script referring to mpc should also. I tried to read up on the mpc documentation but was unsure if it can be done.

Iā€™m not sure what you mean.

Iā€™m sorry. What happened is that I got confused with two different threads and answered to you on something that was not intended for you at all. Sorry :open_mouth:

Hi!

If youā€™re handy with python Iā€™ve written a simple module to interface with mopidy methods and events via Websockets API. You can find it on https://github.com/ismailof/mopidy-json-client.

There is one example which uses a GPIO knob to control volume and mute. Another example shows how to use the interface to play tracks, modify the tracklist, make searches, etc.

Since it uses the HTTP API it runs outside of mopidy extension environment as a different process, which can be a pro or a con depending on your purposes. It is quite alpha but mainly working, but maybe not suitable for newbies in its current shape.

1 Like

5 posts were split to a new topic: GPIO extension - internal pullup resistors are not functioning properly

On the topic of embedding something in furniture, this is very cool. https://www.raspberrypi.org/blog/gesture-control-tv/

Oh nice!

Another idea I just had is (and this probably has already been done somewhere) would be to control pimusicbox using something like a piezo element over GPIO. You could then have same ipod like control that is offered by the ttsgpio extension only it would recognize knocks. So you could hide the entire player inside a bookshelf (for example) and control it by knocking on the shelf with different knock combos. :slight_smile:

Im doing this
It runs on nodejs and started it as a project for rune audio but itā€™s working on mopidy over raspbian. :slight_smile:
IT has button controls (that can only toggle play/pause at the moment) a voulme control and iā€™m trying to implement a display to browse local files.

Hi!
Is it possible use arduino digital outputs as buttons for the raspberry pi?
I want to connect an RFID/NFC reader to my arduino and use different NFC tags to play different playlists. It this possible using Mopidy-TTSGPIO?
Btw I have little experience in programming.

Uhm, there is already a project that used RFID via USB (i.e no arduino. Even if you didnā€™y use USB you probably donā€™t need arduino for this). The code is on github-

Thanks for the tip. I will look into it

hey i have a strange problemā€¦
i had tts-gpio working before but then i tred to enhanc emy setup and by ding that i broke my sd cardā€¦ so i had to re install everythingā€¦
im using tts-gpio to automatically turn on the power of my stereo whenever im playing a song (im using the play led for that).
how everā€¦ tts-gpio is listed as an active plugin and no errors are shown, i also get the tts announcements but the led is not glowing up when a song/radio is playingā€¦ and i dont have a nclue why that isā€¦ i also set the deamon user to rootā€¦
any ideas?

After almost one week of struggling to get my buttons of my walkman to work, i hope to get some help here.
Iā€™d like to control my pi musicbox with some buttons to shutdown the pi, play the next song or load a playlist or radio station.

I read the whole thread several times, but canā€™t get TtsGpio working. I even did a fresh install of my musicbox.

I installed festival, TtsGpio, edited the config, changed the daemon_user to root (also tried sudo mopidy), checked if the extension is enabled (it is!) but ā€¦ nope. no button works. EDIT: i donā€™t know, if it is important, but iā€™m also using LIRC to control mpd (used this tutorial http://stevespi.blogspot.de/)

I tried the gpio_input_tester script (also an updated one from another thread), which displayed an error:
root@MusicBox:~# sudo python /opt/musicbox/gpio_input_tester3.py
TTSGPIO: Not enough permission

If it helps: here a log from mopidy
http://pastebin.com/x14VZdkB
In line 39, there is:
ERROR Frontend (MpdFrontend) initialization error: MPD server startup failed: [Errno 98] Address already in use

Here a link to a part of my config file:
http://pastebin.com/L3Si7xJ9

Btw, iā€™m running Pi Musicbox V0.6 on an RPi3

Also, does anyone know, if there are alternatives to TtsGpio? I tried one script from this thread but it didnā€™t work for me.
Thanks!

I was tinkering for days with writing an extension for mopidy on pi musicbox, and this eventually was the solution.
So many hours for such a little thingā€¦

Hi, am relatively new to raspberry pi but would appreciate your help. I have successfully installed mopidy and music box is working. have also enabled music cards. have installed the files you listed to the highest branch on the SD card and added the content needed into the settings.ini file. Am running the pi via ssh. When i plug everything in however the buttons dont work unfortunately. While running through ssh, is there a way to check whether ttsgpio is an enabled extension?