Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: Rotary Encoder doesn't work
#1
Hey guys! 

My Installation:
- Raspberry Pi 3
- Hifiberry Amp2
- Moode 7.0.1

I want to use a rotary encoder to control the volume. 

The hardware installation looks like this...
Com - 3.3V
Pin A - Gpio 14
Pin B - Gpio 15

In the Moode setup screen I active the Rotary Encoder option and  changed the last two numbers to  14 15.
But the Encoder doesn't work. 
With a small python script I tested if Pi recognized the states on the 2 Gpio ports. 
That works! But there's no volume change in Moode....

Has anybody a idea why it doesn't work? 

Thanks for your help!
Reply
#2
Couple things:
1. The rotary encoder driver defaults to GPIO 23, 24 and GND.
2,. Pins 14/15 might already be in use https://pinout.xyz/pinout/pin8_gpio14

If you want to get some debug info from the driver then you will need to first turn it off in Audio config then launch it from the command line as in the example below.

Code:
sudo rotenc 100 2 3 23 24 1

The launch params are documented in the systemd unit file.
/lib/systemd/system/rotenc.service
Code:
#
# 2019-09-05 TC moOde 6.2.0
#
#

[Unit]
Description=Moode Rotary Encoder Driver
After=sound.target

[Service]
# Useful commands
# ps -e -o class,rtprio,pri,nice,cmd
# ps H -q `pidof -s rotenc` -o 'pid,tid,cls,rtprio,comm'
# NOTE: the RTPRIO col applies to real-time scheduler policies, the NI (nice) and PRI columns are for non real-time policies

# for rotenc process
LimitRTPRIO=50
LimitRTTIME=infinity

# scheduling policy
# real-time
# - fifo, first in first out
# - rr, round robin
# static
# - other, the standard round-robin time-sharing (ts) policy
# - batch, for "batch" style execution of processes
# - idle, for running very low priority background jobs
CPUSchedulingPolicy=other

# scheduling priority
# 1 = lowest, 99 = highest)
CPUSchedulingPriority=42

# scheduling priority adjustment
# applies only to static scheduling policies
# 0 = default, -20 = highest, 19 = lowest
Nice=-10

# processor affinity bit mask
# - empty string = reset bit mask
# - cpu index list or dash seperated range
#CPUAffinity=0,1

# Launch params
# rotenc <poll_interval in ms> <accel_factor> <volume_step> <pin_a> <pin_b> <print_debug>
# rotenc 100 2 3 23 24 1 (with optional debug print)
# rotenc 100 2 3 23 24 (normal)
# poll_interval:    Number of ms delay for each iteration of the volume update loop. Default=100
# accel_factor:        Threshold (difference between last and current position of encoder) to determine whether to use 1 step or STEP steps. Default=2.
# volume_step:        Number of steps to use when knob turns at fast rate. Default=3.
# pin_a/b:            GPIO pin numbers. Defaults: rotenc_py (23,24 - Broadcom SoC), rotenc_c (4,5 wiringPi).
# print_debug:        Print debug information to console. 1=normal, 2=verbose (2 is for rotenc_c only). This is an optional param.
ExecStart=/usr/local/bin/rotenc 100 2 3 23 24

[Install]
WantedBy=multi-user.target
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Thanks Tim for your hints. 

The solution was very simple. I just changed the COM pin on the encoder from 3.3V to GND.
Now it works.

LG Thomas
Reply


Forum Jump: