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

Headphone jack detection does not work #9

Open
michnixweiss opened this issue Apr 22, 2020 · 3 comments
Open

Headphone jack detection does not work #9

michnixweiss opened this issue Apr 22, 2020 · 3 comments

Comments

@michnixweiss
Copy link

I'm using the WM8960 HAT on a Raspi zero using raspbian buster. I've installed the driver like described in the wiki. Everything is working (sound on speaker, on headphone, adjustable with alsa).
BUT when the headphone jack is plugged, it doesn't mute the speaker.
In the datasheet on page 45 the jack detection is mentioned, but I don't have enough knowledge to unterstand how that has to be done. Is it a hardware switch or a software switch? If hardware I think mine is broken, if software does that have to be implemented in the driver, in alsa or done by a script which listens to a gpio?
Thanks a lot

@michnixweiss
Copy link
Author

michnixweiss commented Jan 21, 2021

Only a workaround with a little soldering (a photo is in the thread linked above) and a script. I can post details if you want.

@Bastler80
Copy link

I really would like to have the script. is it possible for you to post it?

@michnixweiss
Copy link
Author

Sorry for late reply.
I created a JackDetect.py with following content:

#!/usr/bin/python

import RPi.GPIO as GPIO

from signal import pause

import subprocess

 

 

# GPIO initialisieren

GPIO.setmode(GPIO.BCM)

GPIO.setup(26, GPIO.IN)

 

# internen Pullup-Widerstand aktivieren.

GPIO.setup(26, GPIO.IN, pull_up_down = GPIO.PUD_UP)

 

# Callback-Funktion fuer beide Flanken

def measure(channel):

if GPIO.input(26) == 0: # fallende Flanke, Startzeit speichern

bashCMD = "sudo amixer -c 0 sset Speaker,0 0"

output = subprocess.check_output(['bash','-c', bashCMD])

else: # steigende Flanke, Endezeit speichern

bashCMD = "sudo amixer -c 0 sset Speaker,0 122"

output = subprocess.check_output(['bash','-c', bashCMD])

 

# Interrupt fuer beide Flanken aktivieren

GPIO.add_event_detect(26, GPIO.BOTH, callback=measure, bouncetime=300)

 

pause()


This should be started as daemon after boot. I did it with a JackDetect.service

[Unit]

Description=Headphone Jack Detection Service

After=network.target iptables.service firewalld.service

 

[Service]

User=pi

Group=pi

Restart=always

WorkingDirectory=/home/pi/RPi-Jukebox-RFID

ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/JackDetect.py

 

[Install]

WantedBy=multi-user.target

 

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

2 participants