Kenpilot Posted July 29, 2024 Posted July 29, 2024 (edited) I'm using a rotary encoder for my course knob, connected to an arduino mega and using DCS bios. When I turn the knob one "detent", it makes it turn the course about 5-10 degrees, instead of just 1 degree. I added a capacitor to the wiring but it didn't help at all. Any ideas on how to fix this? Maybe something needs to be added or adjusted in the arduino sketch or dcs bios sketch? Thanks! Edited July 29, 2024 by Kenpilot Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
crash test pilot Posted July 30, 2024 Posted July 30, 2024 The most usual type of rotary encoder sends 4 pulses per detent. You may want to try this: RotaryEncoder · DCSFlightpanels/dcs-bios-arduino-library Wiki · GitHub
Kenpilot Posted July 30, 2024 Author Posted July 30, 2024 19 minutes ago, crash test pilot said: The most usual type of rotary encoder sends 4 pulses per detent. You may want to try this: RotaryEncoder · DCSFlightpanels/dcs-bios-arduino-library Wiki · GitHub Thanks Crash Test Pilot. I read through all of that but I'm not sure what I was supposed to take from it. I don't know how to code, I only know how to copy and paste the coding from dcs bios and put the pin numbers in. These are the encoders I'm using: Taiss / 5Pcs KY-040 Rotary Encoder Module with 15×16.5 mm with Knobs Cap https://a.co/d/7Yo186v Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
crash test pilot Posted July 30, 2024 Posted July 30, 2024 The code for the HSI course knob should be: typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder; FourStepRotaryEncoder hsiCrsKnob("HSI_CRS_KNOB", "DEC", "INC", PIN1, PIN2);
Kenpilot Posted July 30, 2024 Author Posted July 30, 2024 36 minutes ago, crash test pilot said: The code for the HSI course knob should be: typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder; FourStepRotaryEncoder hsiCrsKnob("HSI_CRS_KNOB", "DEC", "INC", PIN1, PIN2); Awesome! Thanks so much!! I'll test it out tonight. Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
Kenpilot Posted July 30, 2024 Author Posted July 30, 2024 Unfortunately it didn't work. The knob doesn't move at all now. Does it matter if the knob is connected to the analog or digital pins on the arduino with this sketch? Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
No1sonuk Posted July 30, 2024 Posted July 30, 2024 14 hours ago, Kenpilot said: Unfortunately it didn't work. The knob doesn't move at all now. Does it matter if the knob is connected to the analog or digital pins on the arduino with this sketch? I think it'll need to be on digital pins so it can use the pull-ups.
Kenpilot Posted July 30, 2024 Author Posted July 30, 2024 4 hours ago, No1sonuk said: I think it'll need to be on digital pins so it can use the pull-ups. Copy that, I'll change them to digital inputs and see if that helps. Thanks!! Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
Kenpilot Posted July 31, 2024 Author Posted July 31, 2024 No luck. I put the original DCS Bios code back in my sketch and the knob is working again, but still has the same issue, multiple pulses per detent. I tried the code Crash Test Pilot suggested again and the knob doesn't work at all again. Here is my entire sketch I'm using with Crash Test Pilot's code. Am I inserting it wrong? Or does someone see something else that might be wrong with it? Thanks! /* Tell DCS-BIOS to use a serial connection and use interrupt-driven communication. The main program will be interrupted to prioritize processing incoming data. This should work on any Arduino that has an ATMega328 controller (Uno, Pro Mini, many others). */ #define DCSBIOS_IRQ_SERIAL #include "DcsBios.h" #include <Wire.h> DcsBios::LED canopyUnlocked(0x10da, 0x0004, 24); DcsBios::LED gunReady(0x1026, 0x8000, 40); DcsBios::LED markerBeacon(0x10da, 0x0002, 22); DcsBios::LED nosewheelSteering(0x10da, 0x0001, 38); typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder; FourStepRotaryEncoder hsiCrsKnob("HSI_CRS_KNOB", "DEC", "INC", 12, 13); DcsBios::RotaryEncoder hsiHdgKnob("HSI_HDG_KNOB", "-3200", "+3200", A0, A1); DcsBios::RotaryEncoder adiPitchTrim("ADI_PITCH_TRIM", "-3200", "+3200", 26, 28); DcsBios::Switch2Pos nmspAnchrBtn("NMSP_ANCHR_BTN", 43); DcsBios::Switch2Pos nmspTislBtn("NMSP_TISL_BTN", 39); DcsBios::Switch2Pos nmspEgiBtn("NMSP_EGI_BTN", 45); DcsBios::Switch2Pos nmspHarsBtn("NMSP_HARS_BTN", 35); DcsBios::Switch2Pos nmspSteerptBtn("NMSP_STEERPT_BTN", 41); DcsBios::Switch2Pos nmspTcnBtn("NMSP_TCN_BTN", 51); DcsBios::Switch2Pos nmspIlsBtn("NMSP_ILS_BTN", 49); DcsBios::Switch2Pos nmspAbleStow("NMSP_ABLE_STOW", 48); DcsBios::Switch3Pos fireExtDisch("FIRE_EXT_DISCH", A2, A3); DcsBios::Switch2Pos cmscPri("CMSC_PRI", 23); DcsBios::Switch2Pos cmscSep("CMSC_SEP", 25); DcsBios::Switch2Pos cmscUnk("CMSC_UNK", 27); DcsBios::Switch2Pos cmscJmr("CMSC_JMR", 42); DcsBios::Switch2Pos cmscMws("CMSC_MWS", A5); DcsBios::LED cmscPrio(0x1012, 0x0200, 29); DcsBios::LED cmscUnkn(0x1012, 0x0400, 31); DcsBios::LED cmscLaunch(0x1012, 0x0100, 33); void setup() { DcsBios::setup(); Wire.begin(); } void loop() { DcsBios::loop(); } Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
No1sonuk Posted July 31, 2024 Posted July 31, 2024 You're doing it right. The problem is "DEC", "INC". Replace "DEC", "INC" with "-1092", "+1092" You might need to tweak those values for the resolution you want. I tested with "DEC", "INC" and it didn't work, so I put in the numbers, and that works.
Kenpilot Posted July 31, 2024 Author Posted July 31, 2024 Awesome, I'll try that in a little bit. Thanks for looking at it and testing it!! 1 Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
Kenpilot Posted August 1, 2024 Author Posted August 1, 2024 It worked!! Thanks so much!!! 1 Windows 10 ASRock Z370 Extreme4 LGA 1151 (300 Series) MOBO intel i7-8700k (Not overclocked) 16 GB Ram EVGA GeForce GTX 108ti SC Black Edition SSD Trackir
Recommended Posts