Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Using two ADC pins influences analog input voltage readings

    Scheduled Pinned Locked Moved WiPy 2&3
    wipyadc
    8 Posts 2 Posters 1.6k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      MoeweX
      last edited by

      Hi,

      up until now, I have only used P13 as an analog input pin and everything worked as expected. But today, I also started using P16 and noticed that both pins now report values that are too high. For example, on P16 I read a voltage of 2.85 instead of 2.5 as measured with my multimeter. If I only use one adc pin, I read the expected voltage. Does anyone has an explanation for this?

      For both pins, I use ADC.ATTN_11DB.

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @MoeweX
        last edited by

        @moewex GND offset? Are you sure, that the input ciruits have a proper low impedance connection to GND?

        1 Reply Last reply Reply Quote 0
        • M Offline
          MoeweX
          last edited by

          Hi, thx for the response @robert-hh! I double checked, but I only have one power source and am also pretty sure that this is not the reason.

          Furthermore, I did additional testing and somehow the values are now also off if only one adc is measuring as well. I am pretty sure this has not been the case before, but now every value is always slightly too high. Is it possible that I messed up the internal calibration or so?

          I measured four different values (with both my voltmeter and and wipy). These are the results (voltmeter --- wipy --- factor the wipy is to high):

          2.69 --- 3.161 --- 1.175
          2.31 --- 2.642 --- 1.144
          1.62 --- 1.791 --- 1.106
          1.44 --- 1.581 --- 1.098

          As the value differences are not constant, I cannot just calculate "the real" values, or does anyone see a pattern?

          robert-hhR 1 Reply Last reply Reply Quote 1
          • robert-hhR Offline
            robert-hh @MoeweX
            last edited by

            @moewex No, i do not see a pattern except that the ratio is increasing with the voltage, like a non-linear effect. The ESP32 ADC is known for bad linearity. Did you use adc_voltage() or adc_value() for reading the ADC. It may be interesting to try adc_value().
            And you should use a low impedance input (< 10 kOhm).

            M 1 Reply Last reply Reply Quote 1
            • M Offline
              MoeweX @robert-hh
              last edited by

              @robert-hh . For the measurements, I did adc_value() as I essentially just execute the quick usage example.

              I am measuring the analog output of a soil moisture sensor, so the impedance should not be a problem here, right?

              But I tried to also measure the voltage of voltage divider with two 100kOhm resistors, is this problematic?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @MoeweX
                last edited by robert-hh

                @moewex So you translated than the values in the range 0..4095 yourself into a voltage? Then you should test the real range in advance. These devices do NOT have it's full range at 3.3V. See also here: https://www.esp32.com/viewtopic.php?f=19&t=2881&sid=ed97d32cb10488d58c6d4947d68cb59f&start=10
                The best linearity is at 6dB attenuation.
                The impedance affects mostly the noise. I typically put a small capacitor at the input, like 1 .. 10 nF, which also lowers the impedance.
                Edit: I should add that the ADC of the ESP32 is lousy. The effective resolution you get is about 9 bit. Everything else is noise. If you need precise values, use an external ADC, like from Analog Devices.

                M 1 Reply Last reply Reply Quote 1
                • M Offline
                  MoeweX @robert-hh
                  last edited by

                  @robert-hh The moisture sensor output is somewhere between 1V and 2.5V (roughly), so I had not to translate it (where does the 4095 come from anyhow?) :).

                  The link you provided is helpful, thank you! So it seems to be an ESP32 problem (which is good to know). By adding a capacitor to the input (connected between input pin and ground, right?), I should be able to reduce the noise and maybe improve the accuracy, don't I? But I guess the best solution is to add more voltage dividers so that I can use a lower attenuation... . Maybe it would be worthwhile adding such a note to the documentation

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @MoeweX
                    last edited by

                    @moewex The 4095 is the highest value of the 12 bit ADC. So you could try to call apin.value() instead of just apin, which seems to return the voltage value, which has to be calibrated beforehand. The noise and fluctuation will always be large. So you have to add some kind of lowpass or averaging. For the moisture application with ist slow change, using a digital lowpass filter/averaging is surely appicable. And you do not have to care for absolute precision, just consistency.

                    1 Reply Last reply Reply Quote 1

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom