However, this is an internal temperature which is much higher than the temperature of the air due to internal heating. Thus, I have integrated an additional temperature sensor in order to overcome this issue.
There are several temperature sensors available on the market. Some of them are based on i2c (LM75), others on onewire (DS18S20), and others are analog (LM35, KT110).
I have implemented an analog LM35, which has a third pin as output and therefore it can be connected easily to a free analog input of the board.
There exist several sensors of the LM35 family, which differ in accuracy, temperature range, and costs. I bought the cheap LM35DZ for just 1.10€ which has a resolution of 0.25°C and a temperature range from 0°C onwards. It fits to my purpose since I don't use to fly when it is too cold...
What I did was enabled the temperature measurement in config.h via
Code: Select all
/********************************************************************/
/**** temperature monitoring ****/
/********************************************************************/
#define TEMPERATURE LM35
#define TEMPERATURE_SMOOTH 32
than defining the pin being used for the temperature measurement in the section of the used microcontroller (in my case MEGA) in file def.h
Code: Select all
#define TEMPERATUREPIN A1 // Analog Pin 1 for temperature measurement by LM35
I inserted the used variable in the analog structure of file types.h as follows.
Code: Select all
typedef struct {
uint8_t vbat; // battery voltage in 0.1V steps
uint16_t intPowerMeterSum;
uint16_t rssi; // range: [0;1023]
uint16_t amperage;
#if defined (TEMPERATURE)
uint16_t temp; // temperature in 0.01°C steps by LM35
#endif
} analog_t;
The actual code is being placed in the switch loop for analog sensors in the file multiwii.cpp. Search for the first lines and change the third line from 3 to 4 cases.
Code: Select all
// query at most one multiplexed analog channel per MWii cycle
static uint8_t analogReader =0;
switch (analogReader++%4) {
Than I added the code as a switch-case.
Code: Select all
case 3:
{
#if defined(TEMPERATURE) && (TEMPERATURE == LM35)
static uint8_t temp_ind = 0;
static uint16_t temp_vec[TEMPERATURE_SMOOTH], temp_sum;
uint16_t temp = analogRead(TEMPERATUREPIN);
#if TEMPERATURE_SMOOTH == 1
analog.temp = temp * 50; // 0.01V/°C and 5mV/step
#else
temp_sum += temp;
temp_sum -= temp_vec[temp_ind];
temp_vec[temp_ind++] = temp;
temp_ind %= TEMPERATURE_SMOOTH;
analog.temp = (temp_sum / TEMPERATURE_SMOOTH) * 50; // 0.01V/°C and 5mV/step
#endif
debug[3] = analog.temp; // show temperature in debug entry in 0.01°C each step
#endif
}
The result is the temperature in 0.01°C steps, but, due to the accuracy of the analog/digital converter the resolution is just 0.5°C.
I omitted to increase the resolution, since I forward the temperature via FRSKY telemetry to the display FLD-02, which has a resolution of just 1.0°C.
Thus, the result is fine with me. It shows a difference of ca 10°C compared with the barometer's temperature.
Have fun!