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

    Unexpected WiPy ADC values

    Scheduled Pinned Locked Moved WiPy 2&3
    4 Posts 2 Posters 280 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.
    • J Offline
      Jonno
      last edited by

      I'm getting an unexpected reading from the ADC.
      When I connect the ADC input to GND and read it I see a count of 0 and a voltage of 54mV (with 0dB attenuation) or a voltage of 110mV with an attenuation of 11dB.

      import pycom
      import machine
      pycom.heartbeat(False)
      
      adc = machine.ADC()
      apin = adc.channel(pin='P13',attn=adc.ATTN_11DB)
      
      print ("Count:",apin(),"  Voltage:",apin.voltage())
      

      This prints:
      Count: 0 Voltage: 110

      The displayed voltage varies with different attenuation. viz:
      54mV for 0dB, 60mV for 2.5 dB, 82mV for 6dB and 110mV for 11dB. In all cases the count is 0.
      Why is the voltage not also 0mV in all cases?

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

        @Jonno Below ~60 mV, the reading is 0. Therefore, all 0 values are mapped to that value. About the ESP32/WiPy ADC you may look at that analysis: https://github.com/bboser/IoT49/blob/master/doc/analog_io.md

        1 Reply Last reply Reply Quote 1
        • J Offline
          Jonno
          last edited by

          Thanks @robert-hh . OK I see that the ESP32 ADC is less than perfect but not sure I understand why a count of 0 would give a adc.voltage() reading of non-zero.
          Perhaps I should just read the count and do the conversion to voltage myself with

          count * Vref / 4096
          

          and not use the
          adc.voltage() option.

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

            @Jonno That conversion is the heart of the adc.voltage() code. But consider that the adc.value() will return 0 for any input voltage below ~60mV. So if you read 0, you only know that it's below 60mV. And Vref is slightly different for each device.

            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