UIFlow MicroPython Firmware

repository·master·Indexed 41 days ago

https://github.com/m5stack/uiflow-micropython

A specialized MicroPython firmware distribution for M5Stack hardware. It provides the UIFlow2 API, support for M5Stack sensors and modules, and the m5 module for hardware initialization, display management via m5.lcd, and peripheral access.

Tokens
338.5K
Snippets
1.1K
Records
1.4K
Agent score
50%

What's inside UIFlow MicroPython

  1. Overview of HAT 18650C

    master

    The HAT 18650C V1.1 is a hardware expansion module that integrates an AW32257 charger and an INA226 power monitor. It allows developers to:

    • Measure battery voltage, current, and power.
    • Control battery charging parameters.
    • Read charge and fault status.
    • Control the AW32257 Boost/OTG output.

    Important Hardware Notes:

    • Current Polarity: Charging current is typically reported as a negative value, while discharging current is typically positive.
    • Setting Values: Charge current and voltage settings are mapped to supported hardware 'gears' (register steps) in the AW32257 rather than accepting arbitrary floating-point values.
  2. Use the Limit Unit

    master

    The Limit Unit is a travel switch unit used to provide a limit trigger signal to an MCU. It works by pulling the digital signal interface from 3.3V high to 0V low when the switch handle is closed by external force. This is typically used in moving machinery to control stroke and provide terminal limit protection.

    import M5
    from unit import LIMITUnit
    
    # Example initialization
    limit_0 = LIMITUnit((33, 32), True, type=2)
  3. Use the DAC2 Unit to control analog voltage

    master

    The DAC2Unit class interfaces with a GP8413 15-bit Digital to Analog Converter (DAC). It allows you to convert digital signals into two channels of analog voltage output. The output range can be configured to either 0-5V or 0-10V.

    Supported hardware:

    • DAC2Unit
    import M5
    from hardware import *
    from unit import DAC2Unit
    
    # Initialize I2C and DAC2 Unit
    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
    dac2_0 = DAC2Unit(i2c0, 0x59)
    
    # Set range to 10V and output 7.5V on Channel 0
    dac2_0.set_dacoutput_voltage_range(dac2_0.RANGE_10V)
    dac2_0.set_voltage(7.5, channel=dac2_0.CHANNEL_0)
  4. Use the time module for time and date functions

    master

    The time module provides functions to get the current time and date, measure time intervals, and implement delays.

    Important: Time Epoch and Calendar Accuracy

    • Epoch: The epoch is January 1, 1970, 00:00:00 (UTC) on all platforms. You can determine the epoch year using gmtime(0)[0].
    • Calendar Maintenance: On baremetal ports, system time depends on the machine.RTC() object. If your hardware does not have a Real Time Clock (RTC) maintained by a backup battery or NTP, functions requiring absolute time may behave unexpectedly.
    • Setting Time: To set the calendar time on baremetal systems, use machine.RTC().datetime(tuple).
    import time
    # Determine epoch year
    early = time.gmtime(0)[0]
    
    # Note: Setting calendar time requires machine.RTC()
    # import machine
    # machine.RTC().datetime((year, month, day, weekday, hours, minutes, seconds, subseconds))
  5. Use the Chain Key module

    master

    The chain.KeyChain module allows you to interface with M5Chain series devices to read button states, handle interaction events (clicks, double-clicks, long presses), and control onboard RGB LEDs. It requires a ChainBus object to communicate with the hardware.

    from chain import ChainBus
    from chain import KeyChain
    
    # Initialize the bus and the KeyChain device
    chainbus_0 = ChainBus(2, 32, 33, verbose=True)
    keychain_0 = KeyChain(chainbus_0, 1)
  6. Supported packages for Tab5X

    master

    The Tab5X firmware provides access to several user-facing MicroPython packages for hardware control and UI development:

    • M5UI: LVGL component library, including m5ui.M5Keyboard.
    • Module: For M-BUS expansion modules.
    • Unit: For Unit drivers.
    • USB: Includes usb.device for HID, mouse, and keyboard support.
    • Chain: For Chain devices.
    • Tab5: For Tab5 and Tab5X keyboard support.
  7. Use the Atomic Motion Base for servo and motor control

    master

    The Atomic Motion Base is a driver for ATOM series controllers that provides 4 servo channels and 2 DC motor interfaces via I2C communication. It uses an internal STM32 chip for control.

    Hardware Versions:

    • Standard Motion Base: Supports servo and motor control.
    • Motion Base v1.1: Adds INA226 support for voltage, current, and power monitoring.
  8. Use the UWB Unit for ranging and positioning

    master

    The UWB (Ultra Wide Band) Unit uses the Ai-ThinkerBU01 Transceiver (based on Decawave's DW1000) to provide indoor wireless tracking and range finding with approximately 10cm accuracy.

    Key Concepts:

    • Roles: The system operates using Anchors (base stations) and Tags.
    • Capacity: The firmware supports up to 4 base station devices (each with a unique ID) and only a single tag device operating at one time.
    • Functionality: Currently, the firmware supports the transmission of ranging information only; it does not support custom data transmission.
    • Triangulation: Positioning is achieved by the base stations resolving position information and outputting it to the tag.
  9. Support for Atomic Echo Pyramid Base

    master

    The AtomicEchoPyramidBase class provides support for the Atomic Echo Pyramid Base hardware. This base provides audio playback/recording, touch input, and dual RGB LED strips.

    Hardware Compatibility:

    ControllerSupport Status
    Atom EchoO (Full Support)
    Atom LiteS (Supported)
    Atom MatrixS (Supported)
    AtomS3S (Supported)
    AtomS3 LiteS (Supported)
    AtomS3RS (Supported)
    AtomS3R-CAMS (Supported)
    AtomS3R-ExtS (Supported)

    Note: Power must be supplied to both the EchoPyramid base and the Atom controller for correct operation.