🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    ADC Module not working in UIflow2 - [fixed]

    UiFlow 2.0
    3
    5
    2.7k
    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.
    • S
      smatlok
      last edited by smatlok

      Hello,
      Setup: New UIF2 Project, Core2, only adding an external ADC Unit (and calling value in loop)

      Problem: I2C Bus initializes, but the "Init adc_0" Block fails in a debug error: "ValueError: expecting a pin" on the display. The error referres to line "adc_0 = ADC(i2c0)".

      So, sound like function "ADC()" does not accept the i2c0 handler.

      How to proceed/fix? thank you! :)

      1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3
        last edited by ajb2k3

        If you ha a Twitter/X/whatever its called account, post it there with @m5stack

        @M5Stack confirmed.
        here is the console output

        MicroPython v1.20.0 on 2023-08-04; M5STACK with ESP32S3
        Type "help()" for more information.
        >>> 
        >>> 
        >>> import gc
        >>> gc.collect()
        >>> 
        paste mode; Ctrl-C to cancel, Ctrl-D to finish
        === import os, sys, io
        === import M5
        === from M5 import *
        === from hardware import *
        === from unit import *
        === label0 = None
        === i2c0 = None
        === adc_0 = None
        === def setup():
        ===   global label0, i2c0, adc_0
        ===   i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
        ===   adc_0 = ADC(i2c0)
        ===   M5.begin()
        ===   Widgets.fillScreen(0x222222)
        ===   label0 = Widgets.Label("Text", 64, 71, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
        === def loop():
        ===   global label0, i2c0, adc_0
        ===   M5.update()
        ===   label0.setText(str(adc_0.get_raw_value()))
        === if __name__ == '__main__':
        ===   try:
        ===     setup()
        ===     while True:
        ===       loop()
        ===   except (Exception, KeyboardInterrupt) as e:
        ===     try:
        ===       from utility import print_error_msg
        ===       print_error_msg(e)
        ===     except ImportError:
        ===       print("please update to latest firmware")
        === 
        === 
        === 
        Traceback (most recent call last):
          File "<stdin>", line 22, in <module>
          File "<stdin>", line 12, in setup
        ValueError: expecting a pin
        
        >>> 
        

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        1 Reply Last reply Reply Quote 0
        • lbuqueL
          lbuque
          last edited by

          @smatlok @ajb2k3 There is an ADC class in the unit module, which is the abstract class of the ADC unit, and it conflicts with the class name of machine.ADC. It will be fixed in the next version.

          S 1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3
            last edited by

            Machine ADC if for adc readings from the pins directly where as the Unit ADC uses defined port pins.

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            1 Reply Last reply Reply Quote 0
            • S
              smatlok @lbuque
              last edited by

              @lbuque Great, thanks a lot, it works now (alpha23) :) and thanks @ajb2k3 for checking and confirming!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post