Best Practice for Spurious Censor Readings?

Best is to find out why you hare having spurious issues and address that. May be as simple as slowing down your serial bus speed, or adding a capacitor. Most of the time you can at least determine what the issue is, but if you still need a filtering algorithm, I recommend a median filter.

A median filter will sort all the measurements from smallest to largest, then pick the one in the middle. If you have some odd measurements, either high or low, they won’t skew your results like an average will, and you won’t have to mess with your sampling times as this can cause issues elsewhere with other processes like say the wifi stack or the Cayenne business.

Here’s a post where I’ve used one in the past. Feel free to use this code:

Cheers,

Craig

1 Like