Multiple Analog Inputs producing strange data

@sjm - Sorry to drag you in like this, but by looking at the forum, you might be one of the few people who have done this sort of setup.

Would you please take a second to end my insanity? :slight_smile:

Thanks big time!

You’re correct, dataready is only called when the system is idle (ie, no other event handler running). This is why you can pass in multiple buffers - the buffer swap happens at interrupt time, and hence your callback being called does not impact data collection.

Have you checked the length passed into your data ready callback?

Hi,

Thanks for the info!

I ended up calling the takeAndSubmit() function, outlined above from the dataReady() function, which guarantees that the sampler is done and that the info in there is current. The final line of dataReady() is sampler.stop(), which limits the sampler to one iteration at a time.

I call the samplerStart() function from main() and just schedule that with imp.wakeup().

Everything works like a charm now!

Hope this helps anyone who has come across this issue!

P.s. The whole reason I’m doing this is to minimize ADC noise by averaging all of the readings. I’m currently just summing up all of the values in the blob to a single variable in a for() loop and then dividing by the number of iterations outside the loop. While experimenting with the number of iterations I got a couple of “IO errors”, which I’m guessing come into play when the variable overflows.

Is there a smarter way to average this? Perhaps the Sampler itself can do the avg() outside userland?

Thanks again for all of your help!

I am currently using 4 analog inputs with a thermistor, photo-resistor, humidity sensor and ultrasonic ranging senors. I am getting spikes on all of the inputs, I am currently using a breadboard, once I shift to a circuit board I will see if they are diminished. See attached xively graphs.

Hm…

It seems this issue is not isolated to my instance.

You can try running the same code with only one connected input and you’ll see your values normalize (for that particular input).

This, in effect, limits us to using only one ADC channel at a time, which sucks!

@Hugo - Do you have any idea what could be causing this?

Thanks in advance!

I’ve got similar issues. Found that a well places imp.sleep solved them?
Will continue my investigation…

Exactly the same here - I outlined this particular solution above.

Bear in mind that this is not 100%, though. You’ll still get unexplicable spikes from time to time and multiple imp.sleep()s throughout the code are not a good thing, I believe, in general.

@tldstyl3 no, those look very strange (and are periodic at some very long levels, like almost an hour, which really doesn’t point to an adc issue).

Can you log your hardware.voltage() too? What are you using to power the device?

@Hugo - I believe that there is in fact an issue with the ADC, because I’ve run into the same issues that @squaresine @sbright33 have experienced.

Along with the very crude workaround, which works some of the time (imp.sleep).

Sorry if I’m speaking out of turn.

@tldstyl3 indeed there could be an issue, but I was noting that your graphs did not show the same type of issues that others have reported in this thread (ie, they show disturbance on close reads of different channels).

Your plot appears to be showing a long term cyclic issue, which repeats almost every hour. This is very unlikely to be the same type of issue others are discussing, and is much more likely to be power or other environment related.

We’ll see if we can replicate any of these in the lab; it’s possible there is a ADC setup issue somewhere in the code.