Dimmer switch installation for cockpit

Are you building a cockpit, planning to build one or just dreaming, this is your cockpit builder meeting point

Moderators: russ, Ralph

Message
Author
Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Dimmer switch installation for cockpit

#1 Post by Kaellis991 »

While I am waiting to finish up my EGT project, thought I would start looking at another addition to my cockpit build.
I want to add a dimmer potentiometer in my switch panel. (see photo below) The mechanical side of installing the pot and the knob will be the easy part for me.
I have some pots I think I can use. I can 3D print the knob if there is no such thing available to purchase.

But I dont' know what to do next to begin this project and connect a dimmer switch with AM and Xplane.

This is as far as I've progressed...Which is to say not very far...
I've located these three Datarefs in Xplane and found a hardware component in Air Manager that I think can be the basis of a new hardware function. (see images below)

I have some vague ideas of how the LUA scripts work and the idea of variable resistance in a potentiometer but not nearly enough knowledge yet to make these connections on my own.
So where do I begin with this project?

Kirk
Datarefs.jpg
Hardware.jpg
SwitchPanel.jpg

User avatar
jph
Posts: 2853
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Dimmer switch installation for cockpit

#2 Post by jph »

Hi Kirk,
you would use Hw adc input
See - 'Analog Input' https://siminnovations.com/wiki/index.p ... alog_input

Which is a simply a linear potentiometer with a value of anywhere from 1K to 20K with the wiper connected to one of the anolog input pins (adc) on the hardware in use - arduino or pico etc. The supply voltage for the hardware in use (5V or 3.3 depending on what board is used) is connected to the outer two pins of the potentiometer and the wiper is then connected to the adc input pin via a 220ohm resistor. (the 220ohm resistor is standard practice for device port / pin protection - always use it !)

As for the Datarefs and coding I am sure the coding gurus will assist but you will be using the adc_input_change Function as per this page https://siminnovations.com/wiki/index.p ... input_read and the example at the bottom of the page.
This will fire when the pot moves (hence the adc input value changes) and you now have a value. This value is converted to the range and units required for whichever dataref controls the brightness and is then sent to the dataref. That's about it.
Joe
Joe. CISSP, MSc.

JackZ
Posts: 2264
Joined: Mon Feb 22, 2016 1:02 pm

Re: Dimmer switch installation for cockpit

#3 Post by JackZ »

IMHO, it can be easy or …difficult to do!
First things first, what do you want to achieve with this dimmer?

Is it as I suspect to control the brightness of the lighting of the dashboard? If your dashboard is lighted by an 12V led strip, then no need to use AM for this, you’ll simply need a PWM led dimmer such like this:
https://www.amazon.fr/contrôleur-Dimmer ... ng&sr=1-82

On the other hand, If you plan on controlling the internal lighting value of each AM gauge on your screen using this dimmer, this is a less easy path, as you’ll have to get the desired value, THEN transmit this value to all and each of your AM gauges for these to Dim themselves (some code tinkering required)

To get this value to AM, first follow @jph ´s advice.

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Dimmer switch installation for cockpit

#4 Post by Kaellis991 »

Joe,
Perfect! Exactly the info I needed.
Thanks.

Kirk

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Dimmer switch installation for cockpit

#5 Post by Kaellis991 »

Jacques,

This dimmer is not for controlling any physical lighting in the real world. It’s only use would be to change the light intensity of the panel in the virtual world of Xplane.

Edit:
The switch in Xplane changes the lighting of all the gauges simultaneously using those (3) datarefs when I use the mouse to roll the virtual switch up and down. Don’t want to have to use the mouse to do that if I can get this to work.

Kirk

User avatar
jph
Posts: 2853
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Dimmer switch installation for cockpit

#6 Post by jph »

Hello Jacques @JackZ
Good point regarding the basic lighting !. I immediately thought of gauge.
It would be interesting to use a cheap power mosfet with AM using the PWM output and Analog input from a pot to give the same thing. It would only cost a euro or two. It would be simple to also drive various mosfets at differing levels from the same analog input stimulus to AM. this would allow, for example, multiple illumination strips to be set for appropriate brightness levels from a single input and fully adjusted in code.

