ADC Unit

支持以下产品:

ADC

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import ADCUnit
10
11
12label0 = None
13i2c0 = None
14adc_0 = None
15
16
17def setup():
18    global label0, i2c0, adc_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    label0 = Widgets.Label("label0", 16, 16, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
23
24    i2c0 = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
25    adc_0 = ADCUnit(i2c0)
26
27
28def loop():
29    global label0, i2c0, adc_0
30    M5.update()
31    label0.setText(str(adc_0.get_voltage()))
32
33
34if __name__ == "__main__":
35    try:
36        setup()
37        while True:
38            loop()
39    except (Exception, KeyboardInterrupt) as e:
40        try:
41            from utility import print_error_msg
42
43            print_error_msg(e)
44        except ImportError:
45            print("please update to latest firmware")

UIFLOW2 Example:

example.png

adc_cores3_example.m5f2

class ADCUnit

Constructors

class ADCUnit(i2c0)

创建一个ADCUnit对象.

参数是:
  • I2C0 是I2C端口.

UIFLOW2:

init.png

Methods

ADCUnit.get_value()

Gets the original value read by the adc(16 bit).

UIFLOW2:

get_value.png

ADCUnit.get_voltage()

获取电压值。

UIFLOW2:

get_voltage.png

ADCUnit.get_operating_mode()

获取工作模式。(单次读取还是连续读取)

UIFLOW2:

get_operating_mode.png

ADCUnit.get_data_rate()

获取数据的读取速率。

UIFLOW2:

get_data_rate.png

ADCUnit.get_gain()

获取数据的增益倍数。

UIFLOW2:

get_gain.png

ADCUnit.operating_mode()

设置工作模式(单次读取还是连续读取)

UIFLOW2:

set_operating_mode.png

ADCUnit.data_rate()

设置获取数据的速率。

UIFLOW2:

set_data_rate.png

ADCUnit.gain()

设置读取数据的增益倍数。

UIFLOW2:

set_gain.png