Jump to content

Recommended Posts

Posted (edited)

Guys, if you are like me and are pretty useless with coding on DCS Bios, then you are probably searching desperately for working sketches that you can copy.

 

So, I have decided to put this thread in when I get sketches that work, and with details of what I have used with it so that you can hopefully replicate it with no effort. It's about time I gave something back to the forum!

 

So, first up, I have got an LCD 1602A module like the one in the attached photo, which has the PCF8574 'backpack' attached that reduces the number of pins from 16 to just 4.

 

You need to install the LiquidCrystal_PCF8574 library ( https://github.com/mathertel/LiquidCrystal_PCF8574 )

 

The pinout from the Arduino to the PCF8574 backpack board is as follows

 

Arduino GND pin to PCF8574 GND pin

Arduino 5v pin to PCF8574 VCC pin

Arduino A4 pin to PCF8574 SDA pin

Arduino A5 pin to PCF8574 SCL pin

 

This sketch works with the above replicating the CMSC panel via USB

 

 

 

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#define DCSBIOS_IRQ_SERIAL

 

#include <DcsBios.h>

 

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

 

int show;

 

 

void onCmscTxtJmrChange(char* newValue) {

lcd.setCursor(0, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<8> cmscTxtJmrBuffer(0x1096, onCmscTxtJmrChange);

 

void onCmscTxtChaffFlareChange(char* newValue) {

lcd.setCursor(4, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<8> cmscTxtChaffFlareBuffer(0x108e, onCmscTxtChaffFlareChange);

 

void onCmscTxtMwsChange(char* newValue) {

lcd.setCursor(0, 1);

lcd.print(newValue);

}

DcsBios::StringBuffer<8> cmscTxtMwsBuffer(0x12b0, onCmscTxtMwsChange);

 

void setup() {

lcd.begin(16, 2);

lcd.clear();

DcsBios::setup();

 

}

 

void loop() {

DcsBios::loop();

lcd.setBacklight(255);

}

 

 

 

 

 

hope this helps

 

Les

20190616_121559.thumb.jpg.dc41f601f16ff0bd5752a88eafece676.jpg

Edited by lesthegrngo
Posted (edited)

TACAN and ILS panels via USB

 

Again, using a 1602A LCD panel with a PCF8574 this is the sketch for outputting the TACAN and ILS data

 

You need to install the LiquidCrystal_PCF8574 library ( https://github.com/mathertel/LiquidCrystal_PCF8574 )

 

The pinout from the Arduino to the PCF8574 backpack board is as follows

 

Arduino GND pin to PCF8574 GND pin

Arduino 5v pin to PCF8574 VCC pin

Arduino A4 pin to PCF8574 SDA pin

Arduino A5 pin to PCF8574 SCL pin

 

This sketch works with the above replicating the TACAN on the top line and ILS panel on the bottom line

 

 

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#define DCSBIOS_IRQ_SERIAL

 

#include <DcsBios.h>

 

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

 

int show;

 

 

void onTacanChannelChange(char* newValue) {

lcd.setCursor(0, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<4> tacanChannelBuffer(0x1162, onTacanChannelChange);

 

void onIlsKhzChange(char* newValue) {

lcd.setCursor(4, 1);

lcd.print(newValue);

}

DcsBios::StringBuffer<2> ilsKhzStrBuffer(0x1172, onIlsKhzChange);

 

void onIlsMhzChange(char* newValue) {

lcd.setCursor(0, 1);

lcd.print(newValue);

}

DcsBios::StringBuffer<3> ilsMhzStrBuffer(0x116e, onIlsMhzChange);

 

void setup() {

lcd.begin(16, 2);

lcd.clear();

DcsBios::setup();

 

}

 

void loop() {

DcsBios::loop();

lcd.setBacklight(10);

}

Edited by lesthegrngo
Posted (edited)

VHF AM radio via USB

 

 

Using a 1602A LCD panel with a PCF8574 this is the sketch for outputting the VHF AM radio and displaying the 4 character set frequency data on the top line and the preset character on the bottom.

 

It also has the four frequency rotary control dials plus the FM/AM/MAN/PRE Frequency Selection Dial and Preset Channel Selector mapped to rotary encoders

 

You need to install the LiquidCrystal_PCF8574 library ( https://github.com/mathertel/LiquidCrystal_PCF8574 )

 

The pinout from the Arduino to the PCF8574 backpack board is as follows

 

Arduino GND pin to PCF8574 GND pin

Arduino 5v pin to PCF8574 VCC pin

Arduino A4 pin to PCF8574 SDA pin

Arduino A5 pin to PCF8574 SCL pin

 

 

The pins for the rotary encoders are as follows

 

Arduino GND pin to all GND (middle) pins on rotary encoders

Arduino D2 and D3 pin to outer pins on rotary encoder 1 for frequency character 1

Arduino D4 and D5 pin to outer pins on rotary encoder 1 for frequency character 2

Arduino D6 and D7 pin to outer pins on rotary encoder 1 for frequency character 3

Arduino D8 and D9 pin to outer pins on rotary encoder 1 for frequency character 4

Arduino D10 and D11 pin to outer pins on rotary encoder 1 for FM/AM/MAN/PRE Frequency Selection Dial

Arduino D12 and D13 pin to outer pins on rotary encoder 1 for Preset Channel Selector Dial

 

 

 

 

 

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#define DCSBIOS_IRQ_SERIAL

 

#include <DcsBios.h>

 

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

 

int show;

 

 

 

void onVhfamFreq1Change(char* newValue) {

lcd.setCursor(0, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<2> vhfamFreq1StrBuffer(0x1190, onVhfamFreq1Change);

 

void onVhfamFreq2Change(unsigned int newValue) {

lcd.setCursor(3, 0);

lcd.print(newValue);

}

DcsBios::IntegerBuffer vhfamFreq2Buffer(0x118e, 0x00f0, 4, onVhfamFreq2Change);

 

void onVhfamFreq3Change(unsigned int newValue) {

lcd.setCursor(5, 0);

lcd.print(newValue);

}

DcsBios::IntegerBuffer vhfamFreq3Buffer(0x118e, 0x0f00, 8, onVhfamFreq3Change);

 

void onVhfamFreq4Change(char* newValue) {

lcd.setCursor(7, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<2> vhfamFreq4StrBuffer(0x1192, onVhfamFreq4Change);

 

void onVhfamPresetChange(char* newValue) {

lcd.setCursor(0, 1);

lcd.print(newValue);

}

DcsBios::StringBuffer<2> vhfamPresetStrBuffer(0x118a, onVhfamPresetChange);

 

DcsBios::RotaryEncoder vhfamFreq1("VHFAM_FREQ1", "DEC", "INC", 2, 3);

 

DcsBios::RotaryEncoder vhfamFreq2("VHFAM_FREQ2", "DEC", "INC", 4, 5);

 

DcsBios::RotaryEncoder vhfamFreq3("VHFAM_FREQ3", "DEC", "INC", 6, 7);

 

DcsBios::RotaryEncoder vhfamFreq4("VHFAM_FREQ4", "DEC", "INC", 8, 9);

 

DcsBios::RotaryEncoder vhfamFreqemer("VHFAM_FREQEMER", "DEC", "INC", 10, 11);

 

DcsBios::RotaryEncoder vhfamPreset("VHFAM_PRESET", "DEC", "INC", 12, 13);

 

 

void setup() {

lcd.begin(16, 2);

DcsBios::setup();

 

}

 

void loop() {

DcsBios::loop();

lcd.setBacklight(10);

}

Edited by lesthegrngo
Posted

Very helpful stuff.

 

These forums aren't great for code though. I'd suggest using Gist and then just linking them, as it will handle the code a lot better.

 

Here is your last example, the radio panel for example:

https://gist.github.com/jwvanderbeck/1d53fa5ed17917fced92c3212de117f9

 

I'll definitely be looking at that one as the first panels I want to make are tacan and radio since those are the worst in VR. Don't need a display though :)

Intel i7-4770k @ 4.4ghz, 32gb ram, GTX 1080ti, Oculus Rift S

 

Advanced apologies if my post contains typos or missing letters. Many of my posts are typed on a laptop with an old keyboard that has a personality all its own.

Posted (edited)

UHF radio and channel selector via USB

 

*edit*

 

.txt file attached, hopefully easier to transfer

 

Using a 1602A LCD panel with a PCF8574 this is the sketch for outputting the UHF AM radio and displaying the 6 character set plus decimal point frequency data on the bottom line and the preset character on the top, offset to match the position on the panel.

 

It also has the five frequency rotary control dials plus the Preset Channel Selector mapped to rotary encoders

 

You need to install the LiquidCrystal_PCF8574 library (https://github.com/mathertel/LiquidCrystal_PCF8574 )

 

The pinout from the Arduino to the PCF8574 backpack board is as follows

 

Arduino GND pin to PCF8574 GND pin

Arduino 5v pin to PCF8574 VCC pin

Arduino A4 pin to PCF8574 SDA pin

Arduino A5 pin to PCF8574 SCL pin

 

 

The pins for the rotary encoders are as follows

 

Arduino GND pin to all GND (middle) pins on rotary encoders

Arduino D2 and D3 pin to outer pins on rotary encoder 1 for 100mhz frequency character 1

Arduino D4 and D5 pin to outer pins on rotary encoder 1 for 10mhz frequency character 2

Arduino D6 and D7 pin to outer pins on rotary encoder 1 for 1mhz frequency character 3

Arduino D8 and D9 pin to outer pins on rotary encoder 1 for 0.1mhz frequency character 4

Arduino D10 and D11 pin to outer pins on rotary encoder 1 for 0. 25mhz frequency character 5 and 6

(Note, a static decimal point is inserted in character postion 4)

Arduino D12 and D13 pin to outer pins on rotary encoder 1 for Preset Channel Selector Dial

 

 

 

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#define DCSBIOS_IRQ_SERIAL

 

#include <DcsBios.h>

 

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

 

int show;

 

 

 

void onUhf100mhzSelChange(char* newValue) {

lcd.setCursor(0, 1);

lcd.print(newValue);

}

DcsBios::StringBuffer<1> uhf100mhzSelStrBuffer(0x1178, onUhf100mhzSelChange);

 

void onUhf10mhzSelChange(unsigned int newValue) {

lcd.setCursor(1, 1);

lcd.print(newValue);

}

DcsBios::IntegerBuffer uhf10mhzSelBuffer(0x1170, 0x3c00, 10, onUhf10mhzSelChange);

 

void onUhf1mhzSelChange(unsigned int newValue) {

lcd.setCursor(2, 1);

lcd.print(newValue);

}

DcsBios::IntegerBuffer uhf1mhzSelBuffer(0x1178, 0x0f00, 8, onUhf1mhzSelChange);

 

 

void onUhfPresetChange(char* newValue) {

lcd.setCursor(6, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<2> uhfPresetBuffer(0x1188, onUhfPresetChange);

 

 

 

void onUhfPoint1mhzSelChange(unsigned int newValue) {

lcd.setCursor(4, 1);

lcd.print(newValue);

}

DcsBios::IntegerBuffer uhfPoint1mhzSelBuffer(0x1178, 0xf000, 12, onUhfPoint1mhzSelChange);

 

void onUhfPoint25SelChange(char* newValue) {

lcd.setCursor(5, 1);

lcd.print(newValue);

 

lcd.setCursor(3, 1);

lcd.print(".");

}

DcsBios::StringBuffer<2> uhfPoint25SelStrBuffer(0x117a, onUhfPoint25SelChange);

 

DcsBios::RotaryEncoder uhf100mhzSel("UHF_100MHZ_SEL", "DEC", "INC", 2, 3);

 

DcsBios::RotaryEncoder uhf10mhzSel("UHF_10MHZ_SEL", "DEC", "INC", 4, 5);

 

DcsBios::RotaryEncoder uhf1mhzSel("UHF_1MHZ_SEL", "DEC", "INC", 6, 7);

 

DcsBios::RotaryEncoder uhfPoint1mhzSel("UHF_POINT1MHZ_SEL", "DEC", "INC", 8, 9);

 

DcsBios::RotaryEncoder uhfPoint25Sel("UHF_POINT25_SEL", "DEC", "INC", 10, 11);

 

DcsBios::RotaryEncoder uhfPresetSel("UHF_PRESET_SEL", "DEC", "INC", 12, 13);

 

 

void setup() {

lcd.begin(16, 2);

DcsBios::setup();

 

}

 

void loop() {

DcsBios::loop();

lcd.setBacklight(10);

}

PCF 8574 UHF.txt

Edited by lesthegrngo
Posted (edited)

Hi Les,

 

 

Do you see any effect when using a value of 10 in "lcd.setBacklight"?

Is the Display's backlight more dimmed as if using the value 255 (like in the cmsc sketch)?

If you only want to switch the backlight (without dimming) just use: "lcd.backlight();" in the setup loop.

For dimming the backlight I think a PWM pin from the arduino has to be used.

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

No, Vinc, you are right in that the value after the lcd.setBacklight seems to have no effect - the original value was 255, but I was playing around with it on later sketches, and as it seemed to have zero effect I just left it as it was.

 

If there is a line of code to affect it, it would be interesting to know, maybe include it for future sketches?

 

Cheers

 

Les

Posted

I dont think dimming is possible via the PCF Chip. I use a PWM signal (eg. Pin 5) connected to the Background LED of the LCD. Instaed of direct connecting I use a small FET (2N7000) and the analogWrite() function to control brightness of the LED.

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted (edited)

ILS panel via USB

 

 

.txt file attached

 

Using a 1602A LCD panel with a PCF8574 this is the sketch for outputting the ILS and displaying the 5 character set plus decimal point frequency data on the bottom line

 

It also has two frequency control dials plus the on-off switch mapped to rotary encoders. Hopefully future versions will have the volume control mapped to a rotary encoder too, but at the moment I can't seem to make it work

 

You need to install the LiquidCrystal_PCF8574 library (https://github.com/mathertel/LiquidCrystal_PCF8574 )

 

The pinout from the Arduino to the PCF8574 backpack board is as follows

 

Arduino GND pin to PCF8574 GND pin

Arduino 5v pin to PCF8574 VCC pin

Arduino A4 pin to PCF8574 SDA pin

Arduino A5 pin to PCF8574 SCL pin

 

 

The pins for the rotary encoders are as follows

 

Arduino GND pin to all GND (middle) pins on rotary encoders

Arduino D2 and D3 pin to outer pins on rotary encoder 1 for Khz frequency characters 1 & 2

Arduino D4 and D5 pin to outer pins on rotary encoder 1 for Mhz frequency character 3, 4 & 5

Arduino D6 and D7 pin to outer pins on rotary encoder 1 for on-off switch

 

 

 

 

 

#include <Wire.h>

#include <LiquidCrystal_PCF8574.h>

#define DCSBIOS_IRQ_SERIAL

 

#include <DcsBios.h>

 

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display

 

int show;

 

void onIlsKhzChange(char* newValue) {

lcd.setCursor(4, 0);

lcd.print(newValue);

lcd.setCursor(3, 0);

lcd.print(".");

}

DcsBios::StringBuffer<2> ilsKhzStrBuffer(0x1172, onIlsKhzChange);

 

void onIlsMhzChange(char* newValue) {

lcd.setCursor(0, 0);

lcd.print(newValue);

}

DcsBios::StringBuffer<3> ilsMhzStrBuffer(0x116e, onIlsMhzChange);

 

DcsBios::RotaryEncoder ilsKhz("ILS_KHZ", "DEC", "INC", 2, 3);

 

DcsBios::RotaryEncoder ilsMhz("ILS_MHZ", "DEC", "INC", 4, 5);

 

DcsBios::RotaryEncoder ilsPwr("ILS_PWR", "DEC", "INC", 6, 7);

 

 

 

 

void setup() {

lcd.begin(16, 2);

DcsBios::setup();

 

}

 

void loop() {

DcsBios::loop();

lcd.setBacklight(10);

}

PCF8574 ILS.txt

Edited by lesthegrngo
Posted

The proper way to display code on the forum is to place it between characters that show up when you check the # in the menu above. That way you don't have to include a .txt file. This is what you will get by doing it the correct way and it makes it easy to copy the code and paste it into another app... IDE.

 

 


/*This should work on any Arduino that has an ATMega328 controller
 (Uno, Pro Mini, many others).
*/
#define DCSBIOS_IRQ_SERIAL
#include "DcsBios.h"
#include "SwitecX25.h"

#include <LedDisplay.h>
#include <font5x7.h>

//*****************STEPPER MOTORS SETUP AND CONTROL-MAIN FUEL GAUGE************************************

int TotalSteps = 475; //There are 945 steps on these motors. We are only using half of the available steps which equals 475 steps. 

SwitecX25 motor2(315*3, 5,4,3,2);
SwitecX25 motor1(315*3, 6,7,8,9);

void onFuelQtyLChange(unsigned int newValue) { //the value we get from "onFuelQtyLChange" is placed in the variable "newValue" for us to use. 
 motor1.setPosition(map(newValue, 0, 65535, 0, TotalSteps)); //Here is where we are remapping the 475 steps to the total steps that are being exported.
}
DcsBios::IntegerBuffer fuelQtyLBuffer(0x10ca, 0xffff, 0, onFuelQtyLChange);

void onFuelQtyRChange(unsigned int newValue) { //the value we get from "onFuelQtyRChange" is placed in the variable "newValue" for us to use.
  motor2.setPosition(map(newValue, 0, 65535, 0, TotalSteps)); //Here is where we are remapping the 475 steps to the total steps that are being exported.
}
DcsBios::IntegerBuffer fuelQtyRBuffer(0x10cc, 0xffff, 0, onFuelQtyRChange);




//*********************************[b]HCMS Display[/b]**********************************************************
LedDisplay fuelDisplay = LedDisplay(10,11,A0,A1,12,8); //(DIN, RS, CLK, CE, RST, displayLength)

/*"[b]fuelDisplay[/b]" is now the name of the display I just created with the above statement
 as well as the pins it will use on the Arduino board*/

void onFuelQty10000Change(unsigned int newValue) {
 fuelDisplay.setCursor(2);
 fuelDisplay.print(newValue/6553);
}
DcsBios::IntegerBuffer fuelQty10000Buffer(0x10ce, 0xffff, 0, onFuelQty10000Change);

void onFuelQty1000Change(unsigned int newValue) {
  fuelDisplay.setCursor(3);
 fuelDisplay.print(newValue/6553);
}
DcsBios::IntegerBuffer fuelQty1000Buffer(0x10d0, 0xffff, 0, onFuelQty1000Change);

void onFuelQty100Change(unsigned int newValue) {
  fuelDisplay.setCursor(4);
 fuelDisplay.print(newValue/6553);
}
DcsBios::IntegerBuffer fuelQty100Buffer(0x10d2, 0xffff, 0, onFuelQty100Change);




void setup() {
 DcsBios::setup();
 motor1.zero();   // this is a slow, blocking operation
 motor2.zero();
 fuelDisplay.begin();
 fuelDisplay.setBrightness(15);//0 to 15 is the renage of brightness settings
 fuelDisplay.print("88888888");
 delay(2000);
 fuelDisplay.clear(); //Clears the HCMS Display 
 fuelDisplay.setCursor(5);
 fuelDisplay.print("00");
}

void loop() {
 DcsBios::loop();
 motor1.update();
 motor2.update();
}

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

  • Recently Browsing   0 members

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