Jump to content

Recommended Posts

Posted

How many buttons can you make with an Arduino Uno and DCS-Bios? I tried making a 5x5 keypad matrix. It reads if I plug column 1 into ground and plug 1-5 rows into pins 2,3,4,5,6. But if I try plugging column 1 into pin 8 and column 2 into pin 9 it does not work.

 

This works but will only give me 5 buttons

DcsBios::Switch2Pos pvi0("PVI_0", 2);

DcsBios::Switch2Pos pvi1("PVI_1", 3);

 

This does not work

DcsBios::Switch2Pos pvi0("PVI_0", 2,8 );

DcsBios::Switch2Pos pvi1("PVI_1", 2,9);

Posted
/*
 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"

/* paste code snippets from the reference documentation here */
DcsBios::Switch2Pos pvi0("PVI_0", 3,2);
DcsBios::Switch2Pos pvi1("PVI_1", 4,2);
DcsBios::Switch2Pos pvi2("PVI_2", 5,2);
DcsBios::Switch2Pos pvi3("PVI_3", 6,2);
DcsBios::Switch2Pos pvi4("PVI_4", 7,2);
DcsBios::Switch2Pos pvi5("PVI_5", 3,8);
DcsBios::Switch2Pos pvi6("PVI_6", 4,8);
DcsBios::Switch2Pos pvi7("PVI_7", 5,8);
DcsBios::Switch2Pos pvi8("PVI_8", 6,8);
DcsBios::Switch2Pos pvi9("PVI_9", 7,8);
void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

Posted

Yeah that wouldn’t work. By using the defaults of DCS-BIOS you don’t get access to a keypad matrix.

 

The following standard line;

DcsBios::Switch2Pos pvi0("PVI_0", 3);

Basically says to pull pin3 HIGH which would then be PVI_0 value 0. If you ground the input (i.e. a push button or toggle switch between pin2 and GND) then PVI_0 value would be 1.

When you write;

DcsBios::Switch2Pos pvi0("PVI_0", 3,2);

DCS-BIOS Arduino code doesn’t really know what you mean. I can interpret that you mean that in case there is connection between 2 & 3 then PVI_0 is value 1, else it’s not. But DCS-BIOS hasn’t been told this, so what it actually does is it set pin3 HIGH which is like before. On top of that you have written;

DcsBios::Switch2Pos pvi5("PVI_5", 3,8);

Which is just setting pin3 HIGH once more. If you loaded this and watches the SOCAT running without DCS running, you would noticed that in case you ground pin3 then the Arduino would send

PVI_5 1

PVI_0 1

Because both are defined for pin3.

In a keypad matrix you have rows and columns, By alternating the columns between HIGH output and LOW output you can see which of the inputs (rows) are triggered.

Here is a more through explanation of how the keypad works;

 

 

Take a good cup of coffee and watch it. I found it very informative because it explains that there are some functions which needs to be running in the background.

This is what the keypad library does for you. Then you ‘just’ need to setup your own piece of code to let DCS-BIOS know when to send the different messages to DCS. This is how I have used it in CDU sketch I linked to.

 

Note! If you want to use toggle switches then you need to apply diodes otherwise you get false readouts.

 

Cheers

Hans

Posted

Ok I will watch it!! Thank you so much for helping me. I've been reading your post and looking at your simpit and I am amazed. You do some awesome work. I would love to be able to do that but I don't room and time. I just want to make some boards to make it more user friendly when flying and not trying to look at a keyboard sheet to figure out which 4 buttons I need to push at the same time while holding onto the flight stick.

Posted

Well that sound kinda like how I started. I got disoriented when switching radios so I started using Leo Bodnar boards and then it just expanded from there.

I am certain we'll get you going. Depending on where you wanna go you could also look at Overpro's USB controller

https://forums.eagle.ru/showthread.php?t=117011

 

It gives you 256 inputs for switches/buttons. I don't know much about the KA-50 but for the A-10C I know that when using joystick you may have to alter the joystick.lua files to get them to work.

 

Anyway that was just to keep your options open.

 

Cheers

Hans

  • 2 years later...
Posted

Lol I did a similar thing but with a Multiplexer. I still don't have it figured all out yet but that's why I'm here. So basically the way the dcs bios library is built, is it expects a singular place holder like ,15 in the "pin" pointer. I haven't figured out how to put select pins or colum and row pins into the pin place holder for the dcs-bios instance. But I imagine you could try to create an address like button1 =  [2] {col1,pin1} ;  but you'll probably need to do something else with this otherwise dcs might see each time the col or row pin changes high to low as a new value and you'll oscillate your virtual buttons maybe a boolean type operation like if (col1 && pin1 = HIGH); //button is pressed

Buttonstate= HIGH ; this is probably way off but maybe it help some one understand how dcs-bios works with matrices and multiplexer it is not a plug and play library when you use any other method than a basic button and led

