DAC2 Unit

Dac2 类控制GP8413 15位数字到模拟转换器(DAC),能够将数字信号转换为两个通道的模拟电压输出,范围可以为0-5V或0-10V。

支持以下产品:

DAC2Unit

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 DAC2Unit
10
11
12i2c0 = None
13dac2_0 = None
14
15
16def setup():
17    global i2c0, dac2_0
18
19    M5.begin()
20    Widgets.fillScreen(0x222222)
21
22    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
23    dac2_0 = DAC2Unit(i2c0, 0x59)
24    dac2_0.set_dacoutput_voltage_range(dac2_0.RANGE_10V)
25    dac2_0.set_voltage(7.5, channel=dac2_0.CHANNEL_0)
26
27
28def loop():
29    global i2c0, dac2_0
30    M5.update()
31
32
33if __name__ == "__main__":
34    try:
35        setup()
36        while True:
37            loop()
38    except (Exception, KeyboardInterrupt) as e:
39        try:
40            from utility import print_error_msg
41
42            print_error_msg(e)
43        except ImportError:
44            print("please update to latest firmware")

UIFLOW2示例:

example.png

cores3_dac2_example.m5f2

DAC2Unit类

构造函数

class DAC2Unit(i2c0, addr)

创建一个DAC2Unit对象。

  • I2C0 是I2C端口。

  • addr DAC的I2C地址(默认是`0x59`)。

UIFLOW2:

init.png

Methods

DAC2Unit.setDACOutputVoltageRange(_range)

设置DAC的输出电压范围。

  • _range DAC输出电压范围,可以是`DAC2Unit.RANGE_5V`或`DAC2Unit.RANGE_10V`。

UIFLOW2:

setDACOutputVoltageRange.png

DAC2Unit.setVoltage(voltage, channel=Dac2.CHANNEL_BOTH)

设置DAC的输出电压。

  • voltage 期望的输出电压,从0.0到范围最大值(5V或10V)。

  • channel 要设置的DAC通道。选项是`Dac2.CHANNEL_0`、Dac2.CHANNEL_1`或`Dac2.CHANNEL_BOTH

UIFLOW2:

setVoltage.png

DAC2Unit.setVoltageBoth(voltage0, voltage1)

为两个通道设置输出电压。

  • voltage0 期望的输出电压,从0.0到范围最大值(5V或10V)。

  • voltage1 期望的输出电压,从0.0到范围最大值(5V或10V)。

UIFLOW2:

setVoltageBoth.png