* 6.5 - Current sensor parameters **************************************************************************************
* It is possible to measure a current (and current consumption) if a current sensor is connected.
* Connecting a current sensor is an optional feature.
* It requires some additional hardware. It can be an IC like ACS712 (for 5, 20, 30 amp) or ACS758 (for 50, 100, 150, 200 amp).
* Most sensors can read bidirectional currents but ACS758 has "U" types that read only unidirectional current (providing then an higher sensitivity).
* Those current sensors are quite cheap (see e.g. ebay) and return a voltage that depends on the current. This voltage is measured by OXS via an analog pin.
* The Pin value to enter in the oXs_config.h is a number from 0 up to 7 (0 means A0, 1 means A1, ...7 means A7).
* If a current sensor is used, do not to use a pin that is already used by a voltage.
* !! Take care that the voltage applied to Arduino pin may not exceed Vcc (normally 5 volt) or 1.1 volt (if internal reference voltage is used).
* It can be that you have to use a voltage divider in order to reduce the voltage applied on Arduino pin.
* See explanation above (6.2) about voltage divider.
* Take care : do NOT use pins A4 and A5 if you use a vario or an airspeed (those pins are reserved for the barometric and pressure sensors).
* Note: The current sensor is normally powered by the 5 volt VCC from OXS (same as the vario sensor).
* There are bidirectional sensor and unidirectional sensor.
* For bidirectional, output is normally equal to VCC/2 when current = 0 Amp and, for unidirectional, output is normally 0,6 volt at 0 Amp.
* If OXS is connected to a battery giving less than 5.2 volt, the supply voltage for the current sensor will vary with the OXS supply voltage.
* Therefore VCC/2 ( = O amp) will varies with VCC.
* This is an issue if the Arduino ADC is configured to use the 1.1 volt internal reference.
* So, in this case it is better to configure the ADC in order to use VCC as reference for conversion.
* In order to use a current sensor, you have to uncomment the line //#define PIN_CURRENTSENSOR and specify the Arduino pin connected to the current sensor.
* You must also define 2 parameters depending of the type of sensor being use; those parameters are given in the datasheet of the sensor).
* - MVOLT_AT_ZERO_AMP = milliVolt generated by the sensor when current is 0 Amp: normal value is :
* - for a bidirectional sensor : Vcc from current sensor / 2 (so = 2500 if sensor is connected to Arduino Vcc and Arduino Vcc is 5 Volt).
* - 600 for unidirectional sensor
* - MVOLT_PER_AMP = milliVolt per Amp. The value depend on the sensitivity of the sensor (e.g. an ACS712ELCTR-30A-T has a sensitivity of 66 mvolt/A, a ACS758LCB-050U has a sensitivity of 60 mv/Amp)
*
* If you use the 1.1 internal reference to measure voltagse and current, you must also use a voltage divider in order to scale down the voltage produced by the current sensor.
* See the section 6.2 above about voltage divider. The principle are just the same but the names of the 2 paraameters are:
* - RESISTOR_TO_GROUND_FOR_CURRENT
* - RESISTOR_TO_CURRENT_SENSOR
* Note: those parameters are automatically discarded when PIN-CURRENTSENSOR is not defined (= set as comment).
* Note: When current sensor is used, oXs can also calculate and transmit current consumption (milliAh) and Fuel (in % going down from 100% to 0%).
* If you want the last one, then use a setup like "Fuel , MILLIAH , -100 , 4000 ,0" in "data to transmit section" (and replace 4000 by the capacity - in milliAmph - of your battery) (see below).
* Still, with Tx using openTx or Ersky9x software, it is better to let the Tx calculates those values by it self based on the current.
* This ensure that values are consistent; it allows to reset the values on Tx side; it allows to change the value of the battery capacity on Tx side (so without having to reload another set up in Arduino oXs).
* E.g on Ersky9x, in Telemetry menu set up "current source" set "FAS"; in "mAh Alarm", set the mah you want for alarm to sound and select warning sound/voice,
* ie 70% of 2200 mAh lipo, use 1540. then the FUEL percentage will start from 100% count down to 0% when 1540 is consumed.
************************************************************************************************************************
//#define PIN_CURRENTSENSOR 2
#define MVOLT_AT_ZERO_AMP 600
#define MVOLT_PER_AMP 60
#define RESISTOR_TO_GROUND_FOR_CURRENT 10
#define RESISTOR_TO_CURRENT_SENSOR 40