EXTIO2 Unit

EXT.IO2 是一款 IO 扩展 UNIT,基于 STM32F030 主控制器,采用 I2C 通信接口,提供 8 路 IO 扩展。每路 IO 均支持独立配置为数字 I/O、ADC、SERVO 控制、RGB LED 控制等模式。支持配置设备 I2C 地址,这意味着用户可以在同一 I2C BUS 上挂载多个 EXT.IO2 UNIT,以扩展更多 IO 资源。适用于多路数字/模拟信号采集,以及照明 / 舵机控制等应用场景。

支持以下产品:

EXTIO2Unit

MicroPython 应用示例

 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 EXTIO2Unit
10
11
12title0 = None
13label0 = None
14i2c0 = None
15extio2_0 = None
16
17
18def setup():
19    global title0, label0, i2c0, extio2_0
20
21    M5.begin()
22    Widgets.fillScreen(0x222222)
23    title0 = Widgets.Title(
24        "ExtIO2Unit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
25    )
26    label0 = Widgets.Label("IO6 State:", 2, 116, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
27
28    i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000)
29    extio2_0 = EXTIO2Unit(i2c0)
30    extio2_0.set_config_mode(0, 1)
31    extio2_0.set_config_mode(6, 2)
32    extio2_0.set_config_mode(3, 4)
33    extio2_0.write_rgb_led(3, 0xFF0000)
34
35
36def loop():
37    global title0, label0, i2c0, extio2_0
38    M5.update()
39    label0.setText(str((str("IO6 State:") + str((extio2_0.read_adc12_pin(0))))))
40
41
42if __name__ == "__main__":
43    try:
44        setup()
45        while True:
46            loop()
47    except (Exception, KeyboardInterrupt) as e:
48        try:
49            from utility import print_error_msg
50
51            print_error_msg(e)
52        except ImportError:
53            print("please update to latest firmware")

UiFlow2 应用示例

example.png

extio2_core2_example.m5f2

class EXTIO2Unit

Constructors

class EXTIO2Unit(i2c, address)

使用 I2C 或 PAHUBUnit 并指定通信地址来初始化 EXTIO2Unit。

参数:
  • i2c – 用于与 EXTIO2Unit 通信的 I2C 或 PAHUBUnit 接口。

  • address (int) – Unit 的 I2C 地址,默认值为 _DEFAULT_ADDRESS。

UIFLOW2:

init.png

Methods

EXTIO2Unit.set_config_mode(id, mode)

为特定通道设置配置模式。

参数:
  • id (int) – 用于设置模式的通道 ID。

  • mode – 要设置的模式,由 EXTIO2Unit 定义。可以是 0、1、2、3 或 4。

UIFLOW2:

set_config_mode.png

EXTIO2Unit.write_output_pin(id, value)

将值写入 EXTIO2Unit 的输出引脚。

参数:
  • id (int) – 要写入数值的引脚 ID。

  • value – 要写入的值,可以是 0 或 1。

UIFLOW2:

write_output_pin.png

EXTIO2Unit.write_servo_angle(id, angle)

向连接到 EXTIO2Unit 的舵机写入一个角度。

参数:
  • id (int) – 用于设置角度的舵机 ID。

  • angle (int) – 要将舵机设置到的角度 (0-255)。

UIFLOW2:

write_servo_angle.png

EXTIO2Unit.write_servo_pulse(id, pulse)

将脉冲宽度写入连接到 EXTIO2Unit 的舵机。

参数:
  • id (int) – 要为其设置脉冲的舵机 ID。

  • pulse (int) – 要将舵机设置到的脉冲宽度,单位为微秒。

UIFLOW2:

write_servo_pulse.png

EXTIO2Unit.write_rgb_led(id, value)

向 NeoPixel LED 写入 RGB 颜色值。

参数:
  • id (int) – 要设置颜色的 NeoPixel ID。

  • value – 要设置的 RGB 值,以 24 位整数表示。

UIFLOW2:

write_rgb_led.png

EXTIO2Unit.set_address(address)

为 EXTIO2Unit 设置 I2C 地址。

参数:

address (int) – 要为单元设置的新 I2C 地址。

UIFLOW2:

set_address.png

EXTIO2Unit.get_config_mode(id)

获取指定通道的当前配置模式。

参数:

id (int) – 要获取模式的通道 ID。

UIFLOW2:

get_config_mode.png

EXTIO2Unit.read_input_pin(id)

读取输入引脚的值。

参数:

id (int) – 用于读取值的引脚 ID。

UIFLOW2:

read_input_pin.png

EXTIO2Unit.read_adc8_pin(id)

读取引脚的 8 位 ADC 值。

参数:

id (int) – 用于读取 ADC 值的引脚 ID。

UIFLOW2:

read_adc8_pin.png

EXTIO2Unit.read_adc12_pin(id)

读取引脚的 12-bit ADC 值。

参数:

id (int) – 用于读取 ADC 值的引脚 ID。

UIFLOW2:

read_adc12_pin.png

EXTIO2Unit.read_servo_angle(id)

读取舵机的角度。

参数:

id (int) – 要读取角度的舵机 ID。

UIFLOW2:

read_servo_angle.png

EXTIO2Unit.read_servo_pulse(id)

读取舵机的脉冲宽度。

参数:

id (int) – 要从中读取脉宽的舵机 ID。

UIFLOW2:

read_servo_pulse.png

EXTIO2Unit.read_rgb_led(id)

读取 NeoPixel LED 的 RGB 颜色值。

参数:

id (int) – 要从中读取颜色的 NeoPixel ID。

UIFLOW2:

read_rgb_led.png

EXTIO2Unit.pin(id, mode, value)

创建并返回一个 Pin 对象,并设置指定的 mode 和 value。

参数:
  • id – 用于创建 Pin 对象的引脚 ID。

  • mode (int) – 为引脚设置的模式(默认为输入)。

  • value – 如果适用,要为引脚设置的值。