Analogread on proto / max sonar out by 20 cm
Hi, I seem to be having a very basic problem with analog read on an industruino proto, I'm basically reading the analog pin from a maxbotix ultrasonic sensor but all my readings are value + 20, i have used the exact same sketch just to read an analog pin on an uno board and the values are correct, am I missing something here! Help very much appreciated?
What exact type of sensor are you using? And keep in mind the D21G is a 3.3V chip, not 5V like the uno. If you're not careful you might toast your Industruino
--
G Carter-Brown
Sent by Industruino using Odoo about Forum Post Analogread on proto / max sonar out by 20 cm
Hi, i'm not sure what your error value of 20 refers to, it is 20 on the analogRead scale of 0-4095 or 20cm after mapping to your sensor specs?
Anyway, if it is 20 on the analogRead(), i think this goes back to a bug in the original Arduino SAMD core https://github.com/arduino/ArduinoCore-samd/issues/446 - an offset of about 35mV in analog readings. Arduino has fixed this in a core release late last year but we have not had a chance yet to implement it in the Industruino core. The easiest way to fix this is to add these lines in your Industruino core file wiring_analog.c, which on my Linux machine is at ~/.arduino15/packages/industruino/hardware/samd/1.0.1/cores/industruino/wiring_analog.c
At line 169, add this block:
// Waiting for the 1st conversion to complete
while (ADC->INTFLAG.bit.RESRDY == 0);
Just the same as in this github bug fix https://github.com/arduino/ArduinoCore-samd/commit/aef4af4c1e20ffeee2a8e62c6998d1fcb2c7fa4b#diff-63b7293bbdf8f8f0f8b98336a5e85d83
I have tested that with my PROTO unit, with D4/A4 connected to GND, it brings back the raw analogRead() value (should be 0) from around 20 (before the above change) down to 0-4. Please try and let us know if that solves your issue.
UPDATE: setting a stable analogReference() is very important to get accurate results. See here for options. The default is 3.3V reference which may not be stable during operation. My testings shows the best results using any of these 2 settings:
analogReference(AR_INTERNAL1V0);
analogReference(AR_INTERNAL1V65);
I have tried this fix and it seems to have reduced the error considerably, will try to increase accuraccy further by adding temp compensation and filtering, your help is much appreciated.thankyou
I have tried this fix and it seems to have reduced the error considerably, will try to increase accuraccy further by adding temp compensation and filtering, your help is much appreciated.thankyou
I have tried this fix and it seems to have reduced the error considerably, will try to increase accuraccy further by adding temp compensation and filtering, your help is much appreciated.thankyou
Just been playing with this again and the ADC has now gone totally mad, with the pin connected to ground I get readings of 15, 16, 17 , 15, 32, 28 , 14 , 15, the sensor uses a reading of 1 cm/ bit, so as it is the industruino is basically useless for purpose I bought it for, I need accurate measurements, this is unreliable data. I may have to use a PW sensor or abandon the industruino completely, shame as it ticks nearly all the other boxes.
Hi, i have looked further into this and it seems we can get better results by setting the analogReference (in setup) to an internal value of 1V or 1.65V; these 2 options give me best results: analogReference(AR_INTERNAL1V0); and analogReference(AR_INTERNAL1V65); (and just in case it might help anybody: after making that change to the wiring_analog.c file you need to compile/upload your sketch again to see the effect)
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 3/10/20, 2:24 PM |
Seen: 2058 times |
Last updated: 3/13/20, 1:03 AM |
What exact type of sensor are you using? And keep in mind the D21G is a 3.3V chip, not 5V like the uno. If you're not careful you might toast your Industruino