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

    How to select ADC channel?

    Scheduled Pinned Locked Moved FiPy
    2 Posts 1 Posters 156 Views 1 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.
    • R Offline
      railmonitor
      last edited by railmonitor

      When looking at the FiPy datasheet, it would seem that there is 2 different ADC channels, each having several corresponding pins.

      I am having some problems understanding how to define which channel to use. From the documentation: https://docs.pycom.io/firmwareapi/pycom/machine/adc/

      I am using following code to associate a pin with the ADC channel, but which one of the two channels?:

      adc = ADC()
      apin = adc.channel(pin = 'P16')
      

      From micropython documentation, it would seem that this could be selected this way:

      adc = ADC()
      apin = adc.channel(id = 2, pin = 'P16')
      #or this way
      apin = adc.channel(2, pin = 'P16')
      

      But both options produces following output:
      e5f484f6-b06f-4f4a-8a2e-d4a8af9f0716-image.png

      Now i have seen on the link below, that the ADC can be initated with code:

      adc = ADC(0)
      

      which i would assume is ADC channel 1, but giving it (1) as an argument (channel 2 i assume) produces an error:

      7b84e39c-fe52-49d4-bcb8-707b89e4ed59-image.png

      https://docs-mk2.readthedocs.io/en/latest/tutorials/all/adc/

      So how do i select channel? I didn't find any useful post here, but thanks in advance.

      EDIT: Just realized that P16 only is for ADC channel 1, so naturally it says resource not available, but trying to use channel 2 with, for instance, P9 also gives the resource not available error.

      So i'm guessing that channel is simply decided by which pin you are using, and that you can only use one pin per channel at a time? Can someone confirm?

      RE-EDIT: (sorry for all the edits, i'll try to test things out some more before i make posts in the future)

      I tried this now:

      adc=ADC()
      apin = adc.channel(pin = 'P9')
      

      and got the resource not available error. So i'm still confused as to how this works? How do i activate the 2nd ADC channel?

      Also i read somewhere that the ADC2 channel does not work when using WiFi, but that was an old post. Does that count for the FiPy in current versions?

      /rm

      1 Reply Last reply Reply Quote 0
      • R Offline
        railmonitor
        last edited by railmonitor

        Still hoping for an answer. In short: How do i get to use ADC 2? How do i take readings from pin P3 for instance? Can i use both ADC channels, maybe even two pins at channel 1 and two pins at channel 2, at the same time?

        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