Multiple Rotary encoders - help

This line

rotary = RotaryIRQ(14, 15, pull_up=True)

establishes an object with the name ‘rotary’ that you can reference in a line such as

new_val = rotary.value() # What is the encoder value right now?

in order to get the value. So if you have more devices you use the same code to create the other objects but with different names (rotary1, rotary2, perhaps) and the appropriate pin numbers for those other encoders. Then duplicate the code you are using to handle the value, substituting the correct object name, and using separate variables if you need to keep track of them simultaneously.

Whether or not the Pico needs to be a gamepad or joystick or some other USB device depends entirely on the application that you are interfacing it to - XPlane 11/12. Is there a user forum for that application?. If it’s accessible someone may be able to look at it for you and find the section that refers to interfacing external devices.

Meanwhile you can get the other encoders up and running and oputput the results to console to confirm that your code can retrieve and process each value.


Hi Jeff105671,
Thank you so much. I managed to work out the code for 2 encoders after my post, so now i know how to handle that part.

In relation to the xplane, when i set the pico up using Audrino IDE and had it as a joystick/game pad device, xplane just simply recognised it when i plugged it in. I am thinking that should also be the case using micropython. I just dont know which library to use and the code i need for the pico to become an extrenal usb device. I looked at the user manual fro the flight simulator and it just says " Note: X‑Plane can only interface with USB devices. This covers nearly all the controllers manufactured in the last ten years, but if you have a non-USB device, an adapter will be needed to change it to a USB input.

Does any of this help? Thank you again :slight_smile:

So there are two parts to that - the first is to set up the Pico Pi as a USB device. Then you need to find out exactly what is meant by “nearly all the controllers manufactured in the last ten years” because I suspect that is not quite so broad a range of devices as it implies, but in any case you still have to be specific about what USB device the Pico will be.

For instance, if the app supports a keyboard HID as a game controller then there is an example of a project here:
Custom USB games controllers with Raspberry Pi Pico

The Pico is configured as a keyboard HID. You will need to know the keyboard codes for each function that is supported. Code for the controller then converts user input (rotary encoders in your case) to key sequences.

1 Like

Hi Hubert
I have done just that. Only difference I have XPlane 10. I have used 10 encoders. 9 for Nav and DME tuning and 1 for elevator trim.

Each encoder button has to be filtered or switch bounce will scramble the whole thing and readings all over the place. So I cheated a bit and used a product designed and sold by Leo Bodnar of IK. I used 2 boards. The first has the encoder connections as part of a matrix but to display approximate elevator trim position I needed to connect a small Arduino in parallel with one of the inputs which the matrix would not allow. So I had to upgrade to a bigger Bodnar board which would allow this.

Google “Leo Bodnar” to get to his site for details. All debounce is taken care of within these boards.

These boards are plug and play and each encoder switch appears in XPlane so you can assign whatever function you like to them. These boards also have 8 analog inputs which appear as axes in Plane and once again can be assigned anything which requires analog input (pitch, Roll etc)

The Arduino is used purely to analyse the encoder inputs and drive the LEDs for elevator trim approximate position. The push button on that encoder is used to return the trim to default “take off” position.

Have a good read and if you have any questions feel free to ask. There are other recent posts on encoders on this forum. Search “rotary encoder” and see what comes up.
Cheers Bob


Hi Robert,

I have done exactly that lol, i have one of those Leo Bodnar boards on its way. I was hopin the pico board i have i can achieve the same thing - and learn something new…oh and not let it send me insane as i don’t tend to give up … ha ha ha…

1 Like

Hi Hubert
Sorry that link take you to the project. There is more info on the progression to the larger board on the forum posts here

Project by Robert; Potentiometer Position Monitor

Search the forum for that to get more info.
Cheers Bob
What Bodnar board are you getting??
EDIT. Sorry for confusing the issue. The link take you to the Forum post. The “Read more” link takes you to the project which outlines the initial story.

1 Like

this is the board i have ordered

thank you again, i will keep exploring…its a very steep learning curve :wink:

Nothing posted. No board.
Cheers Bob

BBI-32 Button Box Interface - With Connectors

Hi Hubert
Yes that should work nicely. You might have to download some configuration software. I used the BU0836A with the breakout matrix board and later changed to BU0836X which doesn’t have the buttons laid out in a matrix format. I am using some of the Analog inputs which the Button Box Interface does not have.
If you need the configuration software it is pretty self explanatory and easy to use, you are basically telling it that the buttons are Rotary Encoders or straight buttons. When I got it it was Windows only which was not a big deal as although I use a Mac I also have a (old) Windows laptop unit. I think from memory once loaded the software starts up as soon as you plug your board into the computer.

My boards seem to handle switch bounce very nicely so I imagine yours will too. They work very well and seamlessly integrate with XPlane.
Cheers Bob

1 Like

Hi Hubert,

Welcome to the forum :slight_smile:
I’ve just edited your first two messages slightly to fix the formatting on the code sections and make it a bit easier to read.

Sounds like Jeff and Bob have already got you sorted with some great advice on all the main points of your project in question. Best of luck with the flight sim controller build, please report back with some photos of the build so we know how it turns out!

1 Like

Awesome…i am still determined to get this damn pico board to be recognised as a USB device so that xplane can see it. I managed it using Arduino IDE but i just cant wrap my head around circuit python…it surely cant be that hard…

Hi Trent,

Thank you

Hi hubert

Interesting to do as a learning exercise but if you use the Bodnar board you won’t need to. The Bodnar board is recognised quite happily and all the connected buttons are there ready to be assigned.
Cheers Bob


Hi Trent,

I thought i would turn to you as i am really lost. I am not sure if i am even making sense in what i am looking for around my issue. I am determined to resolve this as i this Pico board using Arduino can do what i need. All i need is to know what code/library i need to use so that the Pico is seen as a USB device. I have a sample code which proves this to work in the simulator i am using and it does recognise it as a joystick/game controller. This is the link. When i run this, the sim recognises the pico as a joystick. All i need to do is remove everything in this code bar the encoders…i must be stupid…Pico RP2040 HID Joystick Library for Arduino IDE - YouTube

hope you or anyone else can help this stupid old man ha ha ha

1 Like

Hi Hubert,

Really sweet project! Keen to see it.
Though unfortunately micropython doesn’t have any HID support at the moment, so you’ll have to use the Arduino library in that link.

The only rotating bit in the tutorial is the potentiometer, adding some code to keep track of the encoders wont be too much of a stretch once you check out the tutorials below.

(Here’s a link to a couple guides on Encoders with the Arduino:

Using the position from each of the encoders you can keep track of and set one of the Joystick objects from the HID library:
void PicoGamepad::SetX(uint16_t val)

Other analog inputs for your controller:
// gamepad.SetZ(val);
// gamepad.SetRx(val);
// gamepad.SetRy(val);
// gamepad.SetRz(val);
// gamepad.SetS0(val);
// gamepad.SetS1(val);

If you hit any roadblocks with it let us know and we can help out! :slight_smile:


If you have the example working then you have already achieved this.

That example uses the library PicoGamepad

#include <PicoGamepad.h>
PicoGamepad gamepad;

Then, when you read the encoder value as in your first example (‘new_val’) you set the virtual joystick axis that you want to use to that value and send it to the device. Something like:

    . . .
    if (current_val != new_val) {    // The encoder value has changed!
    gamepad.SetX(new_val);       // Do something with the new value
    gamepad.send_update();        // Send that input via HID

Hi Robert,
So the Leobodner board turned up, i wired in 1 encoder, it works like you said…new problem…i assigned the encoder to HDG bug, set it to the lowest ms and as i turn the encoder, the bug moves soooo slowly, it takes over a minute, 30000000 turns (lol) to go anywhere…is there a way i can speed it up? it works, but its way too slow. Im using xplane 11 or 12… same issue :frowning: hope you may have a solution. Its so frustrating

Hi Hubert
It has been a little while since I fired up my XPlane but give me a couple of days to have a look. Unfortunately at the moment my Windows machine is not playing the game and unless Leo Bodnar has a Mac version of his configuration software I can’t even have a look at the settings I used. Forget what they are now. As far as I remember the bugs and tuning work fine

My encoders are as fools from the top.
Nav1 Bug, Tuning coarse , tuning fine
Nav 2 Ditto
NDB (I think) kHz X 100, X10, X1
Total 9 encoders.
The 10th one is Elevator trim, the encoder buttons replace the yolk buttons for nose up and down with the push button switch on the encoder set to return to “take off” position

You can play with some of the encoder settings in the config software, not sure what it all means at the moment but I will see if I can find what mine are. Give me a few days.
Cheers Bob