Alps rotary encoder

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Message
Author
User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Alps rotary encoder

#11 Post by Sling »

A question for Ralph or Corjan to answer is can the Arduino and Rpi encoder implementations handle the different quadrature detents per pulse combinations. This will depend on the way the encoder inputs are being read in software. It seems a lot of the encoder examples on the net assume 1 detent per pulse, but 2 per pulse is also common and I've got a grayhill one with 4 detents per pulse. Can we expect all of these variations to work on both the Arduino's and Rpi.

It's possible this is the reason why we have seen some struggles with encoders for some folk.

pierclav
Posts: 35
Joined: Sun Dec 11, 2016 11:57 am
Location: Bangkok

Re: Alps rotary encoder

#12 Post by pierclav »

Hi Sling,

I tried the code you posted.

Here is what I got in the console window
-----------------------------------------------

1st detent CW = INFO - The dial turned clockwise

1st detent CCW = INFO - The dial turned counterclockwise

2nd detent CW = INFO - The dial turned counterclockwise

2nd detent CCW = INFO - The dial turned clockwise

etc,

------------------------------------------------

The direction reversed with each detent (CW-CCW-CW-CCW, etc...) after the first detent.


I then tried some new Uno's I purchased today and it worked like a charm. You were right about the pull-up resistors. Not all boards are created equal. I went back to my original board and put in two 10K pull-up resistors. The encoder is now working fine with that board too.

There is still the issue of the Arduino installer not working with the Mega's but Uno's will do fine for this project. I posted about it in the Arduino forum.

Thank you for your help. You saved my RTU project.

Pierre

User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Alps rotary encoder

#13 Post by Sling »

Your most welcome. I'm glad it's now working.

Can you post the code you finally used. I'm interested to know if you needed frumpys method or if the wiki code worked. I plan to source encoders with the different detent/pulse combinations to experiment with this myself. I'll post something when I finally get round to doing this.

pierclav
Posts: 35
Joined: Sun Dec 11, 2016 11:57 am
Location: Bangkok

Re: Alps rotary encoder

#14 Post by pierclav »

Very much a work in progress but this is roughly what it will look like. I am still not sure if I will use soft keys or hardware switches for the different functions. I am using a 5.3 inch screen so there is no room for anything on the sides if it's going to fit into the radio bay. Switches and encoders will have to go below the screen. I will use 2 dual encoders for tuning
The attachment rtu_1.PNG is no longer available
Here is the encoder related code I have so far. Only COM1 and NAV1 are implemented at the moment. Next will be XPON, ADF, TCAS functions and the second set of radios.

--------------------------------------START

-- RADIO SELECT SWITCHES

radio=0 --encoder is disabled at startup

-- 1 = COM1
-- 2 = NAV1
-- 3 = XPON
-- 4 = ADF

function new_selectcom()

switch_set_state(switch_1, 1)
switch_set_state(switch_2, 0)
--switch_set_state(switch_3, 0)
--switch_set_state(switch_4, 0)
radio=1

end


function new_selectnav()

switch_set_state(switch_1, 0)
switch_set_state(switch_2, 1)
--switch_set_state(switch_3, 0)
--switch_set_state(switch_4, 0)
radio=2

end

-- WHOLE ENCODER

function dial_change(direction)

if direction == 1 and (radio==1)
then
fsx_event("COM_RADIO_WHOLE_INC")
elseif direction == 1 and (radio==2)
then
fsx_event("NAV1_RADIO_WHOLE_INC")
end

if direction == -1 and (radio==1)
then
fsx_event("COM_RADIO_WHOLE_DEC")
elseif direction == -1 and (radio==2)
then
fsx_event("NAV1_RADIO_WHOLE_DEC")
end

end


-- Bind to Arduino pin 11 (encoder A) and pin 10 (encoder B)
hw_dial_add("ARDUINO_UNO_B_D11", "ARDUINO_UNO_B_D10", dial_change)


-- FRACT ENCODER

function dial_change(direction)

if direction == 1 and (radio==1)
then
fsx_event("COM_RADIO_FRACT_INC")
elseif direction == 1 and (radio==2)
then
fsx_event("NAV1_RADIO_FRACT_INC")
end

if direction == -1 and (radio==1)
then
fsx_event("COM_RADIO_FRACT_DEC")
elseif direction == -1 and (radio==2)
then
fsx_event("NAV1_RADIO_FRACT_DEC")
end

end

-- Bind to Arduino pin 13 (encoder A) and pin 12 (encoder B)
hw_dial_add("ARDUINO_UNO_B_D13", "ARDUINO_UNO_B_D12", dial_change)

------------------------------END
Attachments
rtu_1.PNG

User avatar
Ralph
Posts: 7924
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Alps rotary encoder

#15 Post by Ralph »

Are you using original Arduino's or Chinese Arduino clones?

pierclav
Posts: 35
Joined: Sun Dec 11, 2016 11:57 am
Location: Bangkok

Re: Alps rotary encoder

#16 Post by pierclav »

Chinese Uno`s. They work fine with AM. Had no luck getting Chinese Mega's to work.

User avatar
Ralph
Posts: 7924
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Alps rotary encoder

#17 Post by Ralph »

We've only tested with genuine Arduino's. There's so many clones out there that it's impossible to test those. Should all work well with genuine Arduino's.

User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Alps rotary encoder

#18 Post by Sling »

Thanks Pierre,

So you are using the standard wiki method and all is good, albeit with additional pull-ups. That's good to know. Do you have the encoder part number handy?

A tip for next time. Try posting any code inside </> code tags as it makes it easier to read.

Thanks

Tony

pierclav
Posts: 35
Joined: Sun Dec 11, 2016 11:57 am
Location: Bangkok

Re: Alps rotary encoder

#19 Post by pierclav »

Tony,

Noted. Here is the link for the Alps encoders: http://www.alps.com/prod/info/E/HTML/En ... _list.html.

I am using the dual-shaft 30 detent/15 pulse version.

Ralph,

Import duties and taxes on genuine Arduino's are very high here in Thailand. The Chinese ones are so cheap I consider them a disposable product. Agree that it can be a hit and miss thing. Worst case some of them need pull-up resistors.

Regards,

Pierre

pierclav
Posts: 35
Joined: Sun Dec 11, 2016 11:57 am
Location: Bangkok

Re: Alps rotary encoder

#20 Post by pierclav »

This code also works with the CTS-288 encoders I use on my MCP (1 increment for every 2 detents). That was the only component I had to run on OC/SIOC. Now I can run my whole cockpit on Arduinos.

Post Reply