Issue with Analog Voltage Measurement on Core2
-
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
-
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 -
@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.