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.
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.
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.
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.
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.
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…
Search the forum for that to get more info.
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.
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.
Welcome to the forum
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!
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…
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.
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
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 hope you may have a solution. Its so frustrating
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.