Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpio buttons #1

Closed
ole-seelenmeyer opened this issue Jun 8, 2017 · 41 comments
Closed

gpio buttons #1

ole-seelenmeyer opened this issue Jun 8, 2017 · 41 comments

Comments

@ole-seelenmeyer
Copy link

Hey there,
maybe you can help me out. what could be the best way to use gpio buttons for forward and rewind tracks using the gpio buttons. i read a lot about it but i am not able to do it right now. maybe you can give me a hint.

@hankman13
Copy link

hankman13 commented Jun 8, 2017 via email

@ole-seelenmeyer
Copy link
Author

its mostly a general question. how to control these jukeboxscript with gpio buttons. how to wireing the button is not the problem but how to implent it in the script. or write a second script and put it in the autostart by crontab?

@hankman13
Copy link

hankman13 commented Jun 8, 2017 via email

@MiczFlor
Copy link
Owner

MiczFlor commented Jun 8, 2017

The way this package works, using VLC, "next" and "previous" tracks are not an option. So the gpio buttons are not needed or doable.
There is another, similar project where the author is using XMMS instead of VLC. The "Howto" is in German, but auto translation might do the trick:

Kindgerechter Audioplayer mit dem Raspberry Pi , Part4

You can find links to other, similar projects inside the README file under Acknowledgments

I will eventually close this "issue" because it's not really an issue. But will leave it open for now, because it looks like it will be helpful for others.

@ole-seelenmeyer
Copy link
Author

ok i just see the Jukebox project at adventures in raspberry pi that also uses vlc controlled by gpio buttons but without rfid support. my intention was to connect both projects. to have the rfid trigger to start a audiobook and have some buttons to skip trough the chapters or adjust volume. its hard for a python newby to understand.
thanx a lot.

@hankman13
Copy link

hankman13 commented Jun 8, 2017 via email

@ole-seelenmeyer
Copy link
Author

ole-seelenmeyer commented Jun 8, 2017 via email

@Alwiz79
Copy link

Alwiz79 commented Aug 17, 2017

Hi Ole, have you somehow come to point to combine these projects?
There are a lot jukebox projects out there. But they are all a bit different.
This is by far the best documented project. Anyhow, I'd also to combine the RFID tags with button controls for volume and next/previous track. I simply don't know how.

as far as I understand the code a starting point could be the chapter "Register your USB device for the jukebox". The RFID reader is registered here. If it was possible to register also the GPIO Buttons, this could be a way forward, right ?

@tullm
Copy link

tullm commented Oct 7, 2017

hi.
Just built a prototype for my daughter thanks to your work and great instructions.

I also wanted to control vlc with next or pause and so on. Today I found a working solution.

Some little tweaking to the trigger script is needed.

First you need the definition of the command you want. Mapped to a RFID key on my side:
CMDPAUSE="000123456"

Then you need to add this to the other commands:
elif [ "$CARDID" == "$CMDPAUSE" ]
then
# pause VLC media player
echo "pause" | nc.openbsd -w 1 localhost 4212

Then you need to edit the cvlc call on the end of the script:
(cvlc -I rc --rc-host localhost:4212 $PATHDATA/../playlists/$FOLDERNAME.m3u &)

So it starts vlc with the rc interface on localhost with port 4212. So vlc listens on this port for rc commands. The command we set (pause in my example) echoes pause per nc over the rc interface on the localhost port 4212 and quits after 1.

So we can use all other commands to control vlc.

Maybe that helps with the buttons too?!

Maybe so it is possible to add the standard functions to the Webinterface?!

Maybe also a check it the RFID used is already at play an do nothing?

Also it would be better if only musik files will be added to the playlist. Great would be the possibility to jump to a specific track in the playlist ?!

Thank you very much for your work an I hope this info might be useful for somebody..

Cheers

Tullm

@MiczFlor
Copy link
Owner

MiczFlor commented Oct 9, 2017

@tullm thanks for the hint. This is what I was looking for. Included it in the script:
45616b8
I have not much time at the moment, but will also look into the other things you listed, like adding it to the web interface.

What do you mean with "Also it would be better if only musik files will be added to the playlist."?

All the best, micz

@tullm
Copy link

tullm commented Oct 9, 2017

No problem. You're welcome.

What I mean Ist that there are all files from a folder are put into playlist and are shown in the folder info in the Webinterface. For example are there folder.jpg in my folders. These are also in the playlist.
So I think it would be better to filter for audio files only to put them into the playlist.

Hope that cleared things up.

Cheers

@Geliras
Copy link

Geliras commented Nov 16, 2017

@MiczFlor @tullm
Is it possible to use buttons now?

@tullm
Copy link

tullm commented Nov 17, 2017

Yes, should work as long as you can link them to the card in the script. I#m not aware of how to script this right.

@Geliras
Copy link

Geliras commented Nov 17, 2017

Thank you. I will start buying this weekend and then we will see. If I get it working (I think so), I will write it here.

@MiczFlor
Copy link
Owner

@tullm @Geliras I have not made any changes that would support the GPIO buttons. It would be great if you give this a try and report back. Many people contact me about this feature and - after all - this is on github, so it is open to suggestions, forks and different branches.
What I am working is a version where the RPI serves as a wifi access point. That way, the installation could be easier because rather than connecting the RPi to the local Wifi network, it will its own SSID that devices can connect to.

@Geliras
Copy link

Geliras commented Nov 17, 2017

Controls are working with RFID, so it cannot be that hard to trigger the same command when pressing a button. Right? I never used own buttons on RPi yet.

@MiczFlor
Copy link
Owner

MiczFlor commented Nov 17, 2017

Skipping to the next and previous track on VLC you can see in the bash script
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/scripts/rfid_trigger_play.sh.sample
on line 109:
echo "next" | nc.openbsd -w 1 localhost 4212
and line 113:
echo "prev" | nc.openbsd -w 1 localhost 4212

The volume change is done with the command line in the bash script. So the command to trigger with volume buttons should be something like this:
Volume up: amixer sset 'PCM' 5%+
Volume down: amixer sset 'PCM' 5%-

Good luck and please report back :)

@Geliras
Copy link

Geliras commented Nov 22, 2017

Have not recieved my buttons yet, so i cant try. But wouldn't it be possible to just send one this commands when pressing a button:

echo "play" | nc.openbsd -w 1 localhost 4212
echo "pause" | nc.openbsd -w 1 localhost 4212
echo "next" | nc.openbsd -w 1 localhost 4212
echo "prev" | nc.openbsd -w 1 localhost 4212

We could just edit one of these (2nd one is more detailed):

https://raspberrypi.stackexchange.com/a/13214

https://webcache.googleusercontent.com/search?q=cache:nKcEN5uWTqUJ:https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b+&cd=1&hl=de&ct=clnk&gl=de

@MiczFlor
Copy link
Owner

MiczFlor commented Dec 4, 2017

Hi everybody, I just got a mail that somebody has the Jukebox working with the buttons. Here is the thread in German (sorry, will try to incorporate a "howto" in English soon).

Let me know if this is of any help:
https://forum-raspberrypi.de/forum/thread/13144-projekt-jukebox4kids-jukebox-fuer-kinder/?postID=312257#post312257

I added the code here:
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/misc/GPIO-button-sample.py

@stefansiegl
Copy link

Hi @MiczFlor, this is a tremendously well-documented and easy to setup project. Thanks man, had this running in no time on my raspberry. What a good job.

Regarding the buttons I really think that this would improve this project even more. Having a similar documentation on how to attach the buttons, resistors, ... would just be perfect (especially for somebody like me with little to none practical tinkering experience) ;)

@jackwidu
Copy link

Sorry, if I capture this topic. It seemed inappropiate for me to open a new topic for such a small problem:
I cannot change the volume over the GPIO Buttons. No problem skipping or pausing. I also switched the assigned buttons, so I'm sure the buttons are working.
When in SSH "amixer sset Speaker 20%+" will do what it is suppose to do, and in the
gpio-buttons.py it is:
"def def_volU():
check_call("amixer sset Speaker 20%+", shell=True)"
(Speaker is my USB-Soundcard)

There is a thing I suspect, as I did something not according to the GPIO-buttons.md manual:
in the "/etc/rc.local" I had to add "python " before "/home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py &"
because otherwise the buttons wouldn't work at all.
Any hints or ideas?
Thanks, Jackwidu

@manolllo
Copy link

manolllo commented Apr 16, 2018

@jackwidu I had the same issue that the Volume GPIO buttons were not doing anything. My solution to the problem was the following: Instead of using PCM 1.5db+/- I used Speaker 3+ and 3-

I think the change to Speaker is only needed if you use USB Audio which I am using.

After that everything worked like a charm.

def def_volU():
check_call("amixer sset Speaker 3+", shell=True)

def def_volD():
check_call("amixer sset Speaker 3-", shell=True)

@jackwidu
Copy link

Trank you, but it won‘t work either. It‘s the same: in SSH amixer sset Speaker 3+ will do its job, but Not in gpio-buttons.py. I very much think, ist has something to do with the way I call it in rc.local
Any idea on that?
Thanks a lot!

@MiczFlor
Copy link
Owner

