Arduino, Thingspeak & an ESP8266 (Part V)

Fourth Revision: Now We Are Getting Somewhere!

In the fourth revision of this project things finally started to click together for me.

The problem with my last Sketch was that it used a relatively simple mechanism for averaging the readings between two successive cycles of sending data to Thingspeak. This did a decent job of leveling out strange readings but suffered from a major problem: it was impossible to tune. Is this a problem? Probably not, but it really, really annoyed me.

Another problem with this approach was that it was cycle dependent.  That means that I had no effective way of measuring the averaged reading between cycles!

The standard approach to solving this problem would be to use a moving average as is implemented here. However, I happened to be reading a copy of Simon Monk’s superb Programming Arduino: Next Steps and realized that his simple low-pass filter would do the trick.

Here is the basic equation of the filter:

(alpha * runningaverage) + ((1 - alpha) * newreading)

One way to think of this is if alpha = 0.95 then on every cycle 5% (0.05) of the new value is added to the running average.

There are a couple of advantages to this approach: 1) it is easy to understand, 2) it is easy to tweak (just change alpha), 3) it does not use arrays so is fairly memory friendly (not that that matters on the ESP8266!)

I’ll show you the actual sketch in the next post as I also changed how timing works and want to put that under a different heading.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s