1

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

  • by the way, does not change if I use another GPIO number (e.g. 26, 6,...); getting the same error. – pieterdp Jan 22 '18 at 12:54
  • Are you only using GPIO4 in the above script? – joan Jan 22 '18 at 16:51
  • yes, I am, no other GPIOs (and also no other programs running that use GPIOs) – pieterdp Jan 22 '18 at 18:13
  • Very odd that setting an internal pull-up can cause a problem. That does not make any sense. – joan Jan 22 '18 at 18:42
  • most likely, the hat is using generic software to read / write to the GPIOs, thus setting others pins than the ones really used by the hat. Solved it by using an external pull-up. – pieterdp Jan 25 '18 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.