Hi @jackwidu
This might help to unify your code (webapp, cards, gpio buttons):
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/scripts/playout_controls.sh.sample
I added this in the latest release and you can set the variable for sset in line 35.
Then from PHP, Bash or Python, calling this script should do the same action across all ways of interacting with the box.
You can see it in action already in the webapp:
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/htdocs/index.php
and the bash script:
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/scripts/rfid_trigger_play.sh.sample

If you can test it and update the code for the GPIO buttons:
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/misc/GPIO-button-sample.py
and test if it works, that would be awesome.

All the best, micz

@jackwidu
Copy link

Well..
BEFORE: GPIO were working, except for the volume controll.
the webinterface was working, including volume control, except for starting a folder manually (no reaction at all).
AFTER: GPIO buttons are working, except for the volume controll.
webinterface, neither volume nor starting a folder manually works. But Pause button works after starting via nfc card.
after changing rfid_trigger_play.sh , htdocs/index.php, and rfid_trigger_play.sh creating (changing PCM to Speaker, setting chmod +x)
in ssh this works: ./playout_controls.sh -c=setvolume -v=80
gpio-buttons-sample.py is changed to
def def_volU():
check_call("./playout_controls.sh -c=setvolume -v=80", shell=True)

if I call python gpio-buttons-sample.py I can change volume via the gpio-buttons.

Any ideas? I am not even sure, if this stil is my personal error and your change works perfectly for others.

Jakob

@MiczFlor
Copy link
Owner

Hi @jackwidu

I read your post a few times and am not quite sure what works and what doesn't work now :)

> after changing rfid_trigger_play.sh , htdocs/index.php, 
> and rfid_trigger_play.sh creating (changing PCM to Speaker, setting chmod +x)

This is of course necessary. And for a fresh install it is documented in CONFIGURE.md.
You say that it works on the command line, like ./playout_controls.sh -c=setvolume -v=80
but does it also work for the web interface? If not, have you made sure the settings for the webapp are correct?

sudo chown -R pi:www-data /home/pi/RPi-Jukebox-RFID/shared
sudo chmod -R 775 /home/pi/RPi-Jukebox-RFID/shared

From the sound of your mail, it seems that you have been updating your system rather than installed from scratch. And you are right, there were a couple of changes that might affect the system.

Please tell me in short, after your changes: what does not work?

thanks

@jackwidu
Copy link

Sorry, that my description remained unclear.
It's true, for the reason that 95% work perfectly I did an update and not a clear installation.
Things that are not working now (also after setting chmod as proposed by you):
Volumecontroll via GPIO after starting a file via nfc-card (play/pause, next Button work). Same in the webinterface. In the webinterface I also cannot start any file, I can only use the function play, pause, next track, reboot, reload, shutdown and "last Chip ID".
Interestingly, if I call the GPIO file directly in SSH with "python /home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py" I CAN controll the volume of a playing file via the buttons (though not the play-pause-Button which otherwise works!?). Therefore I think, it might have to something with the way, this file is called in the /etc/rc.local. There it is: "python /home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py&" (next and last line "exit 0").
That doesn't make any sense to me :-(

Thank you so much!

@MiczFlor
Copy link
Owner

It looks to me as if the GPIO script is not running after boot. Why that would be the case, I don't know. And I still don't have a GPIO control running myself. Right now I am working on an update for stretch and will also set up a GPIO Pi for testing.

What I would do: reinstall from scratch.

To make this easier, you can take a look at the helperscripts to create a backup of the shortcuts installed on your machine:
https://github.com/MiczFlor/RPi-Jukebox-RFID/tree/master/scripts/helperscripts

@jackwidu
Copy link

The GPIO Script is working, as the other buttons (play/pause, next track) do their job nicely, but I think you're right and I should do a reinstall. Thanks for your effort!

@jackwidu
Copy link

Hey MiczFlor,
it took me some time but now I did a clean reinstall. To get the MRFC522 working I used https://github.com/keinkurt/RPi-Jukebox-RFID/tree/MFRC255
It's all the same. The GPIO Buttons are working, except for the volume. If I call python gpio-buttons.py directly during playing a file it'll be the other way around: I can controll the volume, but no play/pause next track.
And with the webinterface I also cannot change the volume (but play/pause). And calling any folder to pla won't work. I also tried using a RFID card for volume up and down but that doesn't work either.
Is there a way to grap any occuring error after a script is automatically called on startup?
Thanx, Jakob

MiczFlor pushed a commit that referenced this issue May 7, 2020
Merge latest changes form MiczFlor
MiczFlor pushed a commit that referenced this issue May 23, 2020
Groovylein added a commit that referenced this issue Dec 26, 2021
pabera added a commit that referenced this issue Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

12 participants