I have also been looking at controlling LCD monitor brightness from AM and will hopefully publish this at a later date, but basically it is a system to tap into the existing PWM control for the brightness level that is inherent to virtually all screens. Am takes over the PWM to the existing driver and the internal monitor settings (for brightness only) are ignored and all is done in code. This can all be tailored for individual monitors from the larger units to the small 5" etc. I have a system that has been tested and working with a generic LCD driver with the RTD2660 and a ZJ050NA. The same principle applies to virtually any LCD panel / monitor / TV.

I have just ordered a couple of surplus 18.5" HP LCD monitors for modification and use. I just need to get them back from the UK.
AM is perfect for this. We can have real and balanced dimming ('brightness') on any and all LCDs in a cockpit from a single small unit to a full panel. Let me know if it is of interest ?
Joe
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Dimmer switch installation for cockpit

#7 Post by Kaellis991 »

I've got good news and I have some bad news.

I was able to create an AM hardware_function by following an example in the "Potentiometer connection tutorial" by using and trying all the datarefs for the instrument brightness.
There are (5) such datrarefs...see below.

I got one of the datarefs to work in my code, but unfortunately the code connects to and rotates the NAV light dimmer switch and not the instrument panel dimmer switch.
My Arduino connection is also working with a pot that I have connected to A0 on my Uno.

I swapped out each dataref in my code but cannot get the correct dimmer to move. In fact nothing happens with any of the datarefs except
"sim/cockpit2/switches/instrument_brightness_ratio[32]" which turns the wrong dimmer.

The relationship between the two switches and the (5) datarefs has me in a tailspin. The battery switch also changes how they interact.
It would take me two cups of coffee and a couple of bathroom breaks before I could explain it all using a keyboard.
Perhaps I should take this over to Discord...

Here is what I see in the Xplane DatarefTool and what I have created in AM.
As I said above I can get the left dimmer to work, but I can't get the right dimmer to move.
So there is much more to this dataref and LUA programming than meets the eye of this rookie.

EDIT: I'm not sure how this helps with the troubleshooting, but I wanted to pass this tidbit along.
When the battery is OFF, rotating the NAV dimmer (using the mouse) changes the top and bottom datarefs (of the 5)....
rotating the instrument dimmer changes only the bottom dataref.
TOP = sim/cockpit/electrical/instrument_brightness
BOTTOM = sim/cockpit2/switches/instrument_brightness_ratio[32]

With the battery ON....NAV dimmer changes all five datarefs and
instrument dimmer changes all except the top dataref...

Also found a small typo in the code....('cockpit2' changed to 'cockpit' in the top dataref)

EDIT2:
I will stop here with the additional edits.
I am trying to understand the numbers displayed to the right of the 'sim/cockpit2/switches/instrument_brightness_ratio' dataref.
32 numeric values
Digits 1 and 4 change as the NAV dimmer rotates
Digit 3 changes in response to the instrument panel light dimmer...
[1.,0.,1.,1.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
[0.55,0.,0.55,0.55,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]

The top values above indicate the NAV dimmer full brightness with digits 1 and 4 values set at 1 and the instrument lights full brightness with the third digit set at 1.
The bottom values indicate the dimmers at about half brightness.
Again only the 1, 3 and 4 digits change.

How do I write that into the code?


AM Hardware.jpg
Datarefs 5.jpg
Last edited by Kaellis991 on Sun May 22, 2022 4:53 pm, edited 3 times in total.

User avatar
jph
Posts: 2853
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Dimmer switch installation for cockpit

#8 Post by jph »

Hi Kirk :D
Seems like you are having fun ;)
I have no idea about the discord thing as it is not something I have ever used or indeed would ever use but I think Keith @Keith Baxter uses it.
I am sure you will sort it.
Joe
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Dimmer switch installation for cockpit

#9 Post by Kaellis991 »

Joe,
Keith helped me out on Discord some months ago when working on the Autopilot coding.
He was of great help with the scripting.

User avatar
jph
Posts: 2853
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Dimmer switch installation for cockpit

#10 Post by jph »

Kaellis991 wrote: Sun May 22, 2022 3:31 pm Joe,
Keith helped me out on Discord some months ago when working on the Autopilot coding.
He was of great help with the scripting.
Excellent, he knows his stuff. A really good coder.
Joe. CISSP, MSc.

Post Reply