Check switches positions with OpenXSensor

Development & General Chat for the superb openxvario project.

Moderator: rainer

Post Reply
User avatar
OpenMik
Posts: 26
Joined: Thu Jan 12, 2017 10:20 am
Country: Italy

Check switches positions with OpenXSensor

Post by OpenMik »

I need to check positions of some switches on board the model
I thought to assign a different weight by resistors to each switch in order to obtain a different level of voltage
on radio a LUA routine may decode the analog signal into a binary number
There is no other possibility?

mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Check switches positions with OpenXSensor

Post by mstrens »

How many switches and how many positions do you want to decode?
OpenxXsensor allows to decode easily 6 voltages.
For each voltage being measured, depending on the number of resistors being used, you can probably decode between 2 and 8 positions (perhaps even more). So, you could detect up probably about 48 positions.
If you do not need more than 6 switches each with 2 positions, the easiest is to measure 6 different voltages and to let oXs transmit this in 6 different fields (like accX, AccY, AccZ, T1, T2 and VFAS). Then you can decode it in the Tx setting up just logical switches. So you do not need Lua routine.
User avatar
OpenMik
Posts: 26
Joined: Thu Jan 12, 2017 10:20 am
Country: Italy

Re: Check switches positions with OpenXSensor

Post by OpenMik »

Thank you for answer
at the moment up to 4 switches with 2 positions
are 8 different voltage level
I think only one field is enough
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Check switches positions with OpenXSensor

Post by MikeB »

If you want to encode 4 switches, each with 2 positions, you need 16 voltage levels, not 8.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
OpenMik
Posts: 26
Joined: Thu Jan 12, 2017 10:20 am
Country: Italy

Re: Check switches positions with OpenXSensor

Post by OpenMik »

Yes
2^4

mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Check switches positions with OpenXSensor

Post by mstrens »

If you just need 4 switches (each with 2 position), it seems me easier to use 4 analog pins on arduino.
Each pin is connected in following way:
One pin of switch is connected to ground
Other pin of switch is connected to an Arduino analog pin and to a resistor (e.g. between 1K and 30k).
Other pin of resistor is connected to Arduino Vcc.
So depending on switch position, voltage is or ground or Vcc.
Each voltage can be sent is an separate field to Tx
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Check switches positions with OpenXSensor

Post by jhsa »

Just a reminder here that the receiver also has analog ports.. The D series receivers have 2 of them. I also have a little project that will tell me for example if the landing gear is down and locked in place. Never got to work on it yet though :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Check switches positions with OpenXSensor

Post by MikeB »

The following may be of interest:
Use a 2200 ohm pull up resistor, then connect two switches to ground, one with a 2200 ohm resistor and the other with a 3900 ohm resistor connecting to the pull up resistor.
This way you generate 4 voltages (assuming a VCC of 5V):
5V
3.2V
2.5V
1.95V

With an analog to digital converter of 1024 steps (0-1024), these give converted values of (8-bit 0-255 in brackets):
1023 (255)
654 (163)
512 (128)
399 (99)

If these are sent to the Tx unchanged (as say T1), then use 3 logical switches to decode the 2 switches at the Rx (I'm using ersky9x but openTx is VERY similar):
L1: v<val T1 540
L2: v>val T1 420 AND L1
L3: v<val T1 720 AND !L2
Then L1 gives one switch position and L3 gives the other.
(use 135 instead of 540, 105 instead of 420 and 180 instead of 720 for an 8-bit conversion (e.g. from a 'D' receiver analog input).

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
OpenMik
Posts: 26
Joined: Thu Jan 12, 2017 10:20 am
Country: Italy

Re: Check switches positions with OpenXSensor

Post by OpenMik »

Another strange idea

Acquire switches state by a shift register and send this value by a byte to radio (up to 8 input are possible)
In this case is possible to use a existing field or a new custom sensor creation is needed?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Check switches positions with OpenXSensor

Post by mstrens »

Arduino pro mini has many pins (more than 16).
Only some pins can be used to read analog voltages but all pins can be used to read a digital level (1 or 0).
Some of the pins are used e.g for the telemetry signal to RX, for PPM input, for RPM, for voltage measurements, ...but there is still plenty of free pins.
Current version of oXs does not read the digital status of most pins but it is quite easy to read e.g. 16 pins.
It should then be possible to transmit the "value" resulting from the 16 pins into one telemetry field (e.g. in Temperature 1).
You then have to write some lua code in order to test the value (1 of 0) of each bit in order to know the the position of each switch.
In this case you even do not have to add resistors to oXs because it is possible to activate in Arduino internal resistor that connect each pin to Vcc.
So the switch has just to be connected between Ground and the pin.

As said, this solution is not standard and requires some extra code.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Check switches positions with OpenXSensor

Post by jhsa »

Question for Mike ;)
if the oXs would do as mstrens said above, would it be possible for Ersky9x to do this without scripts.
This could be useful as it would allow us to have some feedback from the model. Not that I need it now, but some others might, and besides, we never know the future. :)
If this could be done without scripts (not really into that anyway), it would be nice..

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Check switches positions with OpenXSensor

Post by MikeB »

Logical switches. There is an option (currently last item) v&val that lets you pick out a single bit or several bits.

So if you send 4 switches as (say) T1, taking values from 0 to 15, 1 bit for each switch, you can easily test a single bit.
Switch 1 is 0 or 1, switch 2 is 0 or 2, switch 3 is 0 or 4 and switch 4 is 0 or 8.
To test for switch 3, just use:
L1: v&val T1 4

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Check switches positions with OpenXSensor

Post by jhsa »

Nice. Had forgotten about that option, maybe because I still don't fully understand it ;) So, then how many switches can we test this way? 4?

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Check switches positions with OpenXSensor

Post by mstrens »

As said you can probably test about 16 switches (each having 2 positions).
Still this requires new code in oXs and some lua code on Tx side.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Check switches positions with OpenXSensor

Post by MikeB »

The val in logical switches is limited to 8 bits, so 8 switches may be tested this way. If you have 16, use a scaler to divide the value by 256, then you can use the scaler output to get at the 'other' 8 bits.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Check switches positions with OpenXSensor

Post by jhsa »

8 switches should be enough.

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

Post Reply

Return to “OpenXVario - an open source vario supported by the open source firmwares!!”