Jump to content

Panel building help


MarkBLN

Recommended Posts

Hey guys. 

I'm going to build my first panel and wanted some advice. Originally it was going to be an F18 panel that had most of the important  switches combined into one panel. Then I decided to make it a bit more general to use with something else, like maybe the apache, also msfs2020. 

 

The original plan was to use DCS bios, but as I want it to be more general and also msfs2020 compatible, I think setting it up as a joystick is the best? 

I have some leds that I want to use, but was possibly going to hook them up to a separate arduino and just use DCS bios to trigger them separately to the inputs which I'll do on an Arduino mega. 

 

I have a bunch of switches that are on-off-on that I want to use as on-on-on. I was told that DCS bios can do this, but what about if I just set the panel up as a joystick? Can I still address those switches as I want? 

 

Any advice would be welcomed. 

 

Cheers, 

 

Mark. 

Link to comment
Share on other sites

51 minutes ago, MarkBLN said:

Hey guys. 

I'm going to build my first panel and wanted some advice. Originally it was going to be an F18 panel that had most of the important  switches combined into one panel. Then I decided to make it a bit more general to use with something else, like maybe the apache, also msfs2020. 

 

The original plan was to use DCS bios, but as I want it to be more general and also msfs2020 compatible, I think setting it up as a joystick is the best? 

I have some leds that I want to use, but was possibly going to hook them up to a separate arduino and just use DCS bios to trigger them separately to the inputs which I'll do on an Arduino mega. 

 

I have a bunch of switches that are on-off-on that I want to use as on-on-on. I was told that DCS bios can do this, but what about if I just set the panel up as a joystick? Can I still address those switches as I want? 

 

Any advice would be welcomed. 

 

Cheers, 

 

Mark. 

I've decided to wait on DCS-Bios; partly because that's a much bigger task, and go with v2.5 of my pit.  Started soldering today, in fact.  Using 3 teensys, which are basically a clone of the Arduino configured as serial/KB/Joystick/mouse along with, roughly, 15x16 port I2C chips (5 per controller).  ~128 buttons and 8 axis each.  Total of 6 panels, with controls for the F/A-18, F-16, some F-14 bits, and even a P-47 switch or two.  With all that there isn't much that can't be done.  Air Force and Navy with a dash of WWII.  They mostly follow patterns.

For my purposes I use ON-ON, (ON)-(ON), and ON-ON-ON NKK switches, some 1-10 position (adjustable) rotaries, and a bunch of ON-(ON) push buttons.  There's actually a LED or two that will be wired in anticipation of DCS-Bios being ready for me (or vice versa; right now Chrome is the deal breaker). 

ON-OFF-ON will work if the DCS controls are configured right; not all of them are.  Otherwise you need a software layer, or you could probably make them ON-ON-ON in code if you worked at it.  I just wrapped up the code to make the eject button light up briefly when you push it, and played with it until if you wait until it goes off to push it again you'll never eject.  It's not good for much, but it was a fun problem.

Maybe I'll work on that; I do have a couple ON-OFF-ON switches laying around.

One thing with <that other sim> you'll need to know button numbers, which is why I also made the boards serial.  I can use Serial.write to kick out diagnostic and informational messages.  I can neither confirm nor deny that lives on a different drive and I'd like to get the pit set up for that as well.

If you need details you came to the right place; lots of people on here that are way smarter than me and can help you solve your problems.

  • Like 1
Link to comment
Share on other sites

Thanks for the reply mate. I'm new to this so will have to research how to use the on-off-on as on-on-on, and free on-off as on-on. 

I know its possible with DCS bios, but need to get some specific informations to do it as just a joystick. I wanted to get on-on-on switches to make like easier but couldn't find them cheap. 

 

As I've never done anything like this I'm a bit lost on the finer details at moment. 


Edited by MarkBLN
Link to comment
Share on other sites

1 hour ago, MarkBLN said:

Thanks for the reply mate. I'm new to this so will have to research how to use the on-off-on as on-on-on, and free on-off as on-on. 

I know its possible with DCS bios, but need to get some specific informations to do it as just a joystick. I wanted to get on-on-on switches to make like easier but couldn't find them cheap. 

The code looks like this.  One button is always down; either one of the two real buttons, or a third 'ghost' button that's active any time the others aren't.  I wrote it with arrays so adding new button sets would be easy.

Tested in DCS, and it looks like a 3 position switch.  Of course I wrote this for Teensy; Arduino might look a little different; even if it does the idea would still be the same.

 

/*
 * This is a test to turn an ON-OFF-ON switch into an ON-ON-ON switch
 */

const byte switch3PNumber = 1;              // Number of ON-OFF-ON switches to manage

int switch3PPins[switch3PNumber][2] = {     //Pins the two 'real' switches are attached to
{7,9}
};

int switch3PButtons[switch3PNumber][3] = {  // Buttons to 'press' depending on the switch position
{50,51,52}
};

void setup()   
{                
  Serial.begin(9600);
  for (int i = 0; i < switch3PNumber; i++)  // Set the pullup resistors on the actual ports
  {
    for (int x = 0; x < 2; x++)
    {
      pinMode(switch3PPins[i][x], INPUT_PULLUP);
    }
  }

  Joystick.useManualSend(true);
}

void loop()                     
{
  for (int x=0; x < switch3PNumber; x++)
  {
    if (digitalRead(switch3PPins[x][0]) == LOW) // If button 1 in down then press it
    {
      Joystick.button(switch3PButtons[x][0], 1);
      Joystick.button(switch3PButtons[x][1], 0);
      Joystick.button(switch3PButtons[x][2], 0);      
      //Serial.println(" 1, 0, 0 ");
    } else if (digitalRead(switch3PPins[x][1]) == LOW)    // If button 2 is down the press it
    {
      Joystick.button(switch3PButtons[x][0], 0);
      Joystick.button(switch3PButtons[x][1], 0);
      Joystick.button(switch3PButtons[x][2], 1);   
      //Serial.println(" 0, 0, 1 ");
    } else // If neither button is down push the ghost button
    {
      Joystick.button(switch3PButtons[x][0], 0);
      Joystick.button(switch3PButtons[x][1], 1);
      Joystick.button(switch3PButtons[x][2], 0);      
      //Serial.println(" 0, 1, 0 ");
    }
  }
  Joystick.send_now();
  delay(25);
}

 

  • Like 1
Link to comment
Share on other sites

33 minutes ago, Raisuli said:

The code looks like this.  One button is always down; either one of the two real buttons, or a third 'ghost' button that's active any time the others aren't.  I wrote it with arrays so adding new button sets would be easy.

[CODE DELETED FROM QUOTE]

You should probably add previous state comparison to that to avoid glitching.
And I'd use Switch/Case to keep it simple:
 

#include <Joystick.h>

// Create Joystick
Joystick_ Joystick;


#define SwitchNamePin1 2   // Switch input pins
#define SwitchNamePin2 3
int SwitchNameStat = 0;    // Current state of switch
int SwitchNamePrev = 5;    // Previous state of switch
// Previous state intialised with an impossible number so that the state code will run at reset.

int SwitchNameButtons[3] = {31,30,29}; // Buttons to 'press' depending on the switch position
// Button numbers here are button number-1. i.e. 0 here is 1 to computer

void setup()
{
 pinMode(SwitchNamePin1,INPUT_PULLUP);
 pinMode(SwitchNamePin2,INPUT_PULLUP);

  // Initialize Joystick Library in manual send mode to avoid glitching
    Joystick.begin(false);

}

void loop()
{
   //Read the two inputs and make them into a single number
  SwitchNameStat = digitalRead(SwitchNamePin1) + digitalRead(SwitchNamePin2)*2; 

  //Compare the new number with the old
  if (SwitchNameStat != SwitchNamePrev){

    // Do this if they're different
  switch(SwitchNameStat)
  {
    case 0b00000001:  // UP
      Joystick.setButton(SwitchNameButtons[0], 1);
      Joystick.setButton(SwitchNameButtons[1], 0);
      Joystick.setButton(SwitchNameButtons[2], 0);
      break;

    case 0b00000010:  // Down
      Joystick.setButton(SwitchNameButtons[0], 0);
      Joystick.setButton(SwitchNameButtons[1], 0);
      Joystick.setButton(SwitchNameButtons[2], 1); 
      break;
   
    default:  //  Middle or disconnected
      Joystick.setButton(SwitchNameButtons[0], 0);
      Joystick.setButton(SwitchNameButtons[1], 1);
      Joystick.setButton(SwitchNameButtons[2], 0);  
  }

   // Set previous state to current state for next loop
  SwitchNamePrev = SwitchNameStat;  
  }

// Everything else for the loop goes here

// Finally, send joystick state
  Joystick.sendState();
}

This works on a Leonardo.

  • Like 1
Link to comment
Share on other sites

7 hours ago, No1sonuk said:

You should probably add previous state comparison to that to avoid glitching.
And I'd use Switch/Case to keep it simple:
 

#include <Joystick.h>

// Create Joystick
Joystick_ Joystick;


#define SwitchNamePin1 2   // Switch input pins
#define SwitchNamePin2 3
int SwitchNameStat = 0;    // Current state of switch
int SwitchNamePrev = 5;    // Previous state of switch
// Previous state intialised with an impossible number so that the state code will run at reset.

int SwitchNameButtons[3] = {31,30,29}; // Buttons to 'press' depending on the switch position
// Button numbers here are button number-1. i.e. 0 here is 1 to computer

void setup()
{
 pinMode(SwitchNamePin1,INPUT_PULLUP);
 pinMode(SwitchNamePin2,INPUT_PULLUP);

  // Initialize Joystick Library in manual send mode to avoid glitching
    Joystick.begin(false);

}

void loop()
{
   //Read the two inputs and make them into a single number
  SwitchNameStat = digitalRead(SwitchNamePin1) + digitalRead(SwitchNamePin2)*2; 

  //Compare the new number with the old
  if (SwitchNameStat != SwitchNamePrev){

    // Do this if they're different
  switch(SwitchNameStat)
  {
    case 0b00000001:  // UP
      Joystick.setButton(SwitchNameButtons[0], 1);
      Joystick.setButton(SwitchNameButtons[1], 0);
      Joystick.setButton(SwitchNameButtons[2], 0);
      break;

    case 0b00000010:  // Down
      Joystick.setButton(SwitchNameButtons[0], 0);
      Joystick.setButton(SwitchNameButtons[1], 0);
      Joystick.setButton(SwitchNameButtons[2], 1); 
      break;
   
    default:  //  Middle or disconnected
      Joystick.setButton(SwitchNameButtons[0], 0);
      Joystick.setButton(SwitchNameButtons[1], 1);
      Joystick.setButton(SwitchNameButtons[2], 0);  
  }

   // Set previous state to current state for next loop
  SwitchNamePrev = SwitchNameStat;  
  }

// Everything else for the loop goes here

// Finally, send joystick state
  Joystick.sendState();
}

This works on a Leonardo.

How would I use this though? Do I download a basic joystick library to the arduino mega and then add this code for each 3 way toggle, or 2 way toggle? 

Maybe I need some "Arduino 101 tips" 🙈🤣

Is there a recommended library to download for this? 

Link to comment
Share on other sites

7 hours ago, MarkBLN said:

How would I use this though? Do I download a basic joystick library to the arduino mega and then add this code for each 3 way toggle, or 2 way toggle? 

Maybe I need some "Arduino 101 tips" 🙈🤣

Is there a recommended library to download for this? 

As Raisuli said, download the Arduino IDE, then install the joystick library into the IDE.
I use this one:
https://registry.platformio.org/libraries/mheironimus/Joystick

The #include <Joystick.h> line then tells the IDE compiler to use that library.
How many switches are you intending on using?  If it's a lot, you might want to mix in Raisuli's 2D array code.

Link to comment
Share on other sites

3 hours ago, No1sonuk said:

As Raisuli said, download the Arduino IDE, then install the joystick library into the IDE.
I use this one:
https://registry.platformio.org/libraries/mheironimus/Joystick

The #include <Joystick.h> line then tells the IDE compiler to use that library.
How many switches are you intending on using?  If it's a lot, you might want to mix in Raisuli's 2D array code.

Don't know how many yet. I guess I'll come close to maxing out the mega. 

2 hours ago, No1sonuk said:

I just read that the joystick library doesn't work with the Mega - I think it has the wrong processor.

Ah ok. I found something called unojoy that has mega suppert. Should that do the job? 

Link to comment
Share on other sites

1 minute ago, MarkBLN said:

Don't know how many yet. I guess I'll come close to maxing out the mega. 

The reason I went with Teensy over Arduino originally was the outrageous number of digital pins it had.  You can use I2C to make up for the lack of pins, though.  8x16 port I2C chips is 128 buttons, which is all you get with DirectX anyway.  128 buttons and 8 axis/sliders.

Speaking of which, I need more 16 port I2C chips.

Welcome to the wonderful world of Panel Creep(tm), where you originally decide all you really need is landing gear and master arm, but you end up with the Starship Enterprise... Without actually adding everything together I'm over 300 button positions and around 20-ish axis.  Not counting throttle, stick, pedals, and 3 Cougar MFDs.

Link to comment
Share on other sites

On 6/11/2022 at 3:34 PM, MarkBLN said:

Hey guys. 

I'm going to build my first panel and wanted some advice. Originally it was going to be an F18 panel that had most of the important  switches combined into one panel. Then I decided to make it a bit more general to use with something else, like maybe the apache, also msfs2020. 

The original plan was to use DCS bios, but as I want it to be more general and also msfs2020 compatible, I think setting it up as a joystick is the best? 

if we talking strictly input then I would suggest taking a look at "Community Keybinds". this allows to set an action to be triggered when the switch is set to off (returned to center position) organically without any middleware. 

 

  • Like 1

Anton.

 

My pit build thread .

Simple and cheap UFC project

Link to comment
Share on other sites

  • 2 weeks later...

I was looking into using relays to do the on-off to on-on & on-off-on to on-on-on conversion in hardware. 

If I use a 5v relay strip of 16, or two of them, is it safe to run them from the arduino 5v power directly, or would they need their own power? 

Link to comment
Share on other sites

It depends on the coil current and how many you're going to have running at once.

Arduino regulators don't have massive amounts of current capacity.

Plus remember that inductive loads like relays need "flyback diodes" to prevent damaging the driver electronics with a back-EMF pulse when they turn off.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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