"Translate" Exponential Filter value to float or double?

Hi!
I need some help to “translate” a filtered value (Exponential Filter) to a float or double (?) so I can proceed to use the value in an equation. Please see attached code.

I want to be able to use ‘cltFilter’ value inside the thermistor formula as ‘clt’ but the IDE won’t let me :stuck_out_tongue:
Also, I want to use oilpressFilter and voltFilter in the float conversion (mapping) equations.

How can I achieve this? Doesn’t seem too hard to me, but I don’t know where to find the info.

Sketch attached here:

#include "MegunoLink.h"
#include "Filter.h"
#include <Wire.h> 
#include <Adafruit_SSD1306.h> 

#define OLED_RESET 4
Adafruit_SSD1306 display;      // This display increases memory use from 17% - 72%.

// Create a new exponential filter with a weight of 30 and initial value of 0. 
ExponentialFilter<long> cltFilter(30, 0);
ExponentialFilter<long> oilpressFilter(30, 0);
ExponentialFilter<long> voltFilter(30, 0);

int oilpressValue = 0;       // value read from the oil press sender
int battvoltValue = 0;       // value read from batt volt input
int  oildispValue = 0;       // calculated output value for oil pressure
int voltdispValue = 0;       // calculated output value for battery voltmeter
int clt = 0;

void setup() 
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
  display.clearDisplay();

  // Startup splash screen
  display.setTextColor(WHITE); 
  display.setTextSize(2); display.setCursor(5, 10); display.print(F("Meisal"));
  display.setTextSize(4); display.setCursor(79, 10); display.print(F("RX"));
  display.display(); delay(1000);
  display.setTextSize(1); display.setCursor(2,55); display.print(F("Display by Tharaldsen"));
  display.display(); delay(1000); display.clearDisplay();
  
}

void loop() 
{
  // filter each input value
  int cltraw = analogRead(0);                   // CLT input at A0
  cltFilter.Filter(cltraw);                     // Namining filtered CLT input 'cltFilter'
  int oilpressraw = analogRead(1);              // Oil Press input at A1
  oilpressFilter.Filter(oilpressraw);           // Naming filtered Oil Press 'oilpressFilter'
  int voltraw = analogRead(2);                  // Voltmeter input at A2
  voltFilter.Filter(voltraw);                   // Naming filtered volt input 'voltFilter'

  float oildispValue = oilpressValue * (8.61 / 1023.0) -0.86;
  float voltdispValue = battvoltValue * (15.0 / 1023.0);

  // Calculates Water temp displayed value
  int Vo;
  int R1 = 1100;
  float logR2, R2, T, cltdispValue, Tf;
  float c1 = 1.308061745e-03, c2 = 2.576124537e-04, c3 = 1.777597735e-07;
  Vo = clt;
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  cltdispValue = T - 273.15; 


// Analog display values sends to OLED:
display.clearDisplay();
display.setTextWrap(false);         // to avoid the decimals to continue on next line
display.setTextColor(WHITE);
  display.setTextSize(1); display.setCursor(1, 5);  display.print(F("Water Temp:")); display.setTextSize(2); if (cltdispValue < 100) {display.setCursor(104, 5);}   else {display.setCursor(92, 5);} display.print(cltdispValue, 0);
  display.setTextSize(1); display.setCursor(1, 25); display.print(F("Oil Press.:")); display.setTextSize(2);                                                              display.setCursor(92, 25); display.print(oildispValue, 1);
  display.setTextSize(1); display.setCursor(1, 45); display.print(F("Batt. Volt:")); display.setTextSize(2); if (voltdispValue < 10) {display.setCursor(92, 45);}  else {display.setCursor(80, 45);} display.print(voltdispValue, 1);
display.display();
delay(100);
}

Please read the "How to use this forum" post and post your code properly, using code tags.

Very few people on this forum will open mystery links.

Note: "double" and "float" are both of type "float" on ATMega-based Arduinos.

Hi!

Sorry for not including code properly, fixed now. :slight_smile:

The values from the exponential filter are INT’s, but when I try to map them, to a readable value on the display, replaceing the “clt” in the calculation with “cltFilter”, i get this error message:

exit status 1
cannot convert 'ExponentialFilter<long int>' to 'int' in assignment

Sounds like you need to look at the examples for the Filter library to see how to get the filtered value out. It appears that treating the filter object as a value is not the right way.

Where did the Filter library come from?

(What on earth is a MegunoLink?!?)

MegunoLink is a software for displaying arduino values on a computer, as far as I understand. http://www.megunolink.com/documentation/arduino-libraries/exponential-filter/ I just added it, so I could use the filters for smoothing my analog inputs.

If you have good suggestions for less memory usage filter, I'd love to hear it. Running out of memory on Arduino Uno with 128x64 i2c oled attached.

Low on memory? Jump up to '1284P based boards. 128K flash, 16K SRAM (twice that of 2560), dual hardware serial, 32 IO. I offer boards in a bunch of form factors. http://www.crossroadsfencing.com/BobuinoRev17/ |500x209

I'd really like to use the Nano, and it has the same memory as the UNO. The UNO is only used to prototype at this point.

From the documentation: "Current() Returns the current value of the filter output." So you should use "cltFilter.Current()" to get the current filtered value.

"I'd really like to use the Nano, and it has the same memory as the UNO. " That's because they both use the same microcontroller, Atmega328P.

johnwasser: From the documentation: "Current() Returns the current value of the filter output." So you should use "cltFilter.Current()" to get the current filtered value.

Yes. And when I use the filtered value in the "float" mapping/scaling, I get the error message above.

eMTea:
The values from the exponential filter are INT’s, but when I try to map them, to a readable value on the display, replaceing the “clt” in the calculation with “cltFilter”, i get this error message:

exit status 1

cannot convert ‘ExponentialFilter’ to ‘int’ in assignment

I’m saying you should replace ‘clt’ with “cltFilter.Current()” instead of just “cltFilter”.

Yes. And when I use the filtered value in the "float" mapping/scaling, I get the error message above.

POST YOUR DAMNED CODE!