frogger Posted October 28, 2019 Posted October 28, 2019 hi guys im just wondering is it required to run diodes with toggle switches when using arduino. i have a mega a micro and a uno and ive noticed some switches are not behaving well when linked to a common ground.
FSFIan Posted October 28, 2019 Posted October 28, 2019 You only need diodes when using a matrix layout. If each switch is connected to its own pin number, no diodes are required. 1 DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
CorporalCarrot Posted October 30, 2019 Posted October 30, 2019 Some pins on some of the boards can have funny interactions if the pins have multiple functions; For example, pin D13 on a nano has the LED like the UNO, but the way this pin is switched between the nano and UNO is different, leading to issues using this pin as an input on a nano. Other problems might be if you are using a pin that is used for serial communication too. I've noticed issues using pins D0 and D1 on some boards for switches, as it can interfere with the communication bus, but I've not figured it out. If in doubt, try your switch on another pin of the Arduino to see if it behaves properly....
frogger Posted October 30, 2019 Author Posted October 30, 2019 it generally worked ok with push buttons but with a toggle switch in the mix i was getting some flickering on that toggle switch, could even be a bad switch. the setup is 11 momentary switches and 2 toggle switches. each have their own data pin but all share the same ground.
FragBum Posted October 30, 2019 Posted October 30, 2019 If you are using port PINS you can set whether there is a pull up, pull down resistor or no resistor when setting the individual PIN or POUT lines. (At least in Assembler) Erratic state detection might be something like a bad "ground" or return between the switches and the controller board. Maybe use a DMM and measure the resistance (with device off) and check each switch and return. Control is an illusion which usually shatters at the least expected moment. Gazelle Mini-gun version is endorphins with rotors. See above. Currently rolling with a Asus Z390 Prime, 9600K, 32GB RAM, SSD, 2080Ti and Windows 10Pro, Rift CV1. bu0836x and Scratch Built Pedals, Collective and Cyclic.
FSFIan Posted October 30, 2019 Posted October 30, 2019 The DCS-BIOS Arduino Library does not implement debouncing yet. The typical tactile push buttons usually do not bounce at all. Toggle switches tend to bounce around for a few milliseconds. Usually, if a switch bounces, it does not cause any issues, as it will settle on a position and that position will be sent last to DCS. If the switch bouncing does cause problems, a simple workaround is to add a small delay, e.g. a call to "delay(10);" to your loop() function. This might cause issues if you are using rotary encoders, though. I will eventually get around to add debouncing logic to the Arduino library. When I first wrote it, I tried to save every single byte of memory I could, so I did not want to allocate two bytes per toggle switch to store a debounce timer. I now realize that memory is not that constrained. Can you describe the issues you have in more detail? Are we talking about a bouncing switch (you get multiple state changes within a few milliseconds when you flip it) or something else? DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
FragBum Posted October 30, 2019 Posted October 30, 2019 Ian;4091828']The DCS-BIOS Arduino Library does not implement debouncing yet. The typical tactile push buttons usually do not bounce at all. Toggle switches tend to bounce around for a few milliseconds. Usually, if a switch bounces, it does not cause any issues, as it will settle on a position and that position will be sent last to DCS. If the switch bouncing does cause problems, a simple workaround is to add a small delay, e.g. a call to "delay(10);" to your loop() function. This might cause issues if you are using rotary encoders, though. I will eventually get around to add debouncing logic to the Arduino library. When I first wrote it, I tried to save every single byte of memory I could, so I did not want to allocate two bytes per toggle switch to store a debounce timer. I now realize that memory is not that constrained. Can you describe the issues you have in more detail? Are we talking about a bouncing switch (you get multiple state changes within a few milliseconds when you flip it) or something else? You could store an (in)port read as a byte table and use callback timer function in AT mega to compare after some ms the byte table to new (in)port read to filter out bounce. Or maybe even some old fashion RC switch debounce. Control is an illusion which usually shatters at the least expected moment. Gazelle Mini-gun version is endorphins with rotors. See above. Currently rolling with a Asus Z390 Prime, 9600K, 32GB RAM, SSD, 2080Ti and Windows 10Pro, Rift CV1. bu0836x and Scratch Built Pedals, Collective and Cyclic.
Recommended Posts