EXTIO2 Unit

EXT.IO2 is an IO extended unit, based on STM32F030 main controller, using I2C communication interface and providing 8 IO expansion. Each IO supports independent configuration of digital I/O, ADC, SERVO control, RGB LED control modes. Supports configuration of device I2C address, which means that users can mount multiple EXT.IO2 UNITs on the same I2C BUS to extend more IO resources. Suitable for multiple digital/analog signal acquisition, with lighting/servo control applications.

Support the following products:

EXTIO2Unit

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 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:

example.png

extio2_core2_example.m5f2

class EXTIO2Unit

Constructors

class EXTIO2Unit(i2c, address)

Initialize EXTIO2Unit with I2C or PAHUBUnit and address for communication.

Parameters:
  • i2c – The I2C or PAHUBUnit interface for communication with the EXTIO2Unit.

  • address (int) – The I2C address for the unit, default is _DEFAULT_ADDRESS.

UIFLOW2:

init.png

Methods

EXTIO2Unit.set_config_mode(id, mode)

Set the configuration mode for a specific channel.

Parameters:
  • id (int) – The channel ID to set the mode for.

  • mode – The mode to set, defined by the EXTIO2Unit. Can be 0, 1, 2, 3, or 4.

UIFLOW2:

set_config_mode.png

EXTIO2Unit.write_output_pin(id, value)

Write a value to an output pin of the EXTIO2Unit.

Parameters:
  • id (int) – The pin ID to write the value to.

  • value – The value to write, either 0 or 1.

UIFLOW2:

write_output_pin.png

EXTIO2Unit.write_servo_angle(id, angle)

Write an angle to a servo connected to the EXTIO2Unit.

Parameters:
  • id (int) – The servo ID to set the angle for.

  • angle (int) – The angle to set the servo to (0-255).

UIFLOW2:

write_servo_angle.png

EXTIO2Unit.write_servo_pulse(id, pulse)

Write a pulse width to a servo connected to the EXTIO2Unit.

Parameters:
  • id (int) – The servo ID to set the pulse for.

  • pulse (int) – The pulse width to set the servo to, in microseconds.

UIFLOW2:

write_servo_pulse.png

EXTIO2Unit.write_rgb_led(id, value)

Write an RGB color value to a NeoPixel LED.

Parameters:
  • id (int) – The NeoPixel ID to set the color for.

  • value – The RGB value to set, represented as a 24-bit integer.

UIFLOW2:

write_rgb_led.png

EXTIO2Unit.set_address(address)

Set the I2C address for the EXTIO2Unit.

Parameters:

address (int) – The new I2C address to set for the unit.

UIFLOW2:

set_address.png

EXTIO2Unit.get_config_mode(id)

Get the current configuration mode of a specific channel.

Parameters:

id (int) – The channel ID to get the mode for.

UIFLOW2:

get_config_mode.png

EXTIO2Unit.read_input_pin(id)

Read the value of an input pin.

Parameters:

id (int) – The pin ID to read the value from.

UIFLOW2:

read_input_pin.png

EXTIO2Unit.read_adc8_pin(id)

Read the 8-bit ADC value of a pin.

Parameters:

id (int) – The pin ID to read the ADC value from.

UIFLOW2:

read_adc8_pin.png

EXTIO2Unit.read_adc12_pin(id)

Read the 12-bit ADC value of a pin.

Parameters:

id (int) – The pin ID to read the ADC value from.

UIFLOW2:

read_adc12_pin.png

EXTIO2Unit.read_servo_angle(id)

Read the angle of a servo.

Parameters:

id (int) – The servo ID to read the angle from.

UIFLOW2:

read_servo_angle.png

EXTIO2Unit.read_servo_pulse(id)

Read the pulse width of a servo.

Parameters:

id (int) – The servo ID to read the pulse width from.

UIFLOW2:

read_servo_pulse.png

EXTIO2Unit.read_rgb_led(id)

Read the RGB color value of a NeoPixel LED.

Parameters:

id (int) – The NeoPixel ID to read the color from.

UIFLOW2:

read_rgb_led.png

EXTIO2Unit.pin(id, mode, value)

Create and return a Pin object with the specified mode and value.

Parameters:
  • id – The pin ID to create the Pin object for.

  • mode (int) – The mode to set for the pin (default is input).

  • value – The value to set for the pin, if applicable.