ADC Module not working in UIflow2 - [fixed]



  • 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! :)



  • 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
    
    >>> 
    


  • @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.



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



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