Posts: 4
Threads: 1
Joined: Feb 2019
Reputation:
0
hello,
Thank you for this code lines!
I'm very intressed in this feature because I use to use Volumio with the HWbuttons plugin and I've discovered moode 5 beta. I want to moove to moode!
I'm trying to configure my Pi from your script, but I have a little problem:
- when I use "low" GPIO pin with 3.3v pins there is no reaction. do this script only works with high GPIO or is there a way to use the low ones and if it's possible what line must I modify?
I want to use a 3.5 tft screen and I only can use the 27 to 40 pins in order to plug the screen.
Thanks
Mothinos
Posts: 13,450
Threads: 305
Joined: Mar 2018
Reputation:
545
It would be easy enough to make a config screen for this.
Is this the complete source code for the feature?
Code: #!/usr/bin/python
#coding: utf8
#script for moode audio GPIO buttons
#on playlist names no spaces
#import
import RPi.GPIO as GPIO
import sys
import time
import datetime
import os
import subprocess
# Set GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the GPIO pins to be used
SW_PREV = 10
SW_NEXT = 11
SW_POWEROFF = 9
SW_PLAY = 12
SW_VOLUP = 20
SW_VOLDOWN = 26
SW_PL1 = 16
SW_PL2 = 13
# Adjust to the button characteristics if necessary
PRELL = 1000
# Code to manage buttons
GPIO.setup(SW_PREV,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_NEXT,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_POWEROFF,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PLAY,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_VOLUP,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_VOLDOWN,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PL1,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PL2,GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Event procedures
def eSW_PREV(channel):
subprocess.call(['mpc', 'prev' ])
print str(datetime.datetime.now())[:19] + " previous"
def eSW_NEXT(channel):
subprocess.call(['mpc', 'next' ])
print str(datetime.datetime.now())[:19] + " next"
def eSW_POWEROFF(channel):
subprocess.call(['mpc', 'stop' ])
subprocess.call(['sudo', 'poweroff' ])
print str(datetime.datetime.now())[:19] + " shutting down"
def eSW_PLAY(channel):
subprocess.call(['mpc', 'toggle' ])
print str(datetime.datetime.now())[:19] + " play"
def eSW_VOLUP(channel):
subprocess.call(['/var/www/vol.sh', 'up 1' ])
print str(datetime.datetime.now())[:19] + " volup"
def eSW_VOLDOWN(channel):
subprocess.call(['/var/www/vol.sh', 'dn 1' ])
print str(datetime.datetime.now())[:19] + " voldown"
def eSW_PL1(channel):
subprocess.call(['mpc', 'load playlist1' ])
print str(datetime.datetime.now())[:19] + " playlist 1"
def eSW_PL2(channel):
subprocess.call(['mpc', 'load playlist2' ])
print str(datetime.datetime.now())[:19] + " playlist 2"
# Event declarations
GPIO.add_event_detect(SW_PREV, GPIO.RISING, callback = eSW_PREV, bouncetime = PRELL)
GPIO.add_event_detect(SW_NEXT, GPIO.RISING, callback = eSW_NEXT, bouncetime = PRELL)
GPIO.add_event_detect(SW_POWEROFF, GPIO.RISING, callback = eSW_POWEROFF, bouncetime = PRELL)
GPIO.add_event_detect(SW_PLAY, GPIO.RISING, callback = eSW_PLAY, bouncetime = PRELL)
GPIO.add_event_detect(SW_VOLUP, GPIO.RISING, callback = eSW_VOLUP, bouncetime = PRELL)
GPIO.add_event_detect(SW_VOLDOWN, GPIO.RISING, callback = eSW_VOLDOWN, bouncetime = PRELL)
GPIO.add_event_detect(SW_PL1, GPIO.RISING, callback = eSW_PL1, bouncetime = PRELL)
GPIO.add_event_detect(SW_PL2, GPIO.RISING, callback = eSW_PL2, bouncetime = PRELL)
# Actual program sequence
while True:
time.sleep(1)
The config screen would list the 8 events along with fields for GPIO pin number, Enable/Disable, and Playlist name for the two playlist options. Config would prolly be stored in a simple .conf file.
-Tim
Posts: 111
Threads: 12
Joined: Apr 2018
Reputation:
14
(03-25-2019, 01:20 PM)mothinos Wrote: hello,
Thank you for this code lines!
I'm very intressed in this feature because I use to use Volumio with the HWbuttons plugin and I've discovered moode 5 beta. I want to moove to moode!
I'm trying to configure my Pi from your script, but I have a little problem:
- when I use "low" GPIO pin with 3.3v pins there is no reaction. do this script only works with high GPIO or is there a way to use the low ones and if it's possible what line must I modify?
I want to use a 3.5 tft screen and I only can use the 27 to 40 pins in order to plug the screen.
Thanks
Mothinos Hi,
May be Kent a.k.a. theoldpresbyope can answer that question. He is the one who helped with the script. I am sure he will read this and try to help.
Remy
Posts: 6,030
Threads: 177
Joined: Apr 2018
Reputation:
235
(03-25-2019, 01:20 PM)mothinos Wrote: ...
I'm trying to configure my Pi from your script, but I have a little problem:
- when I use "low" GPIO pin with 3.3v pins there is no reaction. do this script only works with high GPIO or is there a way to use the low ones and if it's possible what line must I modify?
...
Hi, @ mothinos
First, let's make sure I understand your question.
When interfacing to the GPIO, "low" and "high" usually refer to the state of the pin, with low being 0V and high 3V3, e.g., "low" and "high" refer to the voltage on the pin.
Is this what you mean or are you referring to the GPIO pin number itself?
Regards,
Kent
Posts: 13,450
Threads: 305
Joined: Mar 2018
Reputation:
545
Try @ Cyanoazimin script from post #9 :-)
Posts: 13,450
Threads: 305
Joined: Mar 2018
Reputation:
545
Hi,
Here is screenie of new GPIO Config feature :-) The underlying code can be easily extended to support other actions. This interfaces with a modified version of @Cyanoazimin's nice script from post #9.
I'll need some volunteers to test this out because I'm w/o any hardware that has GPIO controlled buttons.
-Tim
Posts: 1,538
Threads: 106
Joined: Mar 2018
Reputation:
73
(03-26-2019, 10:53 PM)Tim Curtis Wrote: Hi,
Here is screenie of new GPIO Config feature :-) The underlying code can be easily extended to support other actions. This interfaces with a modified version of @Cyanoazimin's nice script from post #9.
I'll need some volunteers to test this out because I'm w/o any hardware that has GPIO controlled buttons.
-Tim
Tim, from the 1st post...
Quote:On the hardware side, you set your hardware button to connect the ground pin of your RPi with a GPIO pin of your choice.
So you should be able to strip the ends of a couple of dupont cables, connect the plug ends to ground and selected pin then briefly touch the bare ends together.
Happy to test it here...
----------
bob
Posts: 6
Threads: 0
Joined: Mar 2019
Reputation:
0
03-27-2019, 06:13 AM
(This post was last modified: 03-27-2019, 06:16 AM by cyoops.)
(03-26-2019, 10:53 PM)Tim Curtis Wrote: Hi,
Here is screenie of new GPIO Config feature :-) The underlying code can be easily extended to support other actions. This interfaces with a modified version of @Cyanoazimin's nice script from post #9.
I'll need some volunteers to test this out because I'm w/o any hardware that has GPIO controlled buttons.
-Tim
Cool, that's great, but I think I think Random, Single, Power off/on are much more useful than playlist, especially the powerbutton.
Moode with buttons and pydPiper, that's a perfect local player.
Posts: 111
Threads: 12
Joined: Apr 2018
Reputation:
14
(03-26-2019, 11:41 PM)DRONE7 Wrote: Quote:On the hardware side, you set your hardware button to connect the ground pin of your RPi with a GPIO pin of your choice.
So you should be able to strip the ends of a couple of dupont cables, connect the plug ends to ground and selected pin then briefly touch the bare ends together.
Happy to test it here...
Hi. As explained here it actually depends on the "default pull status" of the GPIO: if the default pull status is low, you connect the gpio to the 3.3 volts pin (never connect with the 5 volts pin). If the default status is high, you connect to the ground.
Remy
Posts: 1,538
Threads: 106
Joined: Mar 2018
Reputation:
73
Thanks for that Remy... that's much clearer !
----------
bob
|