BlueWave Studio forum
how to get rotary encoders to work - Printable Version

+- BlueWave Studio forum (https://bluewavestudio.io/community)
+-- Forum: OpenAuto Pro (https://bluewavestudio.io/community/forum-86.html)
+--- Forum: General (https://bluewavestudio.io/community/forum-81.html)
+--- Thread: how to get rotary encoders to work (/thread-2356.html)



how to get rotary encoders to work - enuos92 - 01-21-2021

Hi,

I must prefix this with, I'm a total noob at this Linux and terminal stuff. 

I only got OAP and my pi a few weeks ago, and I have been tinkering with it every day.

So far I have got an auto shutdown script , auto brightness script, backup camera and wireless AA all to work. All thanks to the great info on this forum.

BUT, I can not get my rotary encoder to work. I know that they are supported in V12 of OAP. I would like to use the encoder as a volume knob and the switch as mute. I have tried to follow the instructions on this page https://bluewavestudio.io/community/showthread.php?tid=2208&pid=12582#pid12582 but I can't seem to get it to work.

I'm using OAP version 12 on a raspi 3b+ the rotary encoder is a  KY-040

the encoder is connected to the GPIO as so

sib/clk GPIO 24
sia/dt  GPIO 25
sw      GPIO 12
+        to 3.3v
gn       ground



Also when I ssh into the pi and type  DISPLAY=:0 controller_service /home/pi/.openauto/config/openauto_controller_service.ini     I get this

[2021-01-21 22:34:27.484367] [0x76f51040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 25

[2021-01-21 22:34:27.585038] [0x76f51040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 24
[2021-01-21 22:34:27.685735] [0x76f51040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 12
[2021-01-21 22:34:27.736188] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 0/10
[2021-01-21 22:34:27.786497] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 1/10
[2021-01-21 22:34:27.846253] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 2/10
[2021-01-21 22:34:27.896531] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 3/10
[2021-01-21 22:34:27.946823] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 4/10
[2021-01-21 22:34:27.997884] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 5/10
[2021-01-21 22:34:28.048172] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 6/10
[2021-01-21 22:34:28.098465] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 7/10
[2021-01-21 22:34:28.148760] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 8/10
[2021-01-21 22:34:28.199055] [0x76f51040] [error]  [OpenAuto] [GpioPin] Unable to set direction, pin: 12, attempts: 9/10
[2021-01-21 22:34:28.199151] [0x76f51040] [error]  [OpenAuto] [GpioPinsFactory] set direction failed, pin: 12
Segmentation fault


I think I'm going wrong in the terminal bit. I don't really understand the instructions given on the thread linked above. 

If some could help that would be amazing. Step by step instructions on how to get controller service to work would be great. 
 
I'm also happy to start from a fresh install if all these error codes means I have done something wrong.


RE: how to get rotary encoders to work - BlueWave - 01-22-2021

Hello,
Looks like something is wrong with GPIO12 (PIN32). Please try to change it to e.g. GPIO 26 (PIN 37) and post the result.


RE: how to get rotary encoders to work - enuos92 - 01-22-2021

(01-22-2021, 07:02 AM)BlueWave Wrote: Hello,
Looks like something is wrong with GPIO12 (PIN32). Please try to change it to e.g. GPIO 26 (PIN 37) and post the result.

Hi Blue wave,

Thanks for the reply. Happy to report we have progress. I change pin 12 to 26 on the board and the code. This is what I get now.

pi@raspberrypi:~ $ DISPLAY=:0 controller_service /home/pi/.openauto/config/openauto_controller_service.ini
[2021-01-22 15:31:48.279280] [0x76f32040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 25
[2021-01-22 15:31:48.384674] [0x76f32040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 24
[2021-01-22 15:31:48.485703] [0x76f32040] [debug]  [OpenAuto] [GpioPinsFactory] allocating pin: 26
[2021-01-22 15:31:48.588434] [0x76f32040] [info]    [OpenAuto] [Controller Service] running...
[2021-01-22 15:31:48.588612] [0x76f32040] [debug]  [OpenAuto] [RotaryEncoderControllerService] start.

But still no volume control when I turn the rotary encoder or pause when I press it.

this is what i have pasted in to .openauto/config/openauto_controller_service.ini

[controller]
Type=5

[RotaryEncoder]
SiaPinNumber=25
SibPinNumber=24
SwPinNumber=26
LeftKeyStrokes=F7
RightKeyStrokes=F8
SwitchKeyStrokes=Ctrl+F11

and this is what I have in /etc/xdg/lxsession/LXDE-pi/autostart

lxpanel --profile LXDE-pi

@pcmanfm --desktop --profile LXDE-pi

@xscreensaver -no-splash

point-rpi

xset s off

xset s noblank

xset -dpms

/usr/local/bin/openauto

/usr/local/bin/controller_service_watchdog.sh

/usr/local/bin/relaymonitor.py
/home/pi/.openauto/config/openauto_controller_service.ini

Is there anything i have got wrong ?


RE: how to get rotary encoders to work - BlueWave - 01-22-2021

It looks good. Does the volume control work when you use e.g. slider at OpenAuto Pro interface? Do you see any notification on OpenAuto Pro interface that volume has changed? What sound card do you use?


RE: how to get rotary encoders to work - enuos92 - 01-23-2021

(01-22-2021, 08:16 PM)BlueWave Wrote: It looks good. Does the volume control work when you use e.g. slider at OpenAuto Pro interface? Do you see any notification on OpenAuto Pro interface that volume has changed? What sound card do you use?

yes when using the slider on touchscreen in OAP it dose change the volume and the slider moves. 

one odd thing I noticed is on the desktop when I click on the sound icon in the top right it says no volume control on this device. Not sure if that is normal.

the soundcard I'm using is  https://www.amazon.co.uk/gp/product/B01M7QQQC7/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1 

I got it because of the RCA output as that is how I'm going to hook up the pi to the amp in the car.

is there a certain sound card you recommend ?


RE: how to get rotary encoders to work - BlueWave - 01-23-2021

Could you please take some photos how the rotary encoder is connected to your Raspberry PI? Is there any possibility to test your setup with another Raspberry PI to rule out hardware damage (issue with broken GPIO 12 is quite confusing). We use the KY40 rotary encoder in one of our reference setup without any issues.


RE: how to get rotary encoders to work - enuos92 - 01-23-2021

(01-23-2021, 12:05 AM)enuos92 Wrote:
(01-22-2021, 08:16 PM)BlueWave Wrote: It looks good. Does the volume control work when you use e.g. slider at OpenAuto Pro interface? Do you see any notification on OpenAuto Pro interface that volume has changed? What sound card do you use?

yes when using the slider on touchscreen in OAP it dose change the volume and the slider moves. 

one odd thing I noticed is on the desktop when I click on the sound icon in the top right it says no volume control on this device. Not sure if that is normal.

the soundcard I'm using is  https://www.amazon.co.uk/gp/product/B01M7QQQC7/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1 

I got it because of the RCA output as that is how I'm going to hook up the pi to the amp in the car.

is there a certain sound card you recommend ?


Update:

I got it working !!!!!!!!!!!!!!!!!!!

I was reading another thread on rotary encoders and someone made the mistake of putting the + to the wrong voltage.

That is exactly what I had done. Took a look at the paper work I got with my encoder it said + to 5v not 3.3v

the volume goes up and down but the mute is very dodgy is keeps muting and unmuting. I also think I have some bad connections between the encoder and the gpio pins so this might be the cause. I will take a look at the connections tomorrow and report back.

thanks for all the help


RE: how to get rotary encoders to work - BlueWave - 01-23-2021

Thank you for your feedback. Please be very careful because shortening 5V to the 3V3 may (but not always) damage your Raspberry PI. All GPIO pins are powered by the 3V3 line. If you connected 5V line to the encoder's positive pin it could have some damaging impact on GPIO lines. Please try to connect SW pin of your rotary encoder to another GPIO pin and check if that improves the case.