Jump to content

Need Rotary Encoder Help for Joystick Library


Enabler

Recommended Posts

I have been converting my Viper pit over from DCS-BIOS inputs to USB-HID. This allows me to bind all inputs as a "joystick" button or axis. The advantage over Bios is the ability to bind the switches in DCS directly for all aircraft rather than one specific one. 

Reprograming my Viper EHSI, I'm having a problem coding for the 2 rotary encoders. I have tried numerous different codes specific to encoders but have not had any luck. While the DCS-BIOS code works perfectly, I am still planning to convert to USB-HID with the Joystick library.

The code I have had some success with is simple and the encoders turn the course and heading bugs. However, they require many rotations for few changes in game. The questions I need answers to are: (I am using Arduino Due, but code for Micro and Leonardo are the same.)

1. Can I add code to this to simply change the rotation ratios of the encoder pins?

2. Is there a way to extract the actual code for Course and Heading from within the DCS-BIOS library to enter this manually? (Not referring to the code snippets.)

2. Do I need more specific code for the encoder to function?

3. Can someone help me with the code I need to add?

This sketch includes other buttons in the array for various nearby panels and switches. The pins for the encoders A+B are 55/66 and 58/54.

Thanks for your help!

Screenshot 2023-05-03 154121.png

HID_Ejection_EHSI_Fuel_Qty_Sel_Due_0x14_Ver2.ino

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

Link to comment
Share on other sites

You need specific code to properly compare the states of the rotary encoder inputs to determine which button to "press".
Rotary encoder example:
https://github.com/jssting/ButtonBox

I don't think you can extract the bug data from the F-16, or any other aircraft that has an electronic HSI because there's no "physical gauge".
DCS uses display driver code for that, rather than model animation, which is what DCS-BIOS picks up on with gauge position code.

Link to comment
Share on other sites

Hi I used the code from the jssting site and it works fine.  I did notice that the input from the encoder is not very precise though, ie one click on the rotary encoder may or may not generate the keystroke and sometimes it generates the opposite direction keystroke or both!.  I mapped the encoder to the kneeboard next page and previous page keystrokes in DCS.  Most of the time it goes to the next page if i turn it right,  but sometimes it goes back to previous page.  It is mostly workable but like I said, not particularly precise.   

Is this just how rotary encoders are? or is it the code, or is it my cheap aliexpress rotary encoders causing that issue?   

For my other encoder i use it to turn the nvgs on and the gain up and down,  it works really well for that application cause it does not need to be that precise.

 

Win11 64bit, AMD Ryzen 58003DX, GeForce 3070 8GB, 2TB SSD, 64GB DDR4 RAM at 3200MHz _ full 1:1 FA-18C Cockpit https://www.youtube.com/@TheHornetProject

Link to comment
Share on other sites

Disclaimer: I have no rotaries to try this out.

Looking at that cote on GitHub, I thing there may be a better way to handle rotary interrupts. The author seems to trigger the same interrupt functions for any change. Arduino supports interrupts for specific pin value changes  (high->low; low->high). It strikes me that this can be used a lot more effectively with rotaries than pure guesswork.

I will eventually get some to play with, but update here if this nudged you in the right direction.

Link to comment
Share on other sites

6 hours ago, Sting57 said:

Is this just how rotary encoders are? or is it the code, or is it my cheap aliexpress rotary encoders causing that issue?

i can assure you, this is not how good encoders work, definitely not in airplanes: 1 'bump' equals exactly 1 input in fine mode (slow turning), and they (mostly) work in two modes, coarse and fine, otherwise it would take forever to dial in a specific value.

i had similar issues as those you mention, which i would describe as spikes, with my old goflight gear, and was able to mostly resolve those using contact spray.

Link to comment
Share on other sites

On 5/3/2023 at 9:53 PM, Enabler said:

The advantage over Bios is the ability to bind the switches in DCS directly for all aircraft rather than one specific one.

i am not sure i understand. you have to bind the switches once for each aircraft anyway, either in dcs or in bios, right?

(just curious, not using dcs bios yet, obviously 😄)

Link to comment
Share on other sites

4 hours ago, HILOK said:

i am not sure i understand. you have to bind the switches once for each aircraft anyway, either in dcs or in bios, right?

(just curious, not using dcs bios yet, obviously 😄)

In DCS-BIOS, the code is (mostly) specific to just one aircraft module, meaning trying to run more than one module from the same encoder could cause conflicts in the way the arduino reads the encoder.

If you go the HID (e.g. joystick) route, you only have one output, and there's no problems in the Arduino code if you add a module. You just add the binds in DCS

Link to comment
Share on other sites

1 hour ago, No1sonuk said:

In DCS-BIOS, the code is (mostly) specific to just one aircraft module, meaning trying to run more than one module from the same encoder could cause conflicts in the way the arduino reads the encoder.

