0

So I've managed to get the MCP3008 working as a voltage meter with the Pi. Yay :) First off, thanks to everyone here who has been helping me the past two weeks.

Now as for what I am having an issue with at the moment. The device I am measuring the voltage on seems to have an interesting way to send out it's votlages.

When I compare the output from the ADC to a multimeter reading, I can only assume that the ADC is much more sensitive to votlage shifts than the multimeter. This is because on the multimeter, I can see it holding a steady votlage (say 0.75V) while the ADC readout is going up and down around the ballpark area of that votlage (so I'll see 0.22V, then 0.69V, then 0.80V, then back down to 0.55V, etc).

I want to program it so that the numbers look more stable, but I am not exactly sure how to tackle that. Should I create an array of recent values and just check them against the new one? I tried slowing down my sample rate, but that only made it look even

  • Have you considered taking a number of measurements and storing them in an array and averaging them over a period of time? – Steve Robillard Jun 29 '17 at 14:23
2

What you want to do is called filtering. There's plenty of way to do that ! What you can do is to measure let's say 100 value and make an average of them. You'll do a data structure where when you add a value you throw the last one and still do the average. The more the number of value in the data structure and the less it will be reactive to variation. There's more fancy way to do that filtering but in your case this could be a good way. And it will be easy to implement in a first time.

YCN-

  • So basically create a list that has a maximum size of say...100 values, and just continually update with the average of all values in the list. And then every time there would be a 101st value, bump index 0 out of the list, move everything over, and add the new value to the now empty index 99. Am I understanding that correctly? – Skitzafreak Jun 29 '17 at 14:26
  • Let's say we use 5 value max : first you fill up the structure, and then you push in the new value you sense, and push out the oldest value. Then you do the average of those 5 value. And this average is your value :). That's assuming that the value you sense is almost stable or at least that the value are changing around the real value. – YCN- Jun 29 '17 at 14:29
2

I use this simple and easily tunable method to arrive at a new estimate.

estimate = (estimate * (1.0 - weighting)) + (reading * weighting)

where weighting is greater than 0 and less than or equal to 1.

The higher the weighting the more quickly the estimate changes to reflect the new reading.

By the way your ADC readings should not normally fluctuate as much as you are seeing if the circuit is stable. I suspect something is wrong.

  • I was wondering if it might have been a problem with the circuit. Honestly when I had the ADC plugged into a potentiometer I was getting a decently stable reading out of it, with the only fluctuations being in the 0.001V range of values – Skitzafreak Jun 29 '17 at 15:08
  • @Skitzafreak as you have yet to tell us what the project is and the environment it will be expected to operate in we can help diagnose what may be causing the fluctuations you are seeing. – Steve Robillard Jun 30 '17 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.