I have a raspberry PI 3 (Raspbian) with HifiBerryDac+, running Mixxx.
I wanted to run a pythonscript (2.7) which would allow users to automatically restart Mixxx by pressing a button (in case they can't manage to get to some original settings). The code for the script can be found at the bottom of the post.
I'm using GPIO 4 to read the input of this button, so first set this as pull-up resistor. According to the HifiBerry spec's, this GPIO is not being used:
HIFIBERRY DAC+, DIGI+ AND AMP+ GPIO2-3 (pins 3 and 5) are used by our products for configuration. If you are experienced with I2C, you might add other slave devices. If you a a novice, we don’t recommend this at all. GPIOs 18-21 (pins 12, 35, 38 and 40) are used for the sound interface. You can’t use them for any other purpose.
However, when I'm trying to open Mixxx from the python script, I get the following error:
Mixxx was unable to open all the configured sound devices. 0, snd_rpi_hifiberry_dacplus: - (hw:0,0) is used by another application or not plugged in.
When I close the python script and run Mixxx, there is no issue or error.
This makes me believe there is an issue with Python reading GPIO's (or at least writing the pull-up for GPIO 4) and the pins HifiBerryDac+ is using.
I'm probably missing something here...
import RPi.GPIO as GPIO
import pygame
import time
import os
import subprocess
import logging
pygame.init()
ingedrukt = 0
resetinputpin = 4
logging.config.fileConfig("/home/pi/mixxxlog.conf")
logger = logging.getLogger("mixxxscript")
GPIO.setmode(GPIO.BCM)
GPIO.setup(resetinputpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print"PINs ingesteld"
# run mixxx
os.system("home/pi/Documents/mixxx/./mixxx &")
print "mixxx opgestart"
##### Functie om te checken of bepaald proces nog aan het runnen is
#proc -> name/id of the process
#id = 1 -> search for pid
#id = 0 -> search for name (default)
def process_exists(proc, id = 0):
ps = subprocess.Popen("ps -A", shell=True, stdout=subprocess.PIPE)
ps_pid = ps.pid
output = ps.stdout.read()
ps.stdout.close()
ps.wait()
for line in output.split("\n"):
if line != "" and line != None:
fields = line.split()
pid = fields[0]
pname = fields[3]
if(id == 0):
if(pname == proc):
return True
else:
if(pid == proc):
return True
return False
################################################################################################"
print "loop begint"
while True:
if GPIO.input(resetinputpin) == 0:
print "indrukking toets eerste maal"
n = 0
while (n < 20):
print n
n = n + 1
if GPIO.input(resetinputpin)==0:
ingedrukt = ingedrukt +1
print "OK"
if GPIO.input(resetinputpin)==1:
ingedrukt = 0
print "doorheen de loop"
print ingedrukt
if ingedrukt >= 18:
print "nu toets ingedrukt"
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
screen.fill((0, 0, 0))
pygame.mouse.set_visible(False)
# stop mixxx
os.system("sudo pkill mixxx &")
print "mixxx wordt nu afgesloten"
time.sleep(10) #aantal seconden dat mixxx moet afsluiten
# check of mixxx al afgesloten is
for check in range(0,5):
print "check"
if process_exists("mixxx",0):
print "nog niet afgesloten"
time.sleep(10)
# indien niet afgesloten, doe een volledige reboot
if process_exists("mixxx",0):
print "reboot nodig"
logger.info("reboot")
# os.system("sudo reboot now")
# start mixxx opnieuw
print "restart mixxx"
pygame.mouse.set_visible(True)
pygame.display.quit()
os.system("/home/pi/Documents/mixxx/./mixxx &") #check path
# disable the screen fill
ingedrukt = 0
EDIT: it is really setting the internal pull-up causing this error; when I replace
GPIO.setup(resetinputpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
by
GPIO.setup(resetinputpin, GPIO.IN)
then mixxx does run correctly (but the script doesn't run correctly as I have a floating pin)
So probably I could bypass this issue by making my own external pull-up, but still, would like to understand first what causes the issue before doing so.
Pieter