Jump to content

DCS-BIOS: How to connect Pots and Switches to an Arduino NANO


Tekkx

Recommended Posts

Initially: This should neither become a real DCS-BIOS article, nor I want to compete with the other "Big Explainers" :).

But as there appeared different questions (as this, for example) I decided to write a short roundup of the more simple things. Here: Connecting Buttons..

This is also not a complete essay of the matter! There are so many kind of switches available... and there are also Rotary Encoders...

All written Information are substantially valid to other Members of the Arduino/Genuino-Family.

If I get new ideas, I will add them here in this post. So put your attention to "last edited...".

 

If you ask for more information, look at this userguide. The authors put a lot of work into that. Don't offend them by ignoring this notably piece of "paper".

 

Now here comes, what I wanted to tell you (beginners):

 

The NANO has 8 analog Inputs and 12 digital Inputs/Outputs.

Analog-Pins A0 to A5 can we use to connect one Pot (a Pot-entiometer is a variable Resistor) or Switch each. If we connect Push-Buttons or Switches to these Pins, they have to act like digital Inputs. This - the behavior of a Pin - is managed by the code.

 

Pins A6 and A7 are just usable as analog Inputs. This means, we can just connect one Pot (no Switches!) each there.

Pins D0 and D1 are used for serial Communication. So I would never touch (or misuse) them. :)

 

nano_pins5_ok.jpg

 

Aside from these analog Inputs and Outputs the NANO provides 12 useabel digital Inputs and Outputs. These Pins are available if we connect the NANO the conventional way: by DCSBIOS_IRQ_SERIAL (short for noobs: USB).

If we follow the RS-485-"path", there is one more digital Pin occupied for RS-485-Communication. Usually is this D2.

 

So there are

  • 6 (A0 to A5) analog Pins, useable as Input for Switches or Pots
  • 2 (A6 and A7) analog Pins, useable just for Pots
  • 11 (D3 to D13) digital Pins, useable as In- or Outputs.

 

Some of the digital Pins provide also the capability of a PWM (pulse width modulation) signal (marked with a small Asterix * at the Sketch). I use one of them (commonly D3) for Backlighting the relevant panel.

So there left

  • 6 (A0 to A5) analog Pins, useable as Input for Switches or Pots
  • 2 (A6 and A7) analog Pins, useable just for Pots
  • 10 (D4 to D13) digital Pins, useable as In- or Outputs.

As we can use digital Outputs also for driving a LED or (with appropriate amplification) some LEDs or Bulbs, answering Mr_Burns Question: "How many Switches are to connect to one NANO?" becomes some complicated. :)

 

Straight we can connect one Push-Button to each Input. Each On-OFF-ON-Switch will consume two (2) of them.

In this case, Buttons and Switches join one Output-Pin to Ground. This will drag (pull down) the logic level of the present voltage to Ground. An internal Resistor of about 10 KiloOhms prevents the cirquit from a "short" and burning the Microcontroller.

If we need more Switches and Bttons than one NANO can provide, we could use more of them or we build a Matrix, while a Matrix is a table-like Structure, consisting of Rows and Columns. Each Cell of this Table represents one Button, one ON-OFF-Switch or one ON-Position of a ON-OFF-ON-Switch.

In this case, each Button or Switch joins one specific Output-Pin to a specific Input-Pin. This combination gives one of the (columns multiplied by rows) output-values.

 

If we have all Ins and Outs available, this means one NANO can (if one digital Out is used for other matters):

6 x 10 = 60 (all analog Ins are configured as Row) Switch(positions) or

7 x 9 = 63 (additional one digital In is configured as Row)

8 x 8 = 64 (additional two digital Ins are set as Row).

 

If you want to look at an example, I did - with the help of Hansolo - a [thread=195285]Switch-Matrix for a CDU here[/thread].

 

Building a Matrix is just possible with Buttons or Switches (not with Pots). If there are Switches (or if you intend to press more than one Button at one time, you have to "isolate" these Pins by a Diode (each). Anode has to be connected to the Column-Pin, Cathode (where the Line on the package is) to the Row-Pin. Current flows from Output (Column) to the Input (Row).

 

char keys[ROWS][COLS] = {  
// Define the Keymap / upper and lower cases matter
// D3, D4 , 5,  6,  7,  11, 10, 9,  8
 {'1','2','3','4','5','6','7','8','9'}, // 12
 {'0','q','w','e','r','t','z','u','i'}, // 13
 {'o','p','a','s','d','f','g','h','j'}, // A0
 {'k','l','(','%','#','<','y','x','c'}, // A1
 {'v','b','n','m','Q','W','E','R','T'}, // A2 - R5
 {'Z','U','I','O','P','A','S','D','F'}, // A3
 {'G','H','J','K','L','Ö','Ä','>','Y'}, // A4
 {'X','C','V','B','N','M',';',':','+'}  // A5
};
// Connect Matrix Rows and Columns to these Arduino pins.
byte rowPins[ROWS] = { 12, 13, A0, A1, A2, A3, A4, A5 };
byte colPins[COLS] = {  3,  4 , 5,  6,  7, 11, 10,  9, 8 };

Different to my example above I have used in the CDU also D3 (just written as "3") as I don't need it there for the Backlight (There are provided two different backlights and a CDU-ON-signal by a second NANO).

So it came a 9x8-Matrix out. Maximum: 72 Buttons on one single NANO. Wow!

 

If you have further questions (not touching DCS-BIOS directly): Ask it here(!) or open a new thread with your problem. :)


Edited by Tekkx
  • Like 1

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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