Balthazar Posted October 19, 2021 Posted October 19, 2021 (edited) Hi all, Trying to bring fuel flow indicator of f16 in an LCD 16/2 with I2C expansion. I am new to arduino coding. I tried to create the code but cannot figure it out. Anybody who has a code for it or can help create one? Tried combining some things from internet but no luck. Thanks Edited October 19, 2021 by Balthazar
No1sonuk Posted October 19, 2021 Posted October 19, 2021 First-off, what are you using to output the data? If it's DCS-BIOS, which version (Flightpanels or Hub)? Secondly: Have you tried a simple sketch that only displays a message on the LCD? If you've not managed that, you can't hope to fault-find two systems at once (game interface and display). Thirdly: Have you managed to get any arduino code talking to the game? The main example is the A-10 master caution light and switch. I don't know if the F16 has a similar simple combination you can test. Finally, Post the code you've tried. It might be something simple.
Balthazar Posted October 20, 2021 Author Posted October 20, 2021 Hi and thanks for the reply. 1. Arduino Uno, LCD 16x2 with I2C exp, DCS-Bios hub 0.10.0 2. Yes and LCD works fine 3. With pleasure but not sure you will understand what i am doing there since as newbie i do not know a think #define DCSBIOS_IRQ_SERIAL #include <DcsBios.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,20,4); int Fueltotalizer1k = 0; int Fueltotalizer100 = 0; int Fueltotalizer10k = 0; void screen() { lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,0); lcd.print(Fueltotalizer100); } /* paste code snippets from the reference documentation here */ void onFueltotalizer1kChange(unsigned int newValue) { Fueltotalizer1k = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer1kBuffer(0x44e2, 0xffff, 0, onFueltotalizer1kChange); void onFuelflowcounter100Change(unsigned int newValue) { Fueltotalizer100 = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e4, 0xffff, 0, onFueltotalizer100Change); void onFueltotalizer10kChange(unsigned int newValue) { Fueltotalizer10k = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e0, 0xffff, 0, onFueltotalizer10kChange); void setup() { DcsBios::setup(); lcd.init(); lcd.init(); lcd.backlight(); } void loop() { DcsBios::loop(); } Thanks for your patience.
Vinc_Vega Posted October 20, 2021 Posted October 20, 2021 (edited) Caused by your "screen()" function, your display only prints the 100th digits, if any. Try this within the curved brackets: lcd.setCursor(0,0); lcd.print("Fuel: "); lcd.setCursor(6,0); lcd.print(Fueltotalizer10k); lcd.setCursor(7,0); lcd.print(Fueltotalizer1k); lcd.setCursor(8,0); lcd.print(Fueltotalizer100); lcd.setCursor(9,0); lcd.print("00"); lcd.display(); // maybe the display has to be refreshed, otherwise delete that statement Regards, Vinc Edited October 20, 2021 by Vinc_Vega typo correction 1 Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC]
No1sonuk Posted October 20, 2021 Posted October 20, 2021 (edited) I think in addition to Vinc's comment, part of your problem is the mismatch of terms here: Quote void onFuelflowcounter100Change(unsigned int newValue) { Fueltotalizer100 = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e4, 0xffff, 0, onFueltotalizer100Change); I'm surprised it compiled OK with those errors. I think it never sets the Fueltotalizer100 value... Edited October 20, 2021 by No1sonuk
Balthazar Posted October 21, 2021 Author Posted October 21, 2021 Hi first of all thank you both for taking the time to help me. I appreciate it. @No1sonuk You are perfectly right the code was not compiling because at the beginning i used wrong reference value and when i changed it i forgot to change the one you catch here. Thanks. Now is compiling. @Vinc_Vega Indeed i had only the 100th digits and i would put also the rest as soon as i could manage to compile. Now the code is like below but i do not read correct fuel flow! It seems that i miss something. #define DCSBIOS_IRQ_SERIAL #include <DcsBios.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,20,4); int Fueltotalizer1k = 0; int Fueltotalizer100 = 0; int Fueltotalizer10k = 0; void screen() { lcd.setCursor(0,0); lcd.print("Fuel: "); lcd.setCursor(6,0); lcd.print(Fueltotalizer10k); lcd.setCursor(7,0); lcd.print(Fueltotalizer1k); lcd.setCursor(8,0); lcd.print(Fueltotalizer100); lcd.setCursor(9,0); lcd.print("00"); } void onFueltotalizer1kChange(unsigned int newValue) { Fueltotalizer1k = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer1kBuffer(0x44e2, 0xffff, 0, onFueltotalizer1kChange); void onFueltotalizer100Change(unsigned int newValue) { Fueltotalizer100 = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer100Buffer(0x44e4, 0xffff, 0, onFueltotalizer100Change); void onFueltotalizer10kChange(unsigned int newValue) { Fueltotalizer10k = newValue; screen(); } DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e0, 0xffff, 0, onFueltotalizer10kChange); void setup() { DcsBios::setup(); lcd.init(); lcd.init(); lcd.backlight(); } void loop() { DcsBios::loop(); }
Balthazar Posted October 21, 2021 Author Posted October 21, 2021 Guys finally i made it. As soon as i will finalize all that i want to do i will upload it in case anyone else is interested. Thanks for your insights!
Balthazar Posted October 21, 2021 Author Posted October 21, 2021 I didn't figure out how the 10K, 1K and 100 worked. A friend explained me that the 100 has 3 digits and the others one and he helped me with the translation of the DCS-Bios data to digits. I also added some other functions and the results are the followings. RF = Remaining Fuel FF = Fuel Flow LG = Landing Gear UP/DN AB = Air Brakes CLO/OPN The code i finally did #define DCSBIOS_IRQ_SERIAL #include <DcsBios.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,20,4); int l = 0; //Remaing fuel counter// void onFueltotalizer1kChange(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 11); l = valueL; lcd.setCursor(4,0); lcd.print(valueL); } DcsBios::IntegerBuffer fueltotalizer1kBuffer(0x44e2, 0xffff, 0, onFueltotalizer1kChange); void onFueltotalizer100Change(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 99); unsigned int firstDigit; unsigned int secondDigit; firstDigit = valueL/10; secondDigit = valueL%10; lcd.setCursor(5,0); lcd.print(firstDigit); lcd.setCursor(6,0); lcd.print(secondDigit); lcd.setCursor(7,0); lcd.print("0"); } DcsBios::IntegerBuffer fueltotalizer100Buffer(0x44e4, 0xffff, 0, onFueltotalizer100Change); void onFueltotalizer10kChange(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 11); lcd.setCursor(3,0); lcd.print(valueL); } DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e0, 0xffff, 0, onFueltotalizer10kChange); //Fuel flow counter// void onFuelflowcounter10kChange(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 11); lcd.setCursor(3,1); lcd.print(valueL); } DcsBios::IntegerBuffer fuelflowcounter10kBuffer(0x44d6, 0xffff, 0, onFuelflowcounter10kChange); void onFuelflowcounter1kChange(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 11); l = valueL; lcd.setCursor(4,1); lcd.print(valueL); } DcsBios::IntegerBuffer fuelflowcounter1kBuffer(0x44d8, 0xffff, 0, onFuelflowcounter1kChange); void onFuelflowcounter100Change(unsigned int newValue) { unsigned int lEngFuelFlowValue = (newValue & 0xffff) >> 0; unsigned int valueL = map(lEngFuelFlowValue, 0, 65535, 0, 99); unsigned int firstDigit; unsigned int secondDigit; firstDigit = valueL/10; secondDigit = valueL%10; lcd.setCursor(5,1); lcd.print(firstDigit); lcd.setCursor(6,1); lcd.print(secondDigit); lcd.setCursor(7,1); lcd.print("0"); } DcsBios::IntegerBuffer fuelflowcounter100Buffer(0x44da, 0xffff, 0, onFuelflowcounter100Change); //Gear down// void onGearHandleChange(unsigned int newValue) { lcd.setCursor(13,0); if (newValue == 0){ lcd.print("DN"); } else { lcd.print("UP"); } } //Air Brakes// void onSpeedbrakeIndicatorChange(unsigned int newValue) { lcd.setCursor(13,1); if (newValue == 0){ lcd.print("CLO"); } else { lcd.print("OPN"); } } DcsBios::IntegerBuffer speedbrakeIndicatorBuffer(0x44c6, 0xffff, 0, onSpeedbrakeIndicatorChange); DcsBios::IntegerBuffer gearHandleBuffer(0x441c, 0x4000, 14, onGearHandleChange); void setup() { DcsBios::setup(); lcd.init(); lcd.init(); lcd.backlight(); lcd.setCursor(0,0); lcd.print("RF:"); lcd.setCursor(0,1); lcd.print("FF:"); lcd.setCursor(10,0); lcd.print("LG:"); lcd.setCursor(10,1); lcd.print("AB:"); } void loop() { DcsBios::loop(); }
Vinc_Vega Posted October 22, 2021 Posted October 22, 2021 (edited) Ahhh, as I don't have the F-16 module I didn't know that the flow values are of the "analogue" type that has to be converted (mapped). Fortunately now everything seems to work Regards, Vinc Edited October 22, 2021 by Vinc_Vega typo correction Regards, Vinc real life: Royal Bavarian Airforce online: VJS-GermanKnights.de [sIGPIC][/sIGPIC]
Recommended Posts