If you go the HID (e.g. joystick) route, you only have one output, and there's no problems in the Arduino code if you add a module. You just add the binds in DCS

ok, and can you load a separate profile for each a/c into the arduino/dcs-bios ?

Link to comment
Share on other sites

10 hours ago, HILOK said:

ok, and can you load a separate profile for each a/c into the arduino/dcs-bios ?

For some things, you don't need to.
For simple switches, you can just us the same pin number in a different code line.
e.g.

DcsBios::Switch2Pos ufcMasterCaution("UFC_MASTER_CAUTION", 2); // A-10 Master Caution Reset

DcsBios::Switch2Pos masterCaution("MASTER_CAUTION", 2); // F-16 Master Caution Reset

DcsBios::Switch2Pos masterCautionResetSw("MASTER_CAUTION_RESET_SW", 2); // FA-18 Master Caution Reset

This uses a button on pin 2, and would send all three "...MASTER_CAUTION..." messages to DCS, but DCS will only respond to the one for the aircraft you're using.  If more than one aircraft uses the same message, then you don't need to add another code line.

I've not tried doing that with a rotary encoder.

The advantage of the HID approach is that if you get another aircraft, you don't have to recode the Arduino, you just edit the control bindings in DCS.

Link to comment
Share on other sites

On 5/5/2023 at 8:23 PM, No1sonuk said:

For some things, you don't need to.
For simple switches, you can just us the same pin number in a different code line.
e.g.

DcsBios::Switch2Pos ufcMasterCaution("UFC_MASTER_CAUTION", 2); // A-10 Master Caution Reset

DcsBios::Switch2Pos masterCaution("MASTER_CAUTION", 2); // F-16 Master Caution Reset

DcsBios::Switch2Pos masterCautionResetSw("MASTER_CAUTION_RESET_SW", 2); // FA-18 Master Caution Reset

This uses a button on pin 2, and would send all three "...MASTER_CAUTION..." messages to DCS, but DCS will only respond to the one for the aircraft you're using.  If more than one aircraft uses the same message, then you don't need to add another code line.

I've not tried doing that with a rotary encoder.

The advantage of the HID approach is that if you get another aircraft, you don't have to recode the Arduino, you just edit the control bindings in DCS.

If I continue to have this issue with generating a viable USB-HID code, then that would be a decent interim solution. I use this board to run my EHSI buttons, encoders, Ejection controls and Fuel Qty Sel panels. They all worked great with a Mega and DCS-BIOS. All the buttons work great as USB-HID on a Due board, but I just can't get the encoders to replicate their proper function as does DCS-BIOS.

Do you think I can combine the Joystick (not Serial) and DCS-BIOS libraries (Serial) in one sketch (Arduino Due) so I can run all buttons/switches as USB-HID and the encoder functions as DCS-BIOS? 

My latest pit update is here and I'm due for another soon. GD ViperWorks - YouTube


Edited by Enabler

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

Link to comment
Share on other sites

1 hour ago, Enabler said:

Do you think I can combine the Joystick (not Serial) and DCS-BIOS libraries (Serial) in one sketch (Arduino Due) so I can run all buttons/switches as USB-HID and the encoder functions as DCS-BIOS? 

Try it.
I know some form of DCS-BIOS / HID hybrid works:

 

Link to comment
Share on other sites

1 hour ago, No1sonuk said:

Try it.
I know some form of DCS-BIOS / HID hybrid works:

 

This is awesome. But I am running into one problem. I think there is a conflict in DCS. Attached is my combined code. It is my switch code for my seat controls, EHSI and Fuel Qty Sel. It works perfectly as USB-HID before adding the DCS-BIOS snipets. 

After adding DCS-BIOS to it, it compiles fine. I test the buttons with Windows USB Game Controller setup. The buttons all work perfectly. The board is connected and ready for DCS to run.

I load DCS, and from the main screen go to controls, and bind the push buttons. No problem. they show as expected as Joy1, Joy2, etc. 

At this point all indications are that I expect this to work. I go to instant action, F-16, ready on the ramp. Test the buttons. Nothing. Turn the encoders, nothing.

I return to the desktop, reopen Game Controllers, and all the buttons still show but will no longer activate. 

Any ideas? Did you experience that at all? Or does your combined code only work with LEDs?

This is running on a Due.

Screenshot 2023-05-07 140242.png


Edited by Enabler

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

Link to comment
Share on other sites

You don't have " DcsBios::setup(); " in your void setup function.  That would stop the DCS-BIOS working.  I'm not sure if that would crash the whole thing, but try changing that first.

Also, on Line 52, I think the " == LOW " on the end is constantly keeping the result low and not allowing it to change.


Edited by No1sonuk
Link to comment
Share on other sites

Two things to try:
1) Make sure the DCS-BIOS connection is using the correct com port - IIRC, hybrids somethines use a different COM port for HID and DCS-BIOS.

2) Try a new sketch with just one of the encoder lines in it to check that's working.

Link to comment
Share on other sites

I don't know if this would help, but I use these little boards with my rotary encoder,
https://gear-falcon.com/products/encoder-boards-with-dedicated-cpu


It converts the rotary pulses to simple button presses.

I use these all over my F-14 panels. For the course and heading, in the F-14 LUA there is 2 digital settings for those knobs, course and fine control, course movement allows for quick movement but not very accurate, fine moves slowly, I set up a control modifier that when I press the rotary button it switches between the 2 modes for each one.

 

F-14B, F-16, F-18C, A-10C, F-5E, F-86, FC3, BF-109, FW-190, P-51, Spitfire, UH-1,AJS-37 Viggen, MIG-15, MIG-19, MIG-21, AV-8B Harrier, P-47D

Persian Gulf, Caucuses, NTTR, Normandy, The Channel, Syria

Combined Arms, WWII Assets,Super Carrier

TM Warthog, Virpil VFX,BuddyFox UFC, Saitek Pro Flight quadrant & Switch Panel, Odyssey+ VR, Jet Pad w/ SSA, Voice Attack w/Viacom Pro

GeForce RTX2080TI OC, Intel Core i7-7700K 4.5Ghz, 64GB DDR4, Dedicated 1TB SSD

Link to comment
Share on other sites

21 hours ago, LASooner said:

I don't know if this would help, but I use these little boards with my rotary encoder,
https://gear-falcon.com/products/encoder-boards-with-dedicated-cpu


It converts the rotary pulses to simple button presses.

I use these all over my F-14 panels. For the course and heading, in the F-14 LUA there is 2 digital settings for those knobs, course and fine control, course movement allows for quick movement but not very accurate, fine moves slowly, I set up a control modifier that when I press the rotary button it switches between the 2 modes for each one.

 

If you're planning to use those on a Bodnar board, there may be no point.  The board may be able to be set up specifically for rotary encoders.  IIRC, there's an app that reprograms them to create up and down pulses from encoder inputs.

Link to comment
Share on other sites

On 5/7/2023 at 3:35 PM, No1sonuk said:

Two things to try:
1) Make sure the DCS-BIOS connection is using the correct com port - IIRC, hybrids somethines use a different COM port for HID and DCS-BIOS.

2) Try a new sketch with just one of the encoder lines in it to check that's working.

The Due has 2 ports. One for programming and another native. Indeed, they both recognize as different ports when plugged in. I did get a simple sketch with 1 button and one encoder to work as a hybrid through a Micro (only one comm connection). I will use the Due program technique to make a hybrid through the native port and see how it goes. I expect that should work.

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

Link to comment
Share on other sites

20 hours ago, No1sonuk said:

If you're planning to use those on a Bodnar board, there may be no point.  The board may be able to be set up specifically for rotary encoders.  IIRC, there's an app that reprograms them to create up and down pulses from encoder inputs.

I'm using arduinos

F-14B, F-16, F-18C, A-10C, F-5E, F-86, FC3, BF-109, FW-190, P-51, Spitfire, UH-1,AJS-37 Viggen, MIG-15, MIG-19, MIG-21, AV-8B Harrier, P-47D

Persian Gulf, Caucuses, NTTR, Normandy, The Channel, Syria

Combined Arms, WWII Assets,Super Carrier

TM Warthog, Virpil VFX,BuddyFox UFC, Saitek Pro Flight quadrant & Switch Panel, Odyssey+ VR, Jet Pad w/ SSA, Voice Attack w/Viacom Pro

GeForce RTX2080TI OC, Intel Core i7-7700K 4.5Ghz, 64GB DDR4, Dedicated 1TB SSD

Link to comment
Share on other sites

On 5/7/2023 at 3:35 PM, No1sonuk said:

Two things to try:
1) Make sure the DCS-BIOS connection is using the correct com port - IIRC, hybrids somethines use a different COM port for HID and DCS-BIOS.

2) Try a new sketch with just one of the encoder lines in it to check that's working.

@No1sonuk I just programmed a Micro as a hybrid and it works perfectly. Thanks so much. The Due did not work. I assume it's because of the 2 separate ports it uses to program and run the board. 

GD ViperWorks - YouTube

F-16CM Block 50 Replica Sim Pit Construction

Link to comment
Share on other sites

58 minutes ago, Enabler said:

@No1sonuk I just programmed a Micro as a hybrid and it works perfectly. Thanks so much. The Due did not work. I assume it's because of the 2 separate ports it uses to program and run the board. 

Dunno.  I do know I tried it on a Leonardo, which uses the 32u4, like the Pro Micro.   The Due uses a different processor.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...