Hallo Micz,
ich würde gerne einen Drehgeber für die Lautstärke Einstellung verwenden. Das finde ich intuitiver.
Ich habe dazu Skripte geschrieben und bei mir funktioniert es soweit. Wäre schön, wenn Du das in das Projekt aufnehmen könntest, damit es bei der Installation gleich eingerichtet wird (analog wie GPIO Buttons).
Leider weiß ich nicht, wie ich das in Git hochladen kann.
Grüße,
Patman
Beispiel für einen Drehgeber. Diesen habe ich verwendet.
https://www.amazon.de/dp/B079H3C98M/ref=psdc_1626220031_t1_B00HSWXR9Y
Hi @patman13
this is a great addition. Can you post me a few lines here regarding the necessary steps to activate it? From what I can see it will involve
Hello Micz,
to be honest I copied from your GPIO button script.
1) soldering: circuit diagram is contained in "rotary-encoder.py"
2) scripts "ky040.py" and "rotary-encoder.py" are placed in the same folder then GPIO button script
3) install systemd service (I copied from your GPIO service)
4) access rights I followed your GPIO example: $ sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
5) volume step size is personal preference
So, nothing new for you. ;-)
circuit diagram
(capacitors are optionally)
.---------------. .---------------.
| | | |
| CLK |------o---------------| GPIO 5 |
| | | | |
| DT |------)----o----------| GPIO 6 |
| | | | | |
| SW |------)----)----------| GPIO 13 |
| | | | | |
| + |------)----)----------| 5V |
| | | | | |
| GND |------)----)----------| GND |
| | | | | |
'---------------' | | '---------------'
KY-040 | | Raspberry
| |
--- ---
100nF --- --- 100nF
| |
| |
| |
=== ===
GND GND
Hi great Idea!
Thanks a lot. I thought I finally got it, but I can't get it to work.
The mute button press works, but not the rotary part, I think I don't get
"3. install systemd service" right.
Noob problem :-(
With sudo nano I created a rotary-encoder.service.sample in the "sampleconfigs" folder with the rotary-encoder.service.txt code in it, like I did it for the "ky040.py" and "rotary-encoder.py" scripts.
$ sudo nano /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/rotary-encoder.service.sample
then I was able do use:
$ sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/rotary-encoder.service.sample /etc/systemd/system/rotary-encoder.service
then I went on with
$ sudo systemctl daemon-reload
$ sudo systemctl enable rotary-encoder
That's what I did.
Or could it be a problem not to use the capacitors?
And why do you use the 5V? In the descritpion they write, for raspi use the 3,3V does it make any difference? or damage anything?
Hope you could help me!
ciao
If I leave the capacitators out, I also don't need to connect GPIO 5&6 to the Ground ?
I tried this and a lot else, still not working.
Any Idea for:
- install systemd service (I copied from your GPIO service)
systemctl status rotary-encoder
tells me
● rotary-encoder.service - Rotary Encoder Service
Loaded: loaded (/etc/systemd/system/rotary-encoder.service; enabled; vendor p
Active: failed (Result: exit-code) since Sun 2018-10-28 20:20:38 CET; 7min ag
Process: 1287 ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py (c
Main PID: 1287 (code=exited, status=1/FAILURE)
Oct 28 20:20:37 raspberrypi systemd[1]: rotary-encoder.service: Failed with resu
Oct 28 20:20:38 raspberrypi systemd[1]: rotary-encoder.service: Service hold-off
Oct 28 20:20:38 raspberrypi systemd[1]: Stopped Rotary Encoder Service.
Oct 28 20:20:38 raspberrypi systemd[1]: rotary-encoder.service: Start request re
Oct 28 20:20:38 raspberrypi systemd[1]: Failed to start Rotary Encoder Service.
Oct 28 20:20:38 raspberrypi systemd[1]: rotary-encoder.service: Unit entered fai
Oct 28 20:20:38 raspberrypi systemd[1]: rotary-encoder.service: Failed with resu
Just want to leave feedback:
Works perfectly with the mentioned rotary encoder from Amazon.
No soldering needed as female-female jumper wires fit on the pins exactly.
Only had to switch vol+ and vol- as it was getting louder if i turn left and other way round. Checked the wires and had everything connected as discribed above.
Just want to leave feedback:
Works perfectly with the mentioned rotary encoder from Amazon.
No soldering needed as female-female jumper wires fit on the pins exactly.
Only had to switch vol+ and vol- as it was getting louder if i turn left and other way round. Checked the wires and had everything connected as discribed above.
Do you use the 5V or the 3.3V pin?
How did you install systemd service ?
Thank you!
Used 5V Pin on Raspberry Pi. Connected everything without Capacitors.
Installed script following way:
sudo nano /etc/systemd/system/rotary-encoder.service
pasted the content of "rotary-encoder.service.txt", saved the file and rebooted.
Enabled service with
sudo systemctl enable rotary-encoder.service
Rebooted again. Thats it.
You write (capacitors are optionally). What are the advantages if you use them?
Works perfectly without capacitors! Thank you very much - Great Work!
My problem was that, opening the txt files with notepad++ copy there and paste into putty, some "space" and "enter" commands were lost. I had to look a little closer to realize this.
now it works great!
I would like to change the "mute" button to "20% Volume", because the children press it accidentally.
I changed the line:
def switchPressed(dummy):
check_call("./scripts/playout_controls.sh -c=mute", shell=True)
to
def switchPressed(dummy):
check_call("./scripts/playout_controls.sh -c=setvolume -v=20", shell=True)
but it does not work. What does the (dummy) mean? I deleted it, but It does not help.
Does somebody have an idea?
I noticed that if the knob is turned quite fast - it does react relative slow - is that the reason capasitors are applied?
I noticed that if the knob is turned quite fast - it does react relative slow - is that the reason capasitors are applied?
Same here.
@patman13 can you tell us the reason for the capacitors?
The effect of reacting bad to fast rotation of the knob results from the debouncing mechanism.
The are some parameters in the KY040 code which you can play on.
arg_rotaryBouncetime and arg_switchBouncetime
I did not pass them to the constructor (__init__) so the default values are used.
You can modify the values by either editing the default values or pass the value via the constructor.
Hi,
kann mir bitte jemand Schritt für Schritt erklären, wie ich den KY-040 einbinde?
Ich verzweifle :-(
Danke und schöne Grüße
Malte
● rotary-encoder.service - Rotary Encoder Service
Loaded: loaded (/etc/systemd/system/rotary-encoder.service; bad; vendor prese
Active: failed (Result: exit-code) since Wed 2018-11-07 17:17:56 CET; 15min a
Process: 469 ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py (co
Main PID: 469 (code=exited, status=203/EXEC)
Nov 07 17:17:55 raspberrypi systemd[1]: rotary-encoder.service: Unit entered fai
Nov 07 17:17:55 raspberrypi systemd[1]: rotary-encoder.service: Failed with resu
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Service hold-off
Nov 07 17:17:56 raspberrypi systemd[1]: Stopped Rotary Encoder Service.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Start request re
Nov 07 17:17:56 raspberrypi systemd[1]: Failed to start Rotary Encoder Service.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Unit entered fai
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Failed with resu
Warning: rotary-encoder.service changed on disk. Run 'systemctl daemon-reload' t
lines 1-15/15 (END)...skipping...
● rotary-encoder.service - Rotary Encoder Service
Loaded: loaded (/etc/systemd/system/rotary-encoder.service; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-11-07 17:17:56 CET; 15min ago
Process: 469 ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py (code=exited, status=203/EXEC)
Main PID: 469 (code=exited, status=203/EXEC)
Nov 07 17:17:55 raspberrypi systemd[1]: rotary-encoder.service: Unit entered failed state.
Nov 07 17:17:55 raspberrypi systemd[1]: rotary-encoder.service: Failed with result 'exit-code'.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Service hold-off time over, scheduling restart.
Nov 07 17:17:56 raspberrypi systemd[1]: Stopped Rotary Encoder Service.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Start request repeated too quickly.
Nov 07 17:17:56 raspberrypi systemd[1]: Failed to start Rotary Encoder Service.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Unit entered failed state.
Nov 07 17:17:56 raspberrypi systemd[1]: rotary-encoder.service: Failed with result 'exit-code'.
Warning: rotary-encoder.service changed on disk. Run 'systemctl daemon-reload' to reload units.
I updated to the newest Version. After I put sudo systemctl enable rotary-encoder.service the encoder works, but the other buttons are disabled. When I put sudo systemctl disable rotary-encoder.service the other buttons work again but not the encoder. Has anyone an Idea?
@MTam86 after you downloaded the newest Version the files ky040.py
rotary-encoder.py are already in the project folder. So you only have to put in following lines
sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
Then the installation of the Script like Andco7 described:
installed script following way:
sudo nano /etc/systemd/system/rotary-encoder.service
pasted the content of "rotary-encoder.service.txt", saved the file and rebooted.
Enabled service with
sudo systemctl enable rotary-encoder.service
Rebooted again. Thats it.
But note that with the newest version the Encoder works that way, but the buttons get disabled
This is the error Code.
When I first start the GPIO Buttons and then the rotary encoder I get the same thing the other way around
pi@raspberrypi:~ $ service phoniebox-gpio-buttons status
● phoniebox-gpio-buttons.service - Phoniebox GPIO Buttons Service
Loaded: loaded (/etc/systemd/system/phoniebox-gpio-buttons.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-11-10 13:33:30 CET; 1min 14s ago
Process: 1401 ExecStart=/home/pi/RPi-Jukebox-RFID/scripts/gpio-buttons.py (code=exited, status=1/FAILURE)
Main PID: 1401 (code=exited, status=1/FAILURE)
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Unit entered failed state.
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Failed with result 'exit-code'.
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Service hold-off time over, scheduling
Nov 10 13:33:30 raspberrypi systemd[1]: Stopped Phoniebox GPIO Buttons Service.
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Start request repeated too quickly.
Nov 10 13:33:30 raspberrypi systemd[1]: Failed to start Phoniebox GPIO Buttons Service.
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Unit entered failed state.
Nov 10 13:33:30 raspberrypi systemd[1]: phoniebox-gpio-buttons.service: Failed with result 'exit-code'.
Okay after some time trying different ways following solution worked for me.
Download the newest Version of Jukebox
the put in the following lines from: https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/Audio-RotaryKnobVolume
sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/phoniebox-rotary-encoder.service.stretch-default.sample /etc/systemd/system/phoniebox-rotary-encoder.service
sudo chown root:root /etc/systemd/system/phoniebox-rotary-encoder.service
sudo chmod 644 /etc/systemd/system/phoniebox-rotary-encoder.service
sudo systemctl enable phoniebox-rotary-encoder
sudo reboot
after that I still had to do
sudo chmod +x /home/pi/RPi-Jukebox-RFID/scripts/rotary-encoder.py
sudo reboot (maybe this can be added to the master ?!)
Since the GPIO Script uses the same buttons as the rotary encoder you have to comment out some things in the GPIO Script:
explained here : https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/325
from gpiozero import Button
from signal import pause
from subprocess import check_call
def def_shutdown():
check_call("./scripts/playout_controls.sh -c=shutdown", shell=True)
def def_volU():
check_call("./scripts/playout_controls.sh -c=volumeup", shell=True)
def def_volD():
check_call("./scripts/playout_controls.sh -c=volumedown", shell=True)
def def_vol0():
check_call("./scripts/playout_controls.sh -c=mute", shell=True)
def def_next():
check_call("./scripts/playout_controls.sh -c=playernext", shell=True)
def def_prev():
check_call("./scripts/playout_controls.sh -c=playerprev", shell=True)
def def_halt():
check_call("./scripts/playout_controls.sh -c=playerpause", shell=True)
shut = Button(3, hold_time=2)
next = Button(26,pull_up=True)
prev = Button(20,pull_up=True)
halt = Button(21,pull_up=True)
shut.when_held = def_shutdown
next.when_pressed = def_next
prev.when_pressed = def_prev
halt.when_pressed = def_halt
pause()
So now they work together for me - only the mute function when pressing the rotary encoder does not work.
So, I even got the mute function to work: you have to remove the dummy within the rotary-encoder.py - so change
def switchPressed(dummy):
check_call("./scripts/playout_controls.sh -c=mute", shell=True)
to
def switchPressed():
check_call("./scripts/playout_controls.sh -c=mute", shell=True)
and it works.
Ronny
The above script works fine but I wonder why it says 5V although the GPIO pins (on my Raspi3) are only 3.3V max?
I connected my rotary to only 3.3V and it seems to work just fine. Maybe you could add a corresponding comment to the script?
Good Morning all.
First of all, I would like to thank you for the scripts of the jukebox and the rotary knob.
The jukebox works perfectly.
I use with success the script rotary-encoder.py for louder, quieter and mute.
To my question:
I would like to shut down and reboot via the rotary knob. So I just need this one rotary knob in my project.
I hope someone can help me as I'm newbie in raspberry stuff and programming.
I searched a lot of forums but without success.
Have a good time.
I added a second encoder for tracks and tried to resolve the systemd issue.
Maybe we can still discuss a better option that hard coded py scripts for the assignment of the GPIOs. (although (https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/325) was closed recently. I would vote for a config file. Any other suggestions?
The above script works fine but I wonder why it says 5V although the GPIO pins (on my Raspi3) are only 3.3V max?
I connected my rotary to only 3.3V and it seems to work just fine. Maybe you could add a corresponding comment to the script?
3.3V is the better solution, 5V is only acceptable. I changed that in the documentation.
The effect of reacting bad to fast rotation of the knob results from the debouncing mechanism.
The are some parameters in the KY040 code which you can play on.
arg_rotaryBouncetime and arg_switchBouncetime
I did not pass them to the constructor (init) so the default values are used.
You can modify the values by either editing the default values or pass the value via the constructor.
One solution could be to use the rotary-volume module by JamesGKent (https://github.com/JamesGKent/rotary_volume). I use it to implement a volume up, volume down and a button-press functionality.
Cheers,
Henning
Interesting solution! We have in dev now a new rotary encoder code with a state machine, that does not need any debouncing, so that issue should be solved already.
I think I referenced the wrong reply. My solution has the advantage that it does not lag or react slowly if you turn the knob fast.
I noticed that if the knob is turned quite fast - it does react relative slow - is that the reason capasitors are applied?
Was that also solved? At least I experienced this issue when using "normal" python scripts for the rotation-direction-calculation.
The state machine does not need debouncing, which may cause a loss of steps. The state machine also take care of illegal states due to bouncing that confuses the often found "sample-data-on-clk-change" approach.
I drilled into the original kernel source - both approaches are equal.
In the newer python code I implemented kind of acceleration, that increases the volume step size as you turn faster. This also helps with usability.
Thanks for this script. It works perfectly! One minor comment/proposal. On my side I changed the down/up to have volume up when clockwise and volume down on anticlockwise. It seems more "standard" for me?
I just changed in rotary-encoder.py
def rotaryChangeCWVol(steps):
check_call("./scripts/playout_controls.sh -c=volumedown -v="+str(steps), shell=True)
def rotaryChangeCCWVol(steps):
check_call("./scripts/playout_controls.sh -c=volumeup -v="+str(steps), shell=True)
I just switched the connection to GPIO 5 / 6 for that :)
It can maybe be changed in code (not necessarily my "dirty" change) to make a clean version and avoid mistakes? @MiczFlor
@dvalob sure cw should be up and ccw down! If that is not the case, I would recommend to change the wiring to A and B of your encoder. Thereby you have no custom code and can take the latest code directly for production. In case that is not feasible, you can change line 62 and 63 like @Yordan1976 did.
Line 51 and 54 should stay unchanged.
yes you are right. Or we can change the A/B definition in the encoder-rotary python code for the same reason (keep production code)?
APinVol = 5 -> 6
BPinVol = 6 -> 5
??
Why don't you want to swap the A and B wires?
Are you absolutely sure that the A of your encoder is connected to GPIO 5 and B to GPIO 6? Does your track encoder (if you have one) also turn in the wrong direction?
My wiring is as follows:
In the original code we have:


So my code is coherent with th original code.
With these A/B defintion the volume is inverted. It is not a problem to swap the wires, but to avoid everybody to do it we could just swap A/B definition in the rotary-encoder.py. Or indicate in wiki article hat the wires need to be exchanged if we want to have "standard" sens for volume.
Just a detail I agree :)
Daniel
We shouldn't change the code in a way that would affect the already wired encoders. Editing the documentation and/or adding a setting for switching the definition would be the better way.
we could simply update this image in the rotaty-encoder.py (put GPIO 5 on DT and GPIO 6 on CLK).

Hardware pinouts entries in wiki does not specify the encoder pins for GPIO 5/6, so no need to update them.
I checked available hardware while the own is asleep and indeed I mixed A and B up as you suggested. I fixed (because it was already there in one place) and extended the wiki.
I made a double swap in the software to get the naming right and fixed the commend as suggested. Tested on my hardware. Pull request #509 is issued.
may I highjack this thread?
I'm wondering on how I can deactivate the mute function of the switch button. I did some testouts and found, that the kids press the button by fault too often. I would like to comment it out until they have more experience with the box.
I can't find the 'mute' function in the rotary-encoder.py do I miss anything? I though I have seen it there once a time, but not sure.
You can simply unplug the SW wire, isn't it?
Le 10 mars 2019 13:49, "domu83" notifications@github.com a écrit :
may I highjack this thread?
I'm wondering on how I can deactivate the mute function of the switch
button. I did some testouts and found, that the kids press the button by
fault too often. I would like to comment it out until they have more
experience with the box.
I can't find the 'mute' function in the rotary-encoder.py do I miss
anything? I though I have seen it there once a time, but not sure.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/267#issuecomment-471285031,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AtbkCOMSePAS7G6-LKkusepyKbaANyp3ks5vVP9jgaJpZM4XsppL
.
@domu83 since I refactored all the encoder code, all buttons are handled in the gpio-buttons.py
thanks @martinclausen2 !
is it possible to use the Rotary incl. Mute and the OLED Display (descriped here https://github.com/splitti/oled_phoniebox)? The problem is that the Display use the I2C Bus GPIO2 and 3, the Rotary uses also the GPIO3.
Hi,
I am having this problem:
Jan 31 21:03:13 raspberrypi systemd[1]: phoniebox-rotary-encoder.service: Start request repeated too quickly.
Jan 31 21:03:13 raspberrypi systemd[1]: phoniebox-rotary-encoder.service: Failed with result 'exit-code'.
Jan 31 21:03:13 raspberrypi systemd[1]: Failed to start Phoniebox Rotary Encoder Service.
Then I tried starting: rotary-encoder.py
result:
Traceback (most recent call last):
File "./rotary-encoder.py", line 44, in
from rotary_encoder_base import RotaryEncoder as enc
File "/home/pi/RPi-Jukebox-RFID/scripts/rotary_encoder_base.py", line 23, in
class Flags(ctypes.Union):
AttributeError: type object 'Flags_bits' has no attribute '_fields_'
Anybody having this problem? What could be the solution?
could you paste the content of /etc/systemd/system/phoniebox-rotary-encoder.service?
solved. I looked into rotary_encoder_base.py
In line 13 there was mising a _ before fields
before fields_ = [
after _fields_ = [
I didnt touch this file before, interesting...
Now it works.
circuit diagram
Mir ist bewusst, dass das für jeden, der sich einigermaßen mit Elektrotechnik auskennt eine unfassbar unbedarfte Frage sein muss, aber: wie ist der Schaltplan zu lesen?
Ich nehme an, ) bedeutet, dass die vertikale Lötung die die horizontale Lötung nicht berührt?
Was bedeutet aber das Symbol o ? Einen Widerstand? Wenn ja, welche Ohmzahl?
Was haben die beiden Massen unten für eine Bedeutung? Zu was sind sie verbunden?? Bzw.: Kann ich alles was zu den Kondensatoren hinführt im Grunde ignorieren? Oder gar alle vertikalen Verbindungen?
Anders gefragt, hat jemand ein Photo von dieser Schaltung?
Oder wieder anders gefragt: Kann mich jemand freundlicherweise auf eine verständliche Erklärung solcher Schaltpläne verweisen?
Ganz herzlichen Dank!
Hallo SKHSKHilber
Es gibt keine Dummen Fragen, nur Dumme....
Keine Panik, es ist keine Schande sich mit manchen Sachen nicht auszukennen.
Also die o in dem Plan sollen Verbindungspunkte darstellen, das bedeutet CLK wir mit GPIO5 und dem 100nF Kondensator verbunden und DT mit GPIO6 und dem anderen Kondensator, die andere Seite der Kondensatoren wird dann auf den GND Anschluss gelegt.
Ganz herzlichen Dank für die Info!
Hello, first of all my english is not the best, but I hope you get what I want/mean.
I want to ask about the current state. To be more precise:
I've added a rotary and it works, but the installing was different to the wiki and I still habe some questions:
Maybe I'm overlooking things!?
Thanks a lot for answers:-)
last weekend i installed the OnOff Shim for usage with a powerbank.
the powerbank wouldn't go into standby as long as the rotary encoder was connected to a 3v3 pin.
when i disconnected rotary <>3v3 OnOff Shim worked as expected and powerbank went into standby.
surprisingly rotary still works without 3v3 ? (volUp / volDown inverted!)
so i'm wondering:
what for do i need 3v3 in this case?
what happens if i don't connect 3v3?
(i'm on develop branch)
hi,
thanks for the awesome project. Today I ran into a problem after updating to phoniebox 2.0: my rotary knob for volume is no longer working. When I run the install commands that I had used in the previous version, the file rotary-encoder.py appears to be missing from the expected location. Have the paths changed or should I integrate the rotary encoder in a different way under the 2.0 software?
greetings
Hi @jlarsch, @michnixweiss,
Yes, you are right. The new components/gpio_control covers the rotary encoder now in 2.0, but it’s not correctly integrated yet and also not really documented.
Please see #991.
If you experience problems, please open a new issue or follow #991.
This issue here is rather old and info might not be up to date.