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

    Issue with Analog Voltage Measurement on Core2

    Core 2
    2
    3
    3.3k
    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.
    • F
      falbriard
      last edited by

      Under UIflow, I execute the following code on a Core2 device, signal from Port A, pin 32,
      using a Micro-Python execution block:

      from machine import ADC
      adc=ADC(32)
      signal = int(adc.read())

      label1 show signal

      The value obtained is always 4095, even if no voltage is present at the input pin 32.

      Please give me some explanations how to connect and measure an analog signal (V) using the
      M5stack core2 device.

      Regards, Claude

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        Hello @falbriard

        the reason is that Port A by default is used for I2C and I2C requires pull-up resistors on both lines which are inside M5Core2. Also see M5Core2 schematic. That is why you always get the value 4095.

        A better choice would be Port B / GPIO36. Port B is available on the M5GO Battery Bottom2. GPIO36 (and others) via Bus Module.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        F 1 Reply Last reply Reply Quote 0
        • F
          falbriard @felmue
          last edited by

          @felmue Now got some useful readings of Volts using the following code. Not sure about accuracy due to logarithmic scale. I've tested it with an AA 1,5 battery as input signal, connecting GND and ADC pin 32. As I already use a GPS and an expansion board, so at the moment SDA pin 32 at Core2 unit is the only available choice. My code:

          execute:
          from machine import ADC
          adc=ADC(32)
          adc.atten(ADC.ATTN_11DB)
          while true (with blockly), execute:
          signal = int(adc.read())
          if signal == 4095:
          signal = 0
          percentage = float(signal / 4095 / 100)
          volts = float(3.9 * percentage * 100)
          label2 show volts (with blockly)

          Now getting 0 at idle connection and +- 1.5 V when testing it with an AA battery as analog signal.

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