Lot2Learn Posted March 19, 2023 Share Posted March 19, 2023 HI, Really proud of this one, it has been a long run of over 6 weeks of research, trials and errors but I finally got it to work over a potentiometer for now... Next is going to be for me to find how to implement in harmony with Bios Fork...which should turn out in a few weeks of learning curves. Thanks to Vince Vega who without knowing got me into this, after I finished my first mechanical IAS with stepper X27 I saw his videos of different gauges oleds project on Vimeo, I was really impressed with the quality of graphics, and decided to buy many ESP32's and Oled and took the plunge. I taught at first that the batteries gauge would be an easy one to go with at first but having two needles going opposite ways was the most challenging part for me. I should have went to school much longer lollll. Lot2Learn 2023-03-19 Batt Gauge 2 Needles.MOV 1 Link to comment Share on other sites More sharing options...
No1sonuk Posted March 19, 2023 Share Posted March 19, 2023 You could either rewrite your code to use the wider bit range of the 16-bit outputs from DCS-BIOS, or you could remap the DCS-BIOS numbers to the numbers you got from the A-D converters and use your existing code. Link to comment Share on other sites More sharing options...
Lot2Learn Posted March 19, 2023 Author Share Posted March 19, 2023 Thanks No1sonuk, It took me 6 weeks to get over this with a potentiometer, I have very few skills in programming so I understand part of what your telling me here but most of it I'll have to research, and make a little trial and errors lolll. It's been a long time 5/6 months or so since I tried coding with DCS Bios, and just realized while trying that it looks like DCS Bios and servo.h does not work with ESP32 I think, I may be wrong. thanks again Link to comment Share on other sites More sharing options...
No1sonuk Posted March 20, 2023 Share Posted March 20, 2023 (edited) Change the control reference view to "Advanced". That will give you more code blocks, including 16-bit integer number outputs for both voltages: void onVoltEChange(unsigned int newValue) { /* your code here */ } DcsBios::IntegerBuffer voltEBuffer(0x753e, 0xffff, 0, onVoltEChange); void onVoltUChange(unsigned int newValue) { /* your code here */ } DcsBios::IntegerBuffer voltUBuffer(0x753c, 0xffff, 0, onVoltUChange); The Arduino map function is this: map(value, fromLow, fromHigh, toLow, toHigh) So try this: int voltE = 0; // Set up global variable for VoltE int voltU = 0; // Set up global variable for VoltU void onVoltEChange(unsigned int newValue) { voltE = map(newValue, 0, 65535, 0, 4095); // Map 16-bit value from DCS to 12-bit value range from ADC displayVoltE(); // Run display routine for VoltE needle } DcsBios::IntegerBuffer voltEBuffer(0x753e, 0xffff, 0, onVoltEChange); void onVoltUChange(unsigned int newValue) { voltU = map(newValue, 0, 65535, 0, 4095); // Map 16-bit value from DCS to 12-bit value range from ADC displayVoltU(); // Run display routine for VoltU needle } DcsBios::IntegerBuffer voltUBuffer(0x753c, 0xffff, 0, onVoltUChange); And write the displayVoltE() and displayVoltU() based on your existing display code. Edited March 20, 2023 by No1sonuk Link to comment Share on other sites More sharing options...
Lot2Learn Posted March 20, 2023 Author Share Posted March 20, 2023 Thanks so much, I'll give it a try tomorrow morning, do you know if DCS Bios is supporting ESP32 ? I've had errors earlier when I tried it said that servo and DCS Bios libraries both didn't support ESP32, they do with Atmel, STM and many others but I'm not sure with ESP32. Thanks again you've helped me a lot, I appreciate Link to comment Share on other sites More sharing options...
No1sonuk Posted March 20, 2023 Share Posted March 20, 2023 That's something to ask the FP Fork guys. I only use Arduinos. However, they're both just C libraries, so I don't see why they wouldn't be portable. The main differences would be in the hardware handling parts such as the USB comms and PWM drive for the servo. Link to comment Share on other sites More sharing options...
Vinc_Vega Posted March 20, 2023 Share Posted March 20, 2023 (edited) You may use the DcsBios library with USB connected ESP32 boards when using the Default_Serial option. There also is an ESP32 library available, dealing with the servo and PWM differences. Else you have to define all the values by yourself. I can bring in an example when I'm home tonight. Regards, Vinc Edited March 20, 2023 by Vinc_Vega Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Lot2Learn Posted March 20, 2023 Author Share Posted March 20, 2023 11 hours ago, Vinc_Vega said: You may use the DcsBios library with USB connected ESP32 boards when using the Default_Serial option. There also is an ESP32 library available, dealing with the servo and PWM differences. Else you have to define all the values by yourself. I can bring in an example when I'm home tonight. Regards, Vinc Thank you very much, I would appreciate if you could send your example. I'm bad at coding and the more I get example the better I 'll get ( I Hope ). Making sketch for switch and pots was easy at first now it's more in the major league with steppers and oled...I find it though. Link to comment Share on other sites More sharing options...
Vinc_Vega Posted March 21, 2023 Share Posted March 21, 2023 (edited) Okay, here we are with the ESP32 attached servo function for DcsBios. As my A-10C II has problems with the DcsBios connection at the time, I simply used the BF-109's altimeter needle to test the script. You need to install the ESP32Servo library and include it BEFORE all the DcsBio stuff. Spoiler /* The servo library has to be included before DcsBios see: https://github.com/dcs-bios/dcs-bios/issues/101 */ #include <ESP32Servo.h> //#define DCSBIOS_IRQ_SERIAL // for use with Arduino Chips #define DCSBIOS_DEFAULT_SERIAL // for use with no Arduino Chips #include "DcsBios.h" #define servoPin 27 // define the servo pin connection Servo servo; //create an instance of the type "Servo" // ---------- DCS.BIOS stuff here ---------- void onAltimeterFineptrChange(unsigned int newValue) { servo.write(map(newValue, 0, 65535, 0, 180)); // map the output to a 0 - 180 degrees } DcsBios::IntegerBuffer altimeterFineptrBuffer(0x4248, 0xffff, 0, onAltimeterFineptrChange); // ---------- SETUP Loop ---------- void setup() { DcsBios::setup(); // define the servo parameters servo.setPeriodHertz(50); // set servo frequency in Hz servo.attach(servoPin, 544, 2400); // define minPulseWidth and maxPulseWidth in Microseconds (DcsBios standard is 544, 2400) // test the servo output servo.write(180); // set servo to 180 degrees delay(250); servo.write(0); // set servo to 0 } void loop() { DcsBios::loop(); // try to keep empty } // ---------- Supporting functions ---------- // if a delay is necessary, try to include the below workaround "setServoPosition()" instead of the "servo.write" command // Function to set the servo void setServoPosition(int degree) { servo.write(degree); delay(25); // small delay of 25 Milliseconds } If your servo is not moving good, try to use a small delay between the steps. You therefore have to replace the line servo.write(map(newValue, 0, 65535, 0, 180)); with the respective function setServoPosition(map(newValue, 0, 65535, 0, 180)); Regards, Vinc Edited March 21, 2023 by Vinc_Vega Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Vinc_Vega Posted March 21, 2023 Share Posted March 21, 2023 PS: if you need more servos connected, just create more instances. Servo servo0, servo1, servo2; Regards, Vinc Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Lot2Learn Posted March 26, 2023 Author Share Posted March 26, 2023 On 3/19/2023 at 8:18 PM, No1sonuk said: Change the control reference view to "Advanced". That will give you more code blocks, including 16-bit integer number outputs for both voltages: void onVoltEChange(unsigned int newValue) { /* your code here */ } DcsBios::IntegerBuffer voltEBuffer(0x753e, 0xffff, 0, onVoltEChange); void onVoltUChange(unsigned int newValue) { /* your code here */ } DcsBios::IntegerBuffer voltUBuffer(0x753c, 0xffff, 0, onVoltUChange); The Arduino map function is this: map(value, fromLow, fromHigh, toLow, toHigh) So try this: int voltE = 0; // Set up global variable for VoltE int voltU = 0; // Set up global variable for VoltU void onVoltEChange(unsigned int newValue) { voltE = map(newValue, 0, 65535, 0, 4095); // Map 16-bit value from DCS to 12-bit value range from ADC displayVoltE(); // Run display routine for VoltE needle } DcsBios::IntegerBuffer voltEBuffer(0x753e, 0xffff, 0, onVoltEChange); void onVoltUChange(unsigned int newValue) { voltU = map(newValue, 0, 65535, 0, 4095); // Map 16-bit value from DCS to 12-bit value range from ADC displayVoltU(); // Run display routine for VoltU needle } DcsBios::IntegerBuffer voltUBuffer(0x753c, 0xffff, 0, onVoltUChange); And write the displayVoltE() and displayVoltU() based on your existing display code. Thank You No1sonuk for your help on that one, it took me a week to understand the mapping function in conjunction with the pointer calibration tool in DCS-Bios FP. Having it reset to 16 volts when there is a change of scenario, mission, or simply when the game is paused was also a challenge for me, but I got it working the way it should. thanks again for taking the time to help. Lot2learn...still Link to comment Share on other sites More sharing options...
Lot2Learn Posted March 26, 2023 Author Share Posted March 26, 2023 On 3/21/2023 at 5:20 AM, Vinc_Vega said: PS: if you need more servos connected, just create more instances. Servo servo0, servo1, servo2; Regards, Vinc Thanks to you also Vinc_Vega, I noticed servo.h was not supported by ESP32, I downloaded another library that should work if I need later on, but for now I was coding for a round 240 x 240 Oled screen inspired by the video of your different gauges I've seen on Vimeo. Thanks Lot2learn Link to comment Share on other sites More sharing options...
aegis53 Posted May 18, 2023 Share Posted May 18, 2023 Greetings, I am very interested in your project here just wondering if you have got this working with DCS yet? i'm also interested in what type of OLED's you used do you have any part numbers you could post. Im guessing this required the ESP from a processing point of view is that correct? Lastly you talk about the coding challenges, but I can't actually see your code was it ever posted to this thread? Regards. Link to comment Share on other sites More sharing options...
BaronVonVaderham Posted October 23, 2023 Share Posted October 23, 2023 Same question for me really Link to comment Share on other sites More sharing options...
Recommended Posts