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

    WiPy ADC resolution

    Scheduled Pinned Locked Moved WiPy 2&3
    5 Posts 2 Posters 457 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 Jonno

      It seems I'm unable to vary the ADC resolution from 12 bits. The doco says 9, 10, 11 and 12 bits are valid.

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

      The above code gives:

      Traceback (most recent call last):
        File "<stdin>", line 9, in <module>
      ValueError: invalid argument(s) value
      >
      

      The only value that doesn't give the error is "bits=12".

      Is my syntax correct?

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

        @Jonno: There is indeed an inconsistency in the code. While the adc instance creating call accepts all values for bits between 9 and 12, the adc.init() call only accepts 12. So you can use for instance:
        adc = machine.ADC(bits=11)

        Edit: Looking at the implementation of adc.init(), it looks like the assignment of the bits value to pyb_adc_obj_t->width is missing. Then, the default value 12 is used. So it may be wrong anyhow.

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

          @robert-hh thanks for that. machine.ADC(bits=11) is a better way of defining the resolution anyway.

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

            @Jonno I raised an issue about adc.init() which also contains the fixed function code. https://github.com/pycom/pycom-micropython-sigfox/issues/324
            I could also make a PR, starting the fight with the git dragon.

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

              @robert-hh Ok thanks for that. Glad to perhaps make a small contribution to an improvement to the code :-)

              1 Reply Last reply Reply Quote 0

              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