Posted

You could "abandon" the DCS-BIOS switch functions altogether and use the sendDcsBiosMessage function.
Which, I'm just seeing, is basically what Hansolo suggested in his first response. 

  • 1 month later...
Posted

G'day blokes and blokettes,

Is anyone able to explain why this code below would not communicate with DCS at all? I am using a MEGA2560 board. My matrix is wired like the screenshot attached, the only difference being which pins the rows and columns are connected to (they are wired as per the code below).

I tried wiring buttons individually to pins through a diode (1N4001) with the cathode pointing to the rows, and that didn't work either when I used the generic Control Reference codes in the #define DCSBIOS_DEFAULT_SERIAL. Both methods don't work with IRQ_SERIAL either.

When I say it doesn't work, I mean I get zero response, not even ghosting etc. DCS BIOS is configured correctly, I get virtual cockpit connection and COMM connection through the correct port etc. and the code verifies and successfully uploads to the board.

This is for an F18 UFC using the control reference for the 'CASE' SendDcsBiosMessage lines.

 

Cheers in advance.

 

#define DCSBIOS_DEFAULT_SERIAL
 
#include <Keypad.h>
#include <DcsBios.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
    {'1','2','3','B'},
    {'4','5','6','C'},
    {'7','8','9','D'},
    {'*','0','#','E'} //ufc keypad minus the top right option select (A) as it didn't neatly fit my matrix
};

byte rowPins[ROWS] = {8,9,10,11}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,5,6,7}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup(){
    DcsBios::setup();
    Serial.begin(9600);
    keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop(){
  DcsBios::loop();
    char key = keypad.getKey();
}

void keypadEvent(KeypadEvent KEY){
  switch (keypad.getState()) { // gives PRESSED, HOLD or RELEASED
    case PRESSED: 
    switch(KEY){
      case '1': sendDcsBiosMessage("UFC_1", "1"); break;
      case '2': sendDcsBiosMessage("UFC_2", "1"); break;
      case '3': sendDcsBiosMessage("UFC_3", "1"); break;
      case '4': sendDcsBiosMessage("UFC_4", "1"); break;
      case '5': sendDcsBiosMessage("UFC_5", "1"); break;
      case '6': sendDcsBiosMessage("UFC_6", "1"); break;
      case '7': sendDcsBiosMessage("UFC_7", "1"); break;
      case '8': sendDcsBiosMessage("UFC_8", "1"); break;
      case '9': sendDcsBiosMessage("UFC_9", "1"); break;
      case '0': sendDcsBiosMessage("UFC_0", "1"); break;

      case '*': sendDcsBiosMessage("UFC_CLR", "1"); break;
      case '#': sendDcsBiosMessage("UFC_ENT", "1"); break;
      
      case 'B': sendDcsBiosMessage("UFC_OS2", "1"); break;
      case 'C': sendDcsBiosMessage("UFC_OS3", "1"); break;
      case 'D': sendDcsBiosMessage("UFC_OS4", "1"); break;
      case 'E': sendDcsBiosMessage("UFC_OS5", "1"); break;
      
    }}

     switch (keypad.getState()) { // gives PRESSED, HOLD or RELEASED
    case RELEASED: 
    switch(KEY){
      case '1': sendDcsBiosMessage("UFC_1", "0"); break;
      case '2': sendDcsBiosMessage("UFC_2", "0"); break;
      case '3': sendDcsBiosMessage("UFC_3", "0"); break;
      case '4': sendDcsBiosMessage("UFC_4", "0"); break;
      case '5': sendDcsBiosMessage("UFC_5", "0"); break;
      case '6': sendDcsBiosMessage("UFC_6", "0"); break;
      case '7': sendDcsBiosMessage("UFC_7", "0"); break;
      case '8': sendDcsBiosMessage("UFC_8", "0"); break;
      case '9': sendDcsBiosMessage("UFC_9", "0"); break;
      case '0': sendDcsBiosMessage("UFC_0", "0"); break;

      case '*': sendDcsBiosMessage("UFC_CLR", "0"); break;
      case '#': sendDcsBiosMessage("UFC_ENT", "0"); break;
      
      case 'B': sendDcsBiosMessage("UFC_OS2", "0"); break;
      case 'C': sendDcsBiosMessage("UFC_OS3", "0"); break;
      case 'D': sendDcsBiosMessage("UFC_OS4", "0"); break;
      case 'E': sendDcsBiosMessage("UFC_OS5", "0"); break;

    }}
}

Button Matrix Wiring.JPG

Posted (edited)

Try taking out the "Serial.begin(9600);".
I think that's probably interfering with the DCS-BIOS setup of the serial port.

Edited by No1sonuk
  • Recently Browsing   0 members

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