Jump to content

Rotary switch & Arduino help needed


Recommended Posts

I want to use Rotary Switch with Arduino.

 

I have a rotary switch (like so: https://www.ebay.com/itm/Single-Deck-11-WAY-11-Position-ROTARY-CERAMIC-SWITCH-10mm-PCB-Panel-Mount-1P11T/302100041211?epid=2258110725&hash=item465690cdfb:g:IqgAAMXQDfdRxCz-:rk:8:pf:0)

 

... and Arduino Mega 2560 - and I want to make it work using 1K resistors as described in this thread: https://forum.arduino.cc/index.php?topic=340227.0 (post #13 to be specific).

 

So far I've only made simple on-off switch connections with Leo Bodnar board - and I want to verify what I'm doing here is correct (see the attached picture).

 

BLACK WIRE => any of the Mega Digital input ?(it's bit hard to see in the image but the black wire is in the terminal that is constantly connected no matter the switch position).

RED WIRE => any of the Mega GND input ?

 

... Is this correct? And is that all I need to connect, have I understood correctly?

 

Any help appreciated!

 

(Electricity is basically magic to me so please lay it down to me like you would to a child - my desire to build DIY cockpit is far greater than my skill level... But you'll never learn unless you try, huh? :joystick: )

162913162_IMG_20181022_165521(1).thumb.jpg.8e4f369fb468ea26be2fac86a8577de9.jpg

IMG_20181022_165446.thumb.jpg.c72bcfc1af3df6f9a411258a4c17930e.jpg

A-10C Warthog | AJS-37 Viggen | F-5E Tiger II | Mig-15bis | MiG-19P Farmer

Link to comment
Share on other sites

Hi

I haven't used these specific ones. But it looks like you need to connect the common pin to ground (the one that goes on the inner ring) and each of the other pins to a corresponding input.

 

MetalGear_Honk

Edit: the version that you are building needs to connect to a ADC input. and you need to check the Value that you get.


Edited by MetalGear_Honk

The threemost dangerous threads to Programmers:

  • Fresh air
  • Bright sun light
  • The horrifying screams of singingbirds

Link to comment
Share on other sites

Hi

I haven't used these specific ones. But it looks like you need to connect the common pin to ground (the one that goes on the inner ring) and each of the other pins to a corresponding input.

 

Thanks. I think I will do that. Also, there is apparently no support for AJS37 Viggen with the DCS Bios - and it's bit over my head to get it working from scratch.

 

So for now, I think I will go the route I know I can do - Leo Bodnar USB board and connect each of the inputs individually. :joystick:

A-10C Warthog | AJS-37 Viggen | F-5E Tiger II | Mig-15bis | MiG-19P Farmer

Link to comment
Share on other sites

Looks like that this resistors arrange are for use this switch as analog axis - divided in fixed bands and then need use an analog input pin in Arduino, not a digital input (buttons).

 

Is this that you pretend/need?

 

If yes, after you need firmware code instruction or software (DCS BIOS?) for translated this axis bands in useful instruction for commands in game.

 

L.Bondar sell a similar rotary switch but with diode PCB that make him work like a encoder.

 

The advantage - over an ordinary encoder, is the positive click of rotary switch when change between positions.

Link to comment
Share on other sites

The advantage - over an ordinary encoder, is the positive click of rotary switch when change between positions.

 

Yeah, gotta love the solid feedback of a rotary switch.

 

Resistor approach seemed inviting as an input saving method - even more so as the Viggen has quite a few rotaries.

A-10C Warthog | AJS-37 Viggen | F-5E Tiger II | Mig-15bis | MiG-19P Farmer

Link to comment
Share on other sites

Hi

As for using the Analog input in Arduino.

{

int Rotary1;

int RotaryPosition;

Rotary1= analogRead(A0);

RotaryPosition = round ( Rotary1 / (1024/11));

}

I don't have the Arduino IDE here. So it might not be spelled correctly, and I cannot test it at all.

The Idea is to split the Input Voltage between the pins so the Analog Value is separated.

MetalGear_Honk

The threemost dangerous threads to Programmers:

  • Fresh air
  • Bright sun light
  • The horrifying screams of singingbirds

Link to comment
Share on other sites

Hi

As for using the Analog input in Arduino.

{

int Rotary1;

int RotaryPosition;

Rotary1= analogRead(A0);

RotaryPosition = round ( Rotary1 / (1024/11));

}

I don't have the Arduino IDE here. So it might not be spelled correctly, and I cannot test it at all.

The Idea is to split the Input Voltage between the pins so the Analog Value is separated.

MetalGear_Honk

 

Ah - analog, makes much more sense. Looking back at the thread again - you would need to connect both ends of the resistor 'chain' to ground, and the middle to analog input if I understood correctly? Or would that be the other way around?

 

Originally I wanted to go DCS Bios/Arduino route as it looked it has many possibilities & I wanted to try to get blinking master caution & autopilot lights (for the Viggen). But I will probably end up going Leo Bodnar route & add some Arduino, IF there's gonna be somekind of support for Viggen with the DCS Bios. I tried to research how to pull the keyboard commands from the files, but I didn't get very far how to actually implement them on Arduino. Like I said, I'm bit over my head :helpsmilie:

A-10C Warthog | AJS-37 Viggen | F-5E Tiger II | Mig-15bis | MiG-19P Farmer

Link to comment
Share on other sites

There are two ways of wiring up this switch to the Arduino Mega:

 

1. Wire up GROUND to the common terminal (the terminal that connects to every arm), then connect each arm of the switch into its own input pin on the Arduino Mega. This is the simple way, since you can read each input pin directly. You will need to set each input pin as INPUT_PULLUP so that when it's not connected to anything, it will be HIGH. When the switch is turned so that it makes a connection from GROUND to the input pin, it will be LOW, and that's how the Arduino knows that the switch is 'pressed'.

 

https://www.arduino.cc/en/Tutorial/DigitalPins

 

rotary.png

 

2. Wire up each arm of the switch so that it acts as a voltage divider and treat the switch as if it was an analog axis. Each switch will then occupy a 'band' on the axis, and using software you can determine which position the switch is in depending on the analog axis value. The advantage of doing it this way is that you only need one analog input, but the downside is that it's more difficult to set up and requires software support.

 

rotary_a.png

 

Right now you're trying to do #2, but it sounds like you don't have a good grasp of what you're trying to do, so I recommend that you switch to #1 instead. It requires a lot more pins, but it's also a lot easier to understand, and unless you plan to implement a ton more controls, the Mega has enough pins to spare.

 

As for DCS BIOS, I find that unless you know what you're doing, it's not a good place to start. DCS BIOS interfaces directly with the sim and gives you access to more controls than you would normally have access to, but it also needs to support the aircraft and you really need a solid understanding of how it works to use it effectively.

 

For most people, what they really want is just a button box that looks like a joystick device and can be bound through the DCS controls configuration. In this case, I recommend looking into MMJoy2. You will have to pick up a new board because only certain ones are supported:

 

https://github.com/MMjoy/mmjoy_en/wiki/Controllers-(compatible-base-boards

 

But it gives you a lot of flexibility in how you want to configure each control. The downside is that MMJoy2 is not exactly user-friendly and it takes a while to figure out, even if you know what you're doing (the docs are ok, but not great).

 

Another viable option is to pick up a Teensy 3 and use its USB joystick library:

 

https://www.pjrc.com/teensy/td_joystick.html

 

It's a little easier to use, especially if you have programming experience, but you lose out on being able to define axis curves, deadzones, hysteresis, etc. that MMJoy2 gives you.

 

If you want to stick with the Arduino Mega though, you'll either have to use DCS BIOS, or find a way to get it to act as a USB joystick, though this is definitely very involved: https://electronics.stackexchange.com/questions/61260/how-do-i-get-my-arduino-mega-2560-registered-as-a-game-controller


Edited by Ranma13
Link to comment
Share on other sites

As for DCS BIOS, I find that unless you know what you're doing, it's not a good place to start. DCS BIOS interfaces directly with the sim and gives you access to more controls than you would normally have access to, but it also needs to support the aircraft and you really need a solid understanding of how it works to use it effectively.

 

For most people, what they really want is just a button box that looks like a joystick device and can be bound through the DCS controls configuration. In this case, I recommend looking into MMJoy2.

 

Thanks a lot for your awesome info anyway - it all helps me grasp how these things work. And you are probably correct - I will approach DCS Bios / Arduino on a later date on some simpler thing for a plane which is better supported.

 

I've done basic button box stuff using Leo Bodnar boards and Xpadder - and it works great. I guess I will start there this time too.

A-10C Warthog | AJS-37 Viggen | F-5E Tiger II | Mig-15bis | MiG-19P Farmer

Link to comment
Share on other sites

  • Recently Browsing   0 members

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