DAC2 Hat
The following products are supported:
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 I2C 9from hardware import Pin 10from hat import DAC2Hat 11 12 13i2c0 = None 14hat_dac2_0 = None 15 16 17def setup(): 18 global i2c0, hat_dac2_0 19 20 M5.begin() 21 i2c0 = I2C(0, scl=Pin(26), sda=Pin(0), freq=100000) 22 hat_dac2_0 = DAC2Hat(i2c0, 0x59) 23 hat_dac2_0.set_dacoutput_voltage_range(hat_dac2_0.RANGE_10V) 24 hat_dac2_0.set_voltage(5, channel=hat_dac2_0.CHANNEL_0) 25 26 27def loop(): 28 global i2c0, hat_dac2_0 29 M5.update() 30 31 32if __name__ == "__main__": 33 try: 34 setup() 35 while True: 36 loop() 37 except (Exception, KeyboardInterrupt) as e: 38 try: 39 from utility import print_error_msg 40 41 print_error_msg(e) 42 except ImportError: 43 print("please update to latest firmware")
UIFLOW2 Example:
stickc_plus2_dac2_example.m5f2
class DAC2Hat
Constructors
- class DAC2Hat(i2c, address: int | list | tuple = 0x59)
Create a DAC2 Hat object.
- 参数:
i2c – I2C object
address – I2C address of the DAC2 Hat
UIFLOW2:

DAC2Hat class inherits DAC2Unit class, See unit.DAC2Unit.Methods for more details.

