# Table of Contents - [UiFlow2 documentation and references — UIFlow2 Programming Guide master documentation](#uiflow2-documentation-and-references-uiflow2-programming-guide-master-documentation) - [MicroPython libraries — UIFlow2 Programming Guide master documentation](#micropython-libraries-uiflow2-programming-guide-master-documentation) - [System — UIFlow2 Programming Guide master documentation](#system-uiflow2-programming-guide-master-documentation) - [Get Started — UIFlow2 Programming Guide master documentation](#get-started-uiflow2-programming-guide-master-documentation) - [Widgets — A basic UI library — UIFlow2 Programming Guide master documentation](#widgets-a-basic-ui-library-uiflow2-programming-guide-master-documentation) - [Software — UIFlow2 Programming Guide master documentation](#software-uiflow2-programming-guide-master-documentation) - [Hardware — UIFlow2 Programming Guide master documentation](#hardware-uiflow2-programming-guide-master-documentation) - [Unit — UIFlow2 Programming Guide master documentation](#unit-uiflow2-programming-guide-master-documentation) - [Module — UIFlow2 Programming Guide master documentation](#module-uiflow2-programming-guide-master-documentation) - [HAT — UIFlow2 Programming Guide master documentation](#hat-uiflow2-programming-guide-master-documentation) - [Controllers — UIFlow2 Programming Guide master documentation](#controllers-uiflow2-programming-guide-master-documentation) - [Base — UIFlow2 Programming Guide master documentation](#base-uiflow2-programming-guide-master-documentation) - [Quick Reference — UIFlow2 Programming Guide master documentation](#quick-reference-uiflow2-programming-guide-master-documentation) - [Advanced — UIFlow2 Programming Guide master documentation](#advanced-uiflow2-programming-guide-master-documentation) - [Contributions Guide — UIFlow2 Programming Guide master documentation](#contributions-guide-uiflow2-programming-guide-master-documentation) - [UiFlow2 documentation and references — UIFlow2 Programming Guide master documentation](#uiflow2-documentation-and-references-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Copyrights and Licenses — UIFlow2 Programming Guide master documentation](#copyrights-and-licenses-uiflow2-programming-guide-master-documentation) - [AtomS3 — UIFlow2 Programming Guide master documentation](#atoms3-uiflow2-programming-guide-master-documentation) - [CoreS3 — UIFlow2 Programming Guide master documentation](#cores3-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [AtomS3 Lite — UIFlow2 Programming Guide master documentation](#atoms3-lite-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [audio — player and recorder — UIFlow2 Programming Guide master documentation](#audio-player-and-recorder-uiflow2-programming-guide-master-documentation) - [bleuart — UART/Serial Port Emulation over BLE — UIFlow2 Programming Guide master documentation](#bleuart-uart-serial-port-emulation-over-ble-uiflow2-programming-guide-master-documentation) - [AtomS3U — UIFlow2 Programming Guide master documentation](#atoms3u-uiflow2-programming-guide-master-documentation) - [modbus – a Modbus library — UIFlow2 Programming Guide master documentation](#modbus-a-modbus-library-uiflow2-programming-guide-master-documentation) - [class Circle – display circle — UIFlow2 Programming Guide master documentation](#class-circle-display-circle-uiflow2-programming-guide-master-documentation) - [Power — UIFlow2 Programming Guide master documentation](#power-uiflow2-programming-guide-master-documentation) - [ADC (analog to digital conversion) — UIFlow2 Programming Guide master documentation](#adc-analog-to-digital-conversion-uiflow2-programming-guide-master-documentation) - [Cardputer — UIFlow2 Programming Guide master documentation](#cardputer-uiflow2-programming-guide-master-documentation) - [StampS3 — UIFlow2 Programming Guide master documentation](#stamps3-uiflow2-programming-guide-master-documentation) - [M5 BLE — UIFlow2 Programming Guide master documentation](#m5-ble-uiflow2-programming-guide-master-documentation) - [class Image – display image — UIFlow2 Programming Guide master documentation](#class-image-display-image-uiflow2-programming-guide-master-documentation) - [4In8Out Module — UIFlow2 Programming Guide master documentation](#4in8out-module-uiflow2-programming-guide-master-documentation) - [CoreInk — UIFlow2 Programming Guide master documentation](#coreink-uiflow2-programming-guide-master-documentation) - [ADC Hat — UIFlow2 Programming Guide master documentation](#adc-hat-uiflow2-programming-guide-master-documentation) - [AIN4 Module — UIFlow2 Programming Guide master documentation](#ain4-module-uiflow2-programming-guide-master-documentation) - [AirQ — UIFlow2 Programming Guide master documentation](#airq-uiflow2-programming-guide-master-documentation) - [CardKB Hat — UIFlow2 Programming Guide master documentation](#cardkb-hat-uiflow2-programming-guide-master-documentation) - [USB Drivers — UIFlow2 Programming Guide master documentation](#usb-drivers-uiflow2-programming-guide-master-documentation) - [DAC Hat — UIFlow2 Programming Guide master documentation](#dac-hat-uiflow2-programming-guide-master-documentation) - [Bala2 Module — UIFlow2 Programming Guide master documentation](#bala2-module-uiflow2-programming-guide-master-documentation) - [Paper — UIFlow2 Programming Guide master documentation](#paper-uiflow2-programming-guide-master-documentation) - [Commu Module — UIFlow2 Programming Guide master documentation](#commu-module-uiflow2-programming-guide-master-documentation) - [camera — UIFlow2 Programming Guide master documentation](#camera-uiflow2-programming-guide-master-documentation) - [API Documentation Template — UIFlow2 Programming Guide master documentation](#api-documentation-template-uiflow2-programming-guide-master-documentation) - [DinMeter — UIFlow2 Programming Guide master documentation](#dinmeter-uiflow2-programming-guide-master-documentation) - [DAC2 Hat — UIFlow2 Programming Guide master documentation](#dac2-hat-uiflow2-programming-guide-master-documentation) - [DLight Hat — UIFlow2 Programming Guide master documentation](#dlight-hat-uiflow2-programming-guide-master-documentation) - [Display Module — UIFlow2 Programming Guide master documentation](#display-module-uiflow2-programming-guide-master-documentation) - [code_scanner — UIFlow2 Programming Guide master documentation](#code-scanner-uiflow2-programming-guide-master-documentation) - [DMX512 Module — UIFlow2 Programming Guide master documentation](#dmx512-module-uiflow2-programming-guide-master-documentation) - [ENV Hat — UIFlow2 Programming Guide master documentation](#env-hat-uiflow2-programming-guide-master-documentation) - [dl — deep learning — UIFlow2 Programming Guide master documentation](#dl-deep-learning-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [USB Mode — UIFlow2 Programming Guide master documentation](#usb-mode-uiflow2-programming-guide-master-documentation) - [DualKmeter Module — UIFlow2 Programming Guide master documentation](#dualkmeter-module-uiflow2-programming-guide-master-documentation) - [image — UIFlow2 Programming Guide master documentation](#image-uiflow2-programming-guide-master-documentation) - [ECG Module — UIFlow2 Programming Guide master documentation](#ecg-module-uiflow2-programming-guide-master-documentation) - [Finger Hat — UIFlow2 Programming Guide master documentation](#finger-hat-uiflow2-programming-guide-master-documentation) - [jpg — UIFlow2 Programming Guide master documentation](#jpg-uiflow2-programming-guide-master-documentation) - [Heart Hat — UIFlow2 Programming Guide master documentation](#heart-hat-uiflow2-programming-guide-master-documentation) - [JoyC Hat — UIFlow2 Programming Guide master documentation](#joyc-hat-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [4EncoderMotor Module — UIFlow2 Programming Guide master documentation](#4encodermotor-module-uiflow2-programming-guide-master-documentation) - [Joystick Hat — UIFlow2 Programming Guide master documentation](#joystick-hat-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Fan v1.1 Module — UIFlow2 Programming Guide master documentation](#fan-v1-1-module-uiflow2-programming-guide-master-documentation) - [MiniEncoderC Hat — UIFlow2 Programming Guide master documentation](#miniencoderc-hat-uiflow2-programming-guide-master-documentation) - [GatewayH2 Module — UIFlow2 Programming Guide master documentation](#gatewayh2-module-uiflow2-programming-guide-master-documentation) - [GNSS Module — UIFlow2 Programming Guide master documentation](#gnss-module-uiflow2-programming-guide-master-documentation) - [MiniJoyC Hat — UIFlow2 Programming Guide master documentation](#minijoyc-hat-uiflow2-programming-guide-master-documentation) - [NCIR Hat — UIFlow2 Programming Guide master documentation](#ncir-hat-uiflow2-programming-guide-master-documentation) - [GPS Module — UIFlow2 Programming Guide master documentation](#gps-module-uiflow2-programming-guide-master-documentation) - [Atomic TFCard Base — UIFlow2 Programming Guide master documentation](#atomic-tfcard-base-uiflow2-programming-guide-master-documentation) - [GPS V2.0 Module — UIFlow2 Programming Guide master documentation](#gps-v2-0-module-uiflow2-programming-guide-master-documentation) - [NeoFlash Hat — UIFlow2 Programming Guide master documentation](#neoflash-hat-uiflow2-programming-guide-master-documentation) - [PIR Hat — UIFlow2 Programming Guide master documentation](#pir-hat-uiflow2-programming-guide-master-documentation) - [GRBL Module — UIFlow2 Programming Guide master documentation](#grbl-module-uiflow2-programming-guide-master-documentation) - [GoPlus2Module — UIFlow2 Programming Guide master documentation](#goplus2module-uiflow2-programming-guide-master-documentation) - [Servos8 Hat — UIFlow2 Programming Guide master documentation](#servos8-hat-uiflow2-programming-guide-master-documentation) - [Speaker Hat — UIFlow2 Programming Guide master documentation](#speaker-hat-uiflow2-programming-guide-master-documentation) - [HMI Module — UIFlow2 Programming Guide master documentation](#hmi-module-uiflow2-programming-guide-master-documentation) - [Servo Hat — UIFlow2 Programming Guide master documentation](#servo-hat-uiflow2-programming-guide-master-documentation) - [Lora Module — UIFlow2 Programming Guide master documentation](#lora-module-uiflow2-programming-guide-master-documentation) - [LLM Module — UIFlow2 Programming Guide master documentation](#llm-module-uiflow2-programming-guide-master-documentation) - [Speaker2 Hat — UIFlow2 Programming Guide master documentation](#speaker2-hat-uiflow2-programming-guide-master-documentation) - [LoRa868 v1.2 Module — UIFlow2 Programming Guide master documentation](#lora868-v1-2-module-uiflow2-programming-guide-master-documentation) - [Thermal Hat — UIFlow2 Programming Guide master documentation](#thermal-hat-uiflow2-programming-guide-master-documentation) - [LoRaWAN868 Module — UIFlow2 Programming Guide master documentation](#lorawan868-module-uiflow2-programming-guide-master-documentation) - [ToF Hat — UIFlow2 Programming Guide master documentation](#tof-hat-uiflow2-programming-guide-master-documentation) - [NB-IoT Module — UIFlow2 Programming Guide master documentation](#nb-iot-module-uiflow2-programming-guide-master-documentation) - [COMX LTE Module — UIFlow2 Programming Guide master documentation](#comx-lte-module-uiflow2-programming-guide-master-documentation) - [ODrive Module — UIFlow2 Programming Guide master documentation](#odrive-module-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [PLUS Module — UIFlow2 Programming Guide master documentation](#plus-module-uiflow2-programming-guide-master-documentation) - [Vibrator HAT — UIFlow2 Programming Guide master documentation](#vibrator-hat-uiflow2-programming-guide-master-documentation) - [requests2 — Network Request Module — UIFlow2 Programming Guide master documentation](#requests2-network-request-module-uiflow2-programming-guide-master-documentation) - [PM2.5 Module — UIFlow2 Programming Guide master documentation](#pm2-5-module-uiflow2-programming-guide-master-documentation) - [time – time related functions — UIFlow2 Programming Guide master documentation](#time-time-related-functions-uiflow2-programming-guide-master-documentation) - [class ImagePlus – display remote image — UIFlow2 Programming Guide master documentation](#class-imageplus-display-remote-image-uiflow2-programming-guide-master-documentation) - [PPS Module — UIFlow2 Programming Guide master documentation](#pps-module-uiflow2-programming-guide-master-documentation) - [PwrCAN Module — UIFlow2 Programming Guide master documentation](#pwrcan-module-uiflow2-programming-guide-master-documentation) - [Relay2 Module — UIFlow2 Programming Guide master documentation](#relay2-module-uiflow2-programming-guide-master-documentation) - [Servo2 Module — UIFlow2 Programming Guide master documentation](#servo2-module-uiflow2-programming-guide-master-documentation) - [StepMotorDriver Module — UIFlow2 Programming Guide master documentation](#stepmotordriver-module-uiflow2-programming-guide-master-documentation) - [RCA Module — UIFlow2 Programming Guide master documentation](#rca-module-uiflow2-programming-guide-master-documentation) - [QRCode Module — UIFlow2 Programming Guide master documentation](#qrcode-module-uiflow2-programming-guide-master-documentation) - [RS232F/M Module — UIFlow2 Programming Guide master documentation](#rs232f-m-module-uiflow2-programming-guide-master-documentation) - [USB Module — UIFlow2 Programming Guide master documentation](#usb-module-uiflow2-programming-guide-master-documentation) - [Zigbee Module — UIFlow2 Programming Guide master documentation](#zigbee-module-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Zigbee Unit — UIFlow2 Programming Guide master documentation](#zigbee-unit-uiflow2-programming-guide-master-documentation) - [class Label – display text — UIFlow2 Programming Guide master documentation](#class-label-display-text-uiflow2-programming-guide-master-documentation) - [ALS — UIFlow2 Programming Guide master documentation](#als-uiflow2-programming-guide-master-documentation) - [umqtt – a simple MQTT client — UIFlow2 Programming Guide master documentation](#umqtt-a-simple-mqtt-client-uiflow2-programming-guide-master-documentation) - [M5-ESPNOW — UIFlow2 Programming Guide master documentation](#m5-espnow-uiflow2-programming-guide-master-documentation) - [Button — UIFlow2 Programming Guide master documentation](#button-uiflow2-programming-guide-master-documentation) - [TCP — UIFlow2 Programming Guide master documentation](#tcp-uiflow2-programming-guide-master-documentation) - [ACMeasure Unit — UIFlow2 Programming Guide master documentation](#acmeasure-unit-uiflow2-programming-guide-master-documentation) - [WLAN STA – control built-in WiFi interfaces — UIFlow2 Programming Guide master documentation](#wlan-sta-control-built-in-wifi-interfaces-uiflow2-programming-guide-master-documentation) - [CAN — UIFlow2 Programming Guide master documentation](#can-uiflow2-programming-guide-master-documentation) - [Accel Unit — UIFlow2 Programming Guide master documentation](#accel-unit-uiflow2-programming-guide-master-documentation) - [WLAN AP – control built-in WiFi interfaces — UIFlow2 Programming Guide master documentation](#wlan-ap-control-built-in-wifi-interfaces-uiflow2-programming-guide-master-documentation) - [WDT — UIFlow2 Programming Guide master documentation](#wdt-uiflow2-programming-guide-master-documentation) - [Atom Socket Base — UIFlow2 Programming Guide master documentation](#atom-socket-base-uiflow2-programming-guide-master-documentation) - [UDP — UIFlow2 Programming Guide master documentation](#udp-uiflow2-programming-guide-master-documentation) - [ADC Unit — UIFlow2 Programming Guide master documentation](#adc-unit-uiflow2-programming-guide-master-documentation) - [ACSSR Unit — UIFlow2 Programming Guide master documentation](#acssr-unit-uiflow2-programming-guide-master-documentation) - [Atom DTU LoRaWAN-Series Base — UIFlow2 Programming Guide master documentation](#atom-dtu-lorawan-series-base-uiflow2-programming-guide-master-documentation) - [Display — UIFlow2 Programming Guide master documentation](#display-uiflow2-programming-guide-master-documentation) - [Get Started — UIFlow2 Programming Guide master documentation](#get-started-uiflow2-programming-guide-master-documentation) - [IMU — UIFlow2 Programming Guide master documentation](#imu-uiflow2-programming-guide-master-documentation) - [Atomic CAN Base — UIFlow2 Programming Guide master documentation](#atomic-can-base-uiflow2-programming-guide-master-documentation) - [ADC V1.1 Unit — UIFlow2 Programming Guide master documentation](#adc-v1-1-unit-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [IR — UIFlow2 Programming Guide master documentation](#ir-uiflow2-programming-guide-master-documentation) - [AIN4-20mA Unit — UIFlow2 Programming Guide master documentation](#ain4-20ma-unit-uiflow2-programming-guide-master-documentation) - [Atomic GPS Base — UIFlow2 Programming Guide master documentation](#atomic-gps-base-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Angle Unit — UIFlow2 Programming Guide master documentation](#angle-unit-uiflow2-programming-guide-master-documentation) - [Mic — UIFlow2 Programming Guide master documentation](#mic-uiflow2-programming-guide-master-documentation) - [Pin — UIFlow2 Programming Guide master documentation](#pin-uiflow2-programming-guide-master-documentation) - [Atomic Display Base — UIFlow2 Programming Guide master documentation](#atomic-display-base-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Atomic Echo Base — UIFlow2 Programming Guide master documentation](#atomic-echo-base-uiflow2-programming-guide-master-documentation) - [Unknown](#unknown) - [Angle8 Unit — UIFlow2 Programming Guide master documentation](#angle8-unit-uiflow2-programming-guide-master-documentation) - [PLC I/O — UIFlow2 Programming Guide master documentation](#plc-i-o-uiflow2-programming-guide-master-documentation) - [Atomic HDriver Base — UIFlow2 Programming Guide master documentation](#atomic-hdriver-base-uiflow2-programming-guide-master-documentation) - [ASR Unit — UIFlow2 Programming Guide master documentation](#asr-unit-uiflow2-programming-guide-master-documentation) - [PWR485 — UIFlow2 Programming Guide master documentation](#pwr485-uiflow2-programming-guide-master-documentation) - [BPS Unit — UIFlow2 Programming Guide master documentation](#bps-unit-uiflow2-programming-guide-master-documentation) - [Atomic Motion Base — UIFlow2 Programming Guide master documentation](#atomic-motion-base-uiflow2-programming-guide-master-documentation) - [Atomic PWM Base — UIFlow2 Programming Guide master documentation](#atomic-pwm-base-uiflow2-programming-guide-master-documentation) - [Rotary — UIFlow2 Programming Guide master documentation](#rotary-uiflow2-programming-guide-master-documentation) - [Button Unit — UIFlow2 Programming Guide master documentation](#button-unit-uiflow2-programming-guide-master-documentation) - [SCD40 — UIFlow2 Programming Guide master documentation](#scd40-uiflow2-programming-guide-master-documentation) --- # UiFlow2 documentation and references — UIFlow2 Programming Guide master documentation * [](#) * UiFlow2 documentation and references * [View page source](_sources/index.rst.txt) * * * UiFlow2 documentation and references[](#uiflow2-documentation-and-references "Link to this heading") ====================================================================================================== * [Get Started](get-started/index.html) * [CORE](get-started/index.html#core) * [STICK](get-started/index.html#stick) * [ATOM](get-started/index.html#atom) * [MicroPython libraries](library/index.html) * [Controllers](controllers/index.html) * [CoreS3](controllers/cores3.html) * [AtomS3](controllers/atoms3.html) * [AtomS3 Lite](controllers/atoms3-lite.html) * [AtomS3U](controllers/atoms3u.html) * [StampS3](controllers/stamps3.html) * [Cardputer](controllers/cardputer.html) * [Startup UI](controllers/cardputer.html#startup-ui) * [CoreInk](controllers/coreink.html) * [UI](controllers/coreink.html#ui) * [AirQ](controllers/airq.html) * [UI](controllers/airq.html#ui) * [Paper](controllers/paper.html) * [UI](controllers/paper.html#ui) * [DinMeter](controllers/dinmeter.html) * [Startup UI](controllers/dinmeter.html#startup-ui) * [System](system/index.html) * [`audio` — player and recorder](system/audio.html) * [Classes](system/audio.html#classes) * [`bleuart` — UART/Serial Port Emulation over BLE](system/bleuart.html) * [Classes](system/bleuart.html#classes) * [M5 BLE](system/m5ble.html) * [M5BLE](system/m5ble.html#m5ble) * [Constructor](system/m5ble.html#constructor) * [Device Methods](system/m5ble.html#device-methods) * [Client Methods](system/m5ble.html#client-methods) * [Server Methods](system/m5ble.html#server-methods) * [Server - connected\_client\_handle Methods](system/m5ble.html#server-connected-client-handle-methods) * [Power](system/power.html) * [class Power](system/power.html#class-power) * [Methods](system/power.html#methods) * [class PORT](system/power.html#class-port) * [Constants](system/power.html#constants) * [`time` – time related functions](system/time.html) * [Functions](system/time.html#functions) * [M5-ESPNOW](system/m5espnow.html) * [class M5ESPNow](system/m5espnow.html#class-m5espnow) * [Constructors](system/m5espnow.html#constructors) * [Methods](system/m5espnow.html#methods) * [WLAN STA – control built-in WiFi interfaces](system/wlan.sta.html) * [Constructors](system/wlan.sta.html#constructors) * [Methods](system/wlan.sta.html#methods) * [WLAN AP – control built-in WiFi interfaces](system/wlan.ap.html) * [Constructors](system/wlan.ap.html#constructors) * [Methods](system/wlan.ap.html#methods) * [Constants](system/wlan.ap.html#constants) * [`Widgets` — A basic UI library](widgets/index.html) * [Screen functions](widgets/index.html#screen-functions) * [`Widgets.setBrightness()`](widgets/index.html#Widgets.Widgets.setBrightness) * [`Widgets.fillScreen()`](widgets/index.html#Widgets.Widgets.fillScreen) * [`Widgets.setRotation()`](widgets/index.html#Widgets.Widgets.setRotation) * [Classes](widgets/index.html#classes) * [class Circle – display circle](widgets/circle.html) * [class Image – display image](widgets/image.html) * [class ImagePlus – display remote image](widgets/image%2B.html) * [class Label – display text](widgets/label.html) * [Software](software/index.html) * [`modbus` – a Modbus library](software/modbus.html) * [Classes](software/modbus.html#classes) * [`requests2` — Network Request Module](software/requests2.html) * [Function](software/requests2.html#function) * [class Response](software/requests2.html#class-response) * [Methods](software/requests2.html#methods) * [`umqtt` – a simple MQTT client](software/umqtt.html) * [Supported MQTT features](software/umqtt.html#supported-mqtt-features) * [Design requirements](software/umqtt.html#design-requirements) * [MQTT client with automatic reconnect](software/umqtt.html#mqtt-client-with-automatic-reconnect) * [MQTT client with SSL file](software/umqtt.html#mqtt-client-with-ssl-file) * [API design](software/umqtt.html#api-design) * [Classes](software/umqtt.html#classes) * [TCP](software/tcp.html) * [API](software/tcp.html#api) * [UDP](software/udp.html) * [API](software/udp.html#api) * [Hardware](hardware/index.html) * [ADC (analog to digital conversion)](hardware/adc.html) * [class ADC](hardware/adc.html#class-adc) * [Methods](hardware/adc.html#methods) * [ALS](hardware/als.html) * [class ALS](hardware/als.html#class-als) * [Methods](hardware/als.html#methods) * [Button](hardware/button.html) * [class Button](hardware/button.html#class-button) * [Methods](hardware/button.html#methods) * [Event Handling](hardware/button.html#event-handling) * [Constants](hardware/button.html#constants) * [class Callback\_Type](hardware/button.html#class-callback-type) * [Constants](hardware/button.html#id1) * [CAN](hardware/can.html) * [Constructors](hardware/can.html#constructors) * [Methods](hardware/can.html#methods) * [Constants](hardware/can.html#constants) * [Display](hardware/display.html) * [Micropython Example](hardware/display.html#micropython-example) * [Functions](hardware/display.html#functions) * [IMU](hardware/imu.html) * [class IMU](hardware/imu.html#class-imu) * [Methods](hardware/imu.html#methods) * [class IMU\_TYPE](hardware/imu.html#class-imu-type) * [Constants](hardware/imu.html#constants) * [IR](hardware/ir.html) * [class IR](hardware/ir.html#class-ir) * [Constructors](hardware/ir.html#constructors) * [Methods](hardware/ir.html#methods) * [Mic](hardware/mic.html) * [class Mic](hardware/mic.html#class-mic) * [Methods](hardware/mic.html#methods) * [class mic\_config\_t](hardware/mic.html#class-mic-config-t) * [Pin](hardware/pin.html) * [class Pin](hardware/pin.html#class-pin) * [Constructors](hardware/pin.html#constructors) * [Methods](hardware/pin.html#methods) * [Constants](hardware/pin.html#constants) * [PLC I/O](hardware/plcio.html) * [UiFlow2 Example](hardware/plcio.html#uiflow2-example) * [MicroPython Example](hardware/plcio.html#micropython-example) * [API](hardware/plcio.html#api) * [PWR485](hardware/pwr485.html) * [UiFlow2 Example](hardware/pwr485.html#uiflow2-example) * [MicroPython Example](hardware/pwr485.html#micropython-example) * [MicroPython Example](hardware/pwr485.html#id2) * [**API**](hardware/pwr485.html#api) * [Rotary](hardware/rotary.html) * [class Rotary](hardware/rotary.html#class-rotary) * [Constructors](hardware/rotary.html#constructors) * [Methods](hardware/rotary.html#methods) * [SCD40](hardware/scd40.html) * [class SCD40](hardware/scd40.html#class-scd40) * [Constructors](hardware/scd40.html#constructors) * [Methods](hardware/scd40.html#methods) * [SEN55](hardware/sen55.html) * [class SEN55](hardware/sen55.html#class-sen55) * [Constructors](hardware/sen55.html#constructors) * [Methods](hardware/sen55.html#methods) * [Speaker](hardware/speaker.html) * [class Speaker](hardware/speaker.html#class-speaker) * [Methods](hardware/speaker.html#methods) * [UART](hardware/uart.html) * [UiFlow2 Example](hardware/uart.html#uiflow2-example) * [MicroPython Example](hardware/uart.html#micropython-example) * [**API**](hardware/uart.html#api) * [WDT](hardware/wdt.html) * [class WDT – watchdog timer](hardware/wdt.html#class-wdt-watchdog-timer) * [Constructors](hardware/wdt.html#constructors) * [Methods](hardware/wdt.html#methods) * [Module](module/index.html) * [4In8Out Module](module/4in8out.html) * [class Module4In8Out](module/4in8out.html#class-module4in8out) * [Constructors](module/4in8out.html#constructors) * [Methods](module/4in8out.html#methods) * [AIN4 Module](module/ain4.html) * [class AIN4Module](module/ain4.html#class-ain4module) * [Constructors](module/ain4.html#constructors) * [Methods](module/ain4.html#methods) * [Bala2 Module](module/bala2.html) * [UiFlow2 Example](module/bala2.html#uiflow2-example) * [MicroPython Example](module/bala2.html#micropython-example) * [**API**](module/bala2.html#api) * [Commu Module](module/commu.html) * [UiFlow2 Example](module/commu.html#uiflow2-example) * [MicroPython Example](module/commu.html#micropython-example) * [**API**](module/commu.html#api) * [Display Module](module/display.html) * [UiFlow2 Example](module/display.html#uiflow2-example) * [MicroPython Example](module/display.html#micropython-example) * [**API**](module/display.html#api) * [DMX512 Module](module/dmx.html) * [class DMX512Module](module/dmx.html#class-dmx512module) * [Constructors](module/dmx.html#constructors) * [Methods](module/dmx.html#methods) * [DualKmeter Module](module/dualkmeter.html) * [class DualKmeterModule](module/dualkmeter.html#class-dualkmetermodule) * [Constructors](module/dualkmeter.html#constructors) * [Methods](module/dualkmeter.html#methods) * [Constants](module/dualkmeter.html#constants) * [ECG Module](module/ecg.html) * [UiFlow2 Example:](module/ecg.html#uiflow2-example) * [MicroPython Example:](module/ecg.html#micropython-example) * [**API**](module/ecg.html#api) * [4EncoderMotor Module](module/encoder4_motor.html) * [UiFlow2 Example](module/encoder4_motor.html#uiflow2-example) * [MicroPython Example](module/encoder4_motor.html#micropython-example) * [**API**](module/encoder4_motor.html#api) * [Fan v1.1 Module](module/fan.html) * [UiFlow2 Example](module/fan.html#uiflow2-example) * [MicroPython Example](module/fan.html#micropython-example) * [**API**](module/fan.html#api) * [GatewayH2 Module](module/gateway_h2.html) * [UiFlow2 Example:](module/gateway_h2.html#uiflow2-example) * [MicroPython Example:](module/gateway_h2.html#micropython-example) * [**API**](module/gateway_h2.html#api) * [GNSS Module](module/gnss.html) * [class GNSSModule](module/gnss.html#class-gnssmodule) * [Constructors](module/gnss.html#constructors) * [Methods](module/gnss.html#methods) * [GPS Module](module/gps.html) * [class GPSModule](module/gps.html#class-gpsmodule) * [Constructors](module/gps.html#constructors) * [Methods](module/gps.html#methods) * [GPS V2.0 Module](module/gpsv2.html) * [class GPSV2Module](module/gpsv2.html#class-gpsv2module) * [Constructors](module/gpsv2.html#constructors) * [Methods](module/gpsv2.html#methods) * [GRBL Module](module/grbl.html) * [class GRBLModule](module/grbl.html#class-grblmodule) * [Constructors](module/grbl.html#constructors) * [Methods](module/grbl.html#methods) * [Constants](module/grbl.html#constants) * [GoPlus2Module](module/goplus2.html) * [class GoPlus2Module](module/goplus2.html#class-goplus2module) * [Constructors](module/goplus2.html#constructors) * [Methods](module/goplus2.html#methods) * [HMI Module](module/hmi.html) * [class HMIModule](module/hmi.html#class-hmimodule) * [Constructors](module/hmi.html#constructors) * [Methods](module/hmi.html#methods) * [LLM Module](module/llm.html) * [class LlmModule](module/llm.html#class-llmmodule) * [Constructors](module/llm.html#constructors) * [Methods](module/llm.html#methods) * [Lora Module](module/lora.html) * [class LoraModule](module/lora.html#class-loramodule) * [Constructors](module/lora.html#constructors) * [Methods](module/lora.html#methods) * [Constants](module/lora.html#constants) * [LoRa868 v1.2 Module](module/lora_sx1262.html) * [UiFlow2 Example](module/lora_sx1262.html#uiflow2-example) * [MicroPython Example](module/lora_sx1262.html#micropython-example) * [**API**](module/lora_sx1262.html#api) * [LoRaWAN868 Module](module/lorawan868.html) * [class LoRaWAN868Module](module/lorawan868.html#class-lorawan868module) * [Constructors](module/lorawan868.html#constructors) * [Methods](module/lorawan868.html#methods) * [Constants](module/lorawan868.html#constants) * [COMX LTE Module](module/lte.html) * [UiFlow2 Example](module/lte.html#uiflow2-example) * [MicroPython Example](module/lte.html#micropython-example) * [**API**](module/lte.html#api) * [NB-IoT Module](module/nbiot.html) * [class NBIOTModule](module/nbiot.html#class-nbiotmodule) * [Constructors](module/nbiot.html#constructors) * [ODrive Module](module/odrive.html) * [class ODriveModule](module/odrive.html#class-odrivemodule) * [Constructors](module/odrive.html#constructors) * [Methods](module/odrive.html#methods) * [Constants](module/odrive.html#constants) * [PLUS Module](module/plus.html) * [class PLUSModule](module/plus.html#class-plusmodule) * [Constructors](module/plus.html#constructors) * [Methods](module/plus.html#methods) * [PM2.5 Module](module/pm25.html) * [class PM25Module](module/pm25.html#class-pm25module) * [Constructors](module/pm25.html#constructors) * [Methods](module/pm25.html#methods) * [PPS Module](module/pps.html) * [class PPSModule](module/pps.html#class-ppsmodule) * [Constructors](module/pps.html#constructors) * [Methods](module/pps.html#methods) * [PwrCAN Module](module/pwrcan.html) * [class PwrCANModule](module/pwrcan.html#class-pwrcanmodule) * [Constructors](module/pwrcan.html#constructors) * [Methods](module/pwrcan.html#methods) * [class PwrCANModuleRS485](module/pwrcan.html#class-pwrcanmodulers485) * [Constructors](module/pwrcan.html#id1) * [Methods](module/pwrcan.html#id2) * [QRCode Module](module/qrcode.html) * [UiFlow2 Example:](module/qrcode.html#uiflow2-example) * [MicroPython Example:](module/qrcode.html#micropython-example) * [**API**](module/qrcode.html#api) * [RCA Module](module/rca.html) * [UiFlow2 Example](module/rca.html#uiflow2-example) * [MicroPython Example](module/rca.html#micropython-example) * [**API**](module/rca.html#api) * [Relay2 Module](module/relay_2.html) * [class Relay2Module](module/relay_2.html#class-relay2module) * [Constructors](module/relay_2.html#constructors) * [Methods](module/relay_2.html#methods) * [RS232F/M Module](module/rs232.html) * [class RS232Module](module/rs232.html#class-rs232module) * [Constructors](module/rs232.html#constructors) * [Methods](module/rs232.html#methods) * [Servo2 Module](module/servo2.html) * [class Servo2Module](module/servo2.html#class-servo2module) * [Constructors](module/servo2.html#constructors) * [Methods](module/servo2.html#methods) * [StepMotorDriver Module](module/step_motor_driver.html) * [class StepMotorDriverModule](module/step_motor_driver.html#class-stepmotordrivermodule) * [Constructors](module/step_motor_driver.html#constructors) * [Methods](module/step_motor_driver.html#methods) * [Constants](module/step_motor_driver.html#constants) * [USB Module](module/usb.html) * [Micropython Example](module/usb.html#micropython-example) * [UIFlow2.0 Example](module/usb.html#uiflow2-0-example) * [class USBModule](module/usb.html#class-usbmodule) * [Constructors](module/usb.html#constructors) * [Zigbee Module](module/zigbee.html) * [class ZigbeeModule](module/zigbee.html#class-zigbeemodule) * [Constructors](module/zigbee.html#constructors) * [Methods](module/zigbee.html#methods) * [Unit](units/index.html) * [ACMeasure Unit](units/ac_measure.html) * [class ACMeasureUnit](units/ac_measure.html#class-acmeasureunit) * [Constructors](units/ac_measure.html#constructors) * [Methods](units/ac_measure.html#methods) * [Accel Unit](units/accel.html) * [UiFlow2 Example](units/accel.html#uiflow2-example) * [MicroPython Example](units/accel.html#micropython-example) * [**API**](units/accel.html#api) * [ACSSR Unit](units/acssr.html) * [class ACSSRUnit](units/acssr.html#class-acssrunit) * [Constructors](units/acssr.html#constructors) * [Methods](units/acssr.html#methods) * [ADC Unit](units/adc.html) * [class ADCUnit](units/adc.html#class-adcunit) * [Constructors](units/adc.html#constructors) * [Methods](units/adc.html#methods) * [ADC V1.1 Unit](units/adc_v11.html) * [class ADCV11Unit](units/adc_v11.html#class-adcv11unit) * [Constructors](units/adc_v11.html#constructors) * [Methods](units/adc_v11.html#methods) * [AIN4-20mA Unit](units/ain4.html) * [class AIN4\_20MAUnit](units/ain4.html#class-ain4-20maunit) * [Constructors](units/ain4.html#constructors) * [Methods](units/ain4.html#methods) * [Angle Unit](units/angle.html) * [class Angle](units/angle.html#class-angle) * [Constructors](units/angle.html#constructors) * [Methods](units/angle.html#methods) * [Angle8 Unit](units/angle8.html) * [class Angle8Unit](units/angle8.html#class-angle8unit) * [Constructors](units/angle8.html#constructors) * [Methods](units/angle8.html#methods) * [ASR Unit](units/asr.html) * [UiFlow2 Example](units/asr.html#uiflow2-example) * [MicroPython Example](units/asr.html#micropython-example) * [**API**](units/asr.html#api) * [BPS Unit](units/bps.html) * [class BPSUnit](units/bps.html#class-bpsunit) * [Constructors](units/bps.html#constructors) * [Methods](units/bps.html#methods) * [Button Unit](units/button.html) * [class ButtonUnit](units/button.html#class-buttonunit) * [Constructors](units/button.html#constructors) * [Methods](units/button.html#methods) * [Buzzer Unit](units/buzzer.html) * [class BuzzerUnit](units/buzzer.html#class-buzzerunit) * [Constructors](units/buzzer.html#constructors) * [Methods](units/buzzer.html#methods) * [ByteButton Unit](units/bytebutton.html) * [class ByteButtonUnit](units/bytebutton.html#class-bytebuttonunit) * [Constructors](units/bytebutton.html#constructors) * [Methods](units/bytebutton.html#methods) * [ByteSwitch Unit](units/byteswitch.html) * [class ByteSwitchUnit](units/byteswitch.html#class-byteswitchunit) * [Constructors](units/byteswitch.html#constructors) * [Methods](units/byteswitch.html#methods) * [CAN Unit](units/can.html) * [class CANUnit](units/can.html#class-canunit) * [Constructors](units/can.html#constructors) * [CardKB Unit](units/cardkb.html) * [class CardKBUnit](units/cardkb.html#class-cardkbunit) * [Constructors](units/cardkb.html#constructors) * [Methods](units/cardkb.html#methods) * [Catch Unit](units/catch.html) * [class CatchUnit](units/catch.html#class-catchunit) * [Constructors](units/catch.html#constructors) * [Methods](units/catch.html#methods) * [CO2 Unit](units/co2.html) * [class CO2Unit](units/co2.html#class-co2unit) * [Constructors](units/co2.html#constructors) * [Methods](units/co2.html#methods) * [CO2L Unit](units/co2l.html) * [class CO2LUnit](units/co2l.html#class-co2lunit) * [Constructors](units/co2l.html#constructors) * [Methods](units/co2l.html#methods) * [Color Unit](units/color.html) * [class ColorUnit](units/color.html#class-colorunit) * [Constructors](units/color.html#constructors) * [Methods](units/color.html#methods) * [DAC Unit](units/dac.html) * [class DACUnit](units/dac.html#class-dacunit) * [Constructors](units/dac.html#constructors) * [Methods](units/dac.html#methods) * [DAC2 Unit](units/dac2.html) * [class DAC2Unit](units/dac2.html#class-dac2unit) * [Constructors](units/dac2.html#constructors) * [Methods](units/dac2.html#methods) * [DCSSR Unit](units/dcssr.html) * [class DCSSRUnit](units/dcssr.html#class-dcssrunit) * [Constructors](units/dcssr.html#constructors) * [DDS Unit](units/dds.html) * [class DDSUnit](units/dds.html#class-ddsunit) * [Constructors](units/dds.html#constructors) * [Methods](units/dds.html#methods) * [Constants](units/dds.html#constants) * [DigiClock Unit](units/digi_clock.html) * [class DigiClockUnit](units/digi_clock.html#class-digiclockunit) * [Constructors](units/digi_clock.html#constructors) * [Methods](units/digi_clock.html#methods) * [DLight Unit](units/dlight.html) * [class DLight](units/dlight.html#class-dlight) * [Constructors](units/dlight.html#constructors) * [Methods](units/dlight.html#methods) * [DMX512 Unit](units/dmx.html) * [class DMX512Unit](units/dmx.html#class-dmx512unit) * [Constructors](units/dmx.html#constructors) * [Methods](units/dmx.html#methods) * [Dual\_Button Unit](units/dualbutton.html) * [class DualButton](units/dualbutton.html#class-dualbutton) * [Constructors](units/dualbutton.html#constructors) * [Methods](units/dualbutton.html#methods) * [EARTH Unit](units/earth.html) * [class Earth](units/earth.html#class-earth) * [Constructors](units/earth.html#constructors) * [Methods](units/earth.html#methods) * [Encoder Unit](units/encoder.html) * [class EncoderUnit](units/encoder.html#class-encoderunit) * [Constructors](units/encoder.html#constructors) * [Methods](units/encoder.html#methods) * [Encoder8 Unit](units/encoder8.html) * [class Encoder8Unit](units/encoder8.html#class-encoder8unit) * [Constructors](units/encoder8.html#constructors) * [Methods](units/encoder8.html#methods) * [ENV Unit](units/env.html) * [class ENVUnit](units/env.html#class-envunit) * [Constructors](units/env.html#constructors) * [Methods](units/env.html#methods) * [ENVPRO Unit](units/envpro.html) * [class ENVPROUnit](units/envpro.html#class-envprounit) * [Constructors](units/envpro.html#constructors) * [Methods](units/envpro.html#methods) * [Constants](units/envpro.html#constants) * [ExtEncoder Unit](units/extencoder.html) * [class ExtEncoderUnit](units/extencoder.html#class-extencoderunit) * [Constructors](units/extencoder.html#constructors) * [Methods](units/extencoder.html#methods) * [EXTIO Unit](units/extio.html) * [class EXTIOUnit](units/extio.html#class-extiounit) * [Constructors](units/extio.html#constructors) * [Methods](units/extio.html#methods) * [class Pin](units/extio.html#class-pin) * [Constructors](units/extio.html#id1) * [Methods](units/extio.html#id2) * [EXTIO2 Unit](units/extio2.html) * [class EXTIO2Unit](units/extio2.html#class-extio2unit) * [Constructors](units/extio2.html#constructors) * [Methods](units/extio2.html#methods) * [Fader Unit](units/fader.html) * [class FaderUnit](units/fader.html#class-faderunit) * [Constructors](units/fader.html#constructors) * [Methods](units/fader.html#methods) * [Finger Unit](units/finger.html) * [class FingerUnit](units/finger.html#class-fingerunit) * [Constructors](units/finger.html#constructors) * [Methods](units/finger.html#methods) * [FlashLight Unit](units/flash_light.html) * [class FlashLightUnit](units/flash_light.html#class-flashlightunit) * [Constructors](units/flash_light.html#constructors) * [Methods](units/flash_light.html#methods) * [Glass Unit](units/glass.html) * [UiFlow2 Example](units/glass.html#uiflow2-example) * [MicroPython Example](units/glass.html#micropython-example) * [**API**](units/glass.html#api) * [Glass2 Unit](units/glass2.html) * [UiFlow2 Example](units/glass2.html#uiflow2-example) * [MicroPython Example](units/glass2.html#micropython-example) * [**API**](units/glass2.html#api) * [class Glass2Unit](units/glass2.html#class-glass2unit) * [GPS V1.1(SMA) Unit](units/gps_v11.html) * [class GPSV11Unit](units/gps_v11.html#class-gpsv11unit) * [Constructors](units/gps_v11.html#constructors) * [Methods](units/gps_v11.html#methods) * [Grove2Grove Unit](units/grove2grove.html) * [class Grove2GroveUnit](units/grove2grove.html#class-grove2groveunit) * [Constructors](units/grove2grove.html#constructors) * [Methods](units/grove2grove.html#methods) * [Hall Effect Unit](units/hall_effect.html) * [class HallEffectUnit](units/hall_effect.html#class-halleffectunit) * [Constructors](units/hall_effect.html#constructors) * [Methods](units/hall_effect.html#methods) * [Constants](units/hall_effect.html#constants) * [Heart Unit](units/heart.html) * [class HeartUnit](units/heart.html#class-heartunit) * [Constructors](units/heart.html#constructors) * [Methods](units/heart.html#methods) * [Constants](units/heart.html#constants) * [ID Unit](units/id.html) * [class IDUnit](units/id.html#class-idunit) * [Constructors](units/id.html#constructors) * [Methods](units/id.html#methods) * [IMU Unit](units/imu.html) * [class IMUUnit](units/imu.html#class-imuunit) * [Constructors](units/imu.html#constructors) * [Methods](units/imu.html#methods) * [IMU Pro Unit](units/imupro.html) * [class IMUProUnit](units/imupro.html#class-imuprounit) * [Constructors](units/imupro.html#constructors) * [Methods](units/imupro.html#methods) * [IR Unit](units/ir.html) * [class IRUnit](units/ir.html#class-irunit) * [Constructors](units/ir.html#constructors) * [Methods](units/ir.html#methods) * [Joystick Unit](units/joystick.html) * [class JoystickUnit](units/joystick.html#class-joystickunit) * [Constructors](units/joystick.html#constructors) * [Methods](units/joystick.html#methods) * [Joystick2 Unit](units/joystick2.html) * [class Joystick2Unit](units/joystick2.html#class-joystick2unit) * [Constructors](units/joystick2.html#constructors) * [Methods](units/joystick2.html#methods) * [Key Unit](units/key.html) * [class KeyUnit](units/key.html#class-keyunit) * [Constructors](units/key.html#constructors) * [Methods](units/key.html#methods) * [Event Handling](units/key.html#event-handling) * [Constants](units/key.html#constants) * [class CB\_TYPE](units/key.html#class-cb-type) * [Constants](units/key.html#id1) * [Kmeter ISO Unit](units/kmeter_iso.html) * [class KmeterISOUnit](units/kmeter_iso.html#class-kmeterisounit) * [Constructors](units/kmeter_iso.html#constructors) * [Methods](units/kmeter_iso.html#methods) * [Constants](units/kmeter_iso.html#constants) * [Kmeter Unit](units/kmeter.html) * [class KmeterUnit](units/kmeter.html#class-kmeterunit) * [Constructors](units/kmeter.html#constructors) * [Methods](units/kmeter.html#methods) * [Constants](units/kmeter.html#constants) * [LaserRX Unit](units/laser_rx.html) * [class LaserRXUnit](units/laser_rx.html#class-laserrxunit) * [Constructors](units/laser_rx.html#constructors) * [Methods](units/laser_rx.html#methods) * [LaserTX Unit](units/laser_tx.html) * [class LaserTXUnit](units/laser_tx.html#class-lasertxunit) * [Constructors](units/laser_tx.html#constructors) * [Methods](units/laser_tx.html#methods) * [LCD Unit](units/lcd.html) * [UiFlow2 Example](units/lcd.html#uiflow2-example) * [MicroPython Example](units/lcd.html#micropython-example) * [**API**](units/lcd.html#api) * [Light Unit](units/light.html) * [class Light](units/light.html#class-light) * [Constructors](units/light.html#constructors) * [Methods](units/light.html#methods) * [Limit Unit](units/limit.html) * [class LimitUnit](units/limit.html#class-limitunit) * [Constructors](units/limit.html#constructors) * [Methods](units/limit.html#methods) * [LoRaE220 Unit](units/lora_e220.html) * [Working Mode](units/lora_e220.html#working-mode) * [class LoRaE220JPUnit](units/lora_e220.html#class-lorae220jpunit) * [Constructors](units/lora_e220.html#constructors) * [Methods](units/lora_e220.html#methods) * [Constants](units/lora_e220.html#constants) * [LoRaE220-433 Unit](units/lora_e220_433.html) * [Working Mode](units/lora_e220_433.html#working-mode) * [class LoRaE220433Unit](units/lora_e220_433.html#class-lorae220433unit) * [Constructors](units/lora_e220_433.html#constructors) * [Methods](units/lora_e220_433.html#methods) * [Constants](units/lora_e220_433.html#constants) * [LoRaWAN-X Unit](units/lorawan_rui3.html) * [class LoRaWAN\_X](units/lorawan_rui3.html#class-lorawan-x) * [Constructors](units/lorawan_rui3.html#constructors) * [Methods](units/lorawan_rui3.html#methods) * [MIDI Unit](units/midi.html) * [class MIDIUnit](units/midi.html#class-midiunit) * [Constructors](units/midi.html#constructors) * [Methods](units/midi.html#methods) * [MiniOLED Unit](units/minioled.html) * [UiFlow2 Example](units/minioled.html#uiflow2-example) * [MicroPython Example](units/minioled.html#micropython-example) * [**API**](units/minioled.html#api) * [Miniscale Unit](units/miniscale.html) * [class MiniScaleUnit](units/miniscale.html#class-miniscaleunit) * [Constructors](units/miniscale.html#constructors) * [Methods](units/miniscale.html#methods) * [MQTT Unit](units/mqtt.html) * [class MQTTUnit](units/mqtt.html#class-mqttunit) * [Constructors](units/mqtt.html#constructors) * [Methods](units/mqtt.html#methods) * [MQTTPoE Unit](units/mqttpoe.html) * [class MQTTPoEUnit](units/mqttpoe.html#class-mqttpoeunit) * [Constructors](units/mqttpoe.html#constructors) * [Methods](units/mqttpoe.html#methods) * [NB-IoT Unit](units/nbiot.html) * [class NBIOTUnit](units/nbiot.html#class-nbiotunit) * [Constructors](units/nbiot.html#constructors) * [Methods](units/nbiot.html#methods) * [NB-IoT2 Unit](units/nbiot2.html) * [class NBIOT2Unit](units/nbiot2.html#class-nbiot2unit) * [Constructors](units/nbiot2.html#constructors) * [Methods](units/nbiot2.html#methods) * [NCIR Unit](units/ncir.html) * [class NCIRUnit](units/ncir.html#class-ncirunit) * [Constructors](units/ncir.html#constructors) * [Methods](units/ncir.html#methods) * [NECO Unit](units/neco.html) * [class NECOUnit](units/neco.html#class-necounit) * [Constructors](units/neco.html#constructors) * [Methods](units/neco.html#methods) * [OLED Unit](units/oled.html) * [UiFlow2 Example](units/oled.html#uiflow2-example) * [MicroPython Example](units/oled.html#micropython-example) * [**API**](units/oled.html#api) * [OP90 Unit](units/op90.html) * [class OPUnit](units/op90.html#class-opunit) * [Constructors](units/op90.html#constructors) * [Methods](units/op90.html#methods) * [OP180 Unit](units/op180.html) * [class OPUnit](units/op180.html#class-opunit) * [Constructors](units/op180.html#constructors) * [Methods](units/op180.html#methods) * [PDM Unit](units/pdm.html) * [UiFlow2 Example](units/pdm.html#uiflow2-example) * [MicroPython Example](units/pdm.html#micropython-example) * [**API**](units/pdm.html#api) * [PIR Unit](units/pir.html) * [class PIR](units/pir.html#class-pir) * [Constructors](units/pir.html#constructors) * [Methods](units/pir.html#methods) * [Puzzle Unit](units/puzzle.html) * [class PuzzleUnit](units/puzzle.html#class-puzzleunit) * [Constructors](units/puzzle.html#constructors) * [Methods](units/puzzle.html#methods) * [QRCode Unit](units/qrcode.html) * [class QRCodeUnit](units/qrcode.html#class-qrcodeunit) * [Constructors](units/qrcode.html#constructors) * [Methods](units/qrcode.html#methods) * [RCA Unit](units/rca.html) * [UiFlow2 Example](units/rca.html#uiflow2-example) * [MicroPython Example](units/rca.html#micropython-example) * [**API**](units/rca.html#api) * [Reflective IR Unit](units/reflective_ir.html) * [class ReflectiveIRUnit](units/reflective_ir.html#class-reflectiveirunit) * [Constructors](units/reflective_ir.html#constructors) * [Methods](units/reflective_ir.html#methods) * [Constants](units/reflective_ir.html#constants) * [RELAY Unit](units/relay.html) * [class RelayUnit](units/relay.html#class-relayunit) * [Constructors](units/relay.html#constructors) * [Methods](units/relay.html#methods) * [Relay4 Unit](units/relay4.html) * [class Relay4Unit](units/relay4.html#class-relay4unit) * [Constructors](units/relay4.html#constructors) * [Methods](units/relay4.html#methods) * [RF433R Unit](units/rf433r.html) * [UiFlow2 Example:](units/rf433r.html#uiflow2-example) * [MicroPython Example:](units/rf433r.html#micropython-example) * [**API**](units/rf433r.html#api) * [RF433T Unit](units/rf433t.html) * [UiFlow2 Example:](units/rf433t.html#uiflow2-example) * [MicroPython Example:](units/rf433t.html#micropython-example) * [**API**](units/rf433t.html#api) * [RFID Unit](units/rfid.html) * [class RFIDUnit](units/rfid.html#class-rfidunit) * [Constructors](units/rfid.html#constructors) * [Methods](units/rfid.html#methods) * [RGB Unit](units/rgb.html) * [class RGB](units/rgb.html#class-rgb) * [Constructors](units/rgb.html#constructors) * [Methods](units/rgb.html#methods) * [Roller485 Unit](units/roller485.html) * [class Roller485Unit](units/roller485.html#class-roller485unit) * [Constructors](units/roller485.html#constructors) * [class RollerBase](units/roller485.html#class-rollerbase) * [Constructors](units/roller485.html#id1) * [Methods](units/roller485.html#methods) * [class RollerI2C(RollerBase)](units/roller485.html#class-rolleri2c-rollerbase) * [Constructors](units/roller485.html#id2) * [Methods](units/roller485.html#id3) * [class Roller485(RollerBase)](units/roller485.html#class-roller485-rollerbase) * [Constructors](units/roller485.html#id4) * [Methods](units/roller485.html#id5) * [class Roller485ToI2CBus(RollerBase)](units/roller485.html#class-roller485toi2cbus-rollerbase) * [Constructors](units/roller485.html#id6) * [Methods](units/roller485.html#id7) * [RollerCAN Unit](units/rollercan.html) * [class RollerCANUnit](units/rollercan.html#class-rollercanunit) * [Constructors](units/rollercan.html#constructors) * [class RollerBase](units/rollercan.html#class-rollerbase) * [Constructors](units/rollercan.html#id1) * [Methods](units/rollercan.html#methods) * [class RollerI2C(RollerBase)](units/rollercan.html#class-rolleri2c-rollerbase) * [Constructors](units/rollercan.html#id2) * [Methods](units/rollercan.html#id3) * [class RollerCAN(RollerBase)](units/rollercan.html#class-rollercan-rollerbase) * [Constructors](units/rollercan.html#id4) * [Methods](units/rollercan.html#id5) * [class RollerCANToI2CBus(RollerBase)](units/rollercan.html#class-rollercantoi2cbus-rollerbase) * [Constructors](units/rollercan.html#id6) * [Methods](units/rollercan.html#id7) * [Scales Unit](units/scales.html) * [class ScalesUnit](units/scales.html#class-scalesunit) * [Constructors](units/scales.html#constructors) * [Methods](units/scales.html#methods) * [Scroll Unit](units/scroll.html) * [class ScrollUnit](units/scroll.html#class-scrollunit) * [Constructors](units/scroll.html#constructors) * [Methods](units/scroll.html#methods) * [SSR Unit](units/ssr.html) * [class SSRUnit](units/ssr.html#class-ssrunit) * [Constructors](units/ssr.html#constructors) * [Methods](units/ssr.html#methods) * [Synth Unit](units/synth.html) * [class SynthUnit](units/synth.html#class-synthunit) * [Constructors](units/synth.html#constructors) * [Methods](units/synth.html#methods) * [Thermal Unit](units/thermal.html) * [class ThermalUnit](units/thermal.html#class-thermalunit) * [Constructors](units/thermal.html#constructors) * [Methods](units/thermal.html#methods) * [TimerPWR Unit](units/timerpwr.html) * [class TimerPWRUnit](units/timerpwr.html#class-timerpwrunit) * [Constructors](units/timerpwr.html#constructors) * [Methods](units/timerpwr.html#methods) * [Constants](units/timerpwr.html#constants) * [TMOS Unit](units/tmos.html) * [class TMOSUnit](units/tmos.html#class-tmosunit) * [Constructors](units/tmos.html#constructors) * [Methods](units/tmos.html#methods) * [ToF Unit](units/tof.html) * [class ToFUnit](units/tof.html#class-tofunit) * [Constructors](units/tof.html#constructors) * [Methods](units/tof.html#methods) * [TVOC Unit](units/tvoc.html) * [class TVOCUnit](units/tvoc.html#class-tvocunit) * [Constructors](units/tvoc.html#constructors) * [Methods](units/tvoc.html#methods) * [UHF-RFID Unit](units/uhf_rfid.html) * [class UHFRFIDUnit](units/uhf_rfid.html#class-uhfrfidunit) * [Constructors](units/uhf_rfid.html#constructors) * [Methods](units/uhf_rfid.html#methods) * [Ultrasonic Unit](units/ultrasonic.html) * [class ULTRASONIC\_I2C](units/ultrasonic.html#class-ultrasonic-i2c) * [Constructors](units/ultrasonic.html#constructors) * [Methods](units/ultrasonic.html#methods) * [UltrasoundIO Unit](units/ultrasonic_io.html) * [class UltrasoundIOUnit](units/ultrasonic_io.html#class-ultrasoundiounit) * [Constructors](units/ultrasonic_io.html#constructors) * [Methods](units/ultrasonic_io.html#methods) * [UWB Unit](units/uwb.html) * [class UWBUnit](units/uwb.html#class-uwbunit) * [Constructors](units/uwb.html#constructors) * [Methods](units/uwb.html#methods) * [Constants](units/uwb.html#constants) * [Vibrator Unit](units/vibrator.html) * [class VibratorUnit](units/vibrator.html#class-vibratorunit) * [Constructors](units/vibrator.html#constructors) * [Methods](units/vibrator.html#methods) * [Watering Unit](units/watering.html) * [class WateringUnit](units/watering.html#class-wateringunit) * [Constructors](units/watering.html#constructors) * [Methods](units/watering.html#methods) * [Weight Unit](units/weight.html) * [class WEIGHTUnit](units/weight.html#class-weightunit) * [Constructors](units/weight.html#constructors) * [Methods](units/weight.html#methods) * [Weight I2C Unit](units/weight_i2c.html) * [class WEIGHT\_I2CUnit](units/weight_i2c.html#class-weight-i2cunit) * [Constructors](units/weight_i2c.html#constructors) * [Methods](units/weight_i2c.html#methods) * [Zigbee Unit](units/zigbee.html) * [class ZigbeeUnit](units/zigbee.html#class-zigbeeunit) * [Constructors](units/zigbee.html#constructors) * [Methods](units/zigbee.html#methods) * [HAT](hats/index.html) * [ADC Hat](hats/adc.html) * [class CANUnit](hats/adc.html#class-canunit) * [Constructors](hats/adc.html#constructors) * [CardKB Hat](hats/cardkb.html) * [class CardKBHat](hats/cardkb.html#class-cardkbhat) * [Constructors](hats/cardkb.html#constructors) * [DAC Hat](hats/dac.html) * [class DACHat](hats/dac.html#class-dachat) * [Constructors](hats/dac.html#constructors) * [DAC2 Hat](hats/dac2.html) * [class DAC2Hat](hats/dac2.html#class-dac2hat) * [Constructors](hats/dac2.html#constructors) * [DLight Hat](hats/dlight.html) * [class DLightHat](hats/dlight.html#class-dlighthat) * [Constructors](hats/dlight.html#constructors) * [ENV Hat](hats/env.html) * [class ENVHat](hats/env.html#class-envhat) * [Constructors](hats/env.html#constructors) * [Methods](hats/env.html#methods) * [Finger Hat](hats/finger.html) * [class FingerHat](hats/finger.html#class-fingerhat) * [Constructors](hats/finger.html#constructors) * [Heart Hat](hats/heart.html) * [class HeartHat](hats/heart.html#class-hearthat) * [Constructors](hats/heart.html#constructors) * [Methods](hats/heart.html#methods) * [Constants](hats/heart.html#constants) * [JoyC Hat](hats/joyc.html) * [class JoyCHat](hats/joyc.html#class-joychat) * [Constructors](hats/joyc.html#constructors) * [Methods](hats/joyc.html#methods) * [Joystick Hat](hats/joystick.html) * [class JoystickHat](hats/joystick.html#class-joystickhat) * [Constructors](hats/joystick.html#constructors) * [Methods](hats/joystick.html#methods) * [MiniEncoderC Hat](hats/mini_encoder.html) * [class MiniEncoderCHat](hats/mini_encoder.html#class-miniencoderchat) * [Constructors](hats/mini_encoder.html#constructors) * [Methods](hats/mini_encoder.html#methods) * [MiniJoyC Hat](hats/mini_joy.html) * [class MiniJoyHat](hats/mini_joy.html#class-minijoyhat) * [Constructors](hats/mini_joy.html#constructors) * [Methods](hats/mini_joy.html#methods) * [NCIR Hat](hats/ncir.html) * [class NCIRHat](hats/ncir.html#class-ncirhat) * [Constructors](hats/ncir.html#constructors) * [NeoFlash Hat](hats/neoflash.html) * [class NeoFlashHat](hats/neoflash.html#class-neoflashhat) * [Constructors](hats/neoflash.html#constructors) * [Methods](hats/neoflash.html#methods) * [Constants](hats/neoflash.html#constants) * [PIR Hat](hats/pir.html) * [class PIRHat](hats/pir.html#class-pirhat) * [Constructors](hats/pir.html#constructors) * [Methods](hats/pir.html#methods) * [Servo Hat](hats/servo.html) * [class ServoHat](hats/servo.html#class-servohat) * [Constructors](hats/servo.html#constructors) * [Methods](hats/servo.html#methods) * [Servos8 Hat](hats/servo8.html) * [class Servos8Hat](hats/servo8.html#class-servos8hat) * [Constructors](hats/servo8.html#constructors) * [Methods](hats/servo8.html#methods) * [Speaker Hat](hats/speaker.html) * [class SpeakerHat](hats/speaker.html#class-speakerhat) * [Constructors](hats/speaker.html#constructors) * [Speaker2 Hat](hats/speaker2.html) * [UiFlow2 Example](hats/speaker2.html#uiflow2-example) * [MicroPython Example](hats/speaker2.html#micropython-example) * [**API**](hats/speaker2.html#api) * [Thermal Hat](hats/thermal.html) * [class ThermalHat](hats/thermal.html#class-thermalhat) * [Constructors](hats/thermal.html#constructors) * [ToF Hat](hats/tof.html) * [class ToFHat](hats/tof.html#class-tofhat) * [Constructors](hats/tof.html#constructors) * [Vibrator HAT](hats/vibrator.html) * [class VibratorHAT](hats/vibrator.html#class-vibratorhat) * [Constructors](hats/vibrator.html#constructors) * [Methods](hats/vibrator.html#methods) * [Base](base/index.html) * [Atom Socket Base](base/atom_socket.html) * [class ATOMSocketBase](base/atom_socket.html#class-atomsocketbase) * [Constructors](base/atom_socket.html#constructors) * [Methods](base/atom_socket.html#methods) * [Atom DTU LoRaWAN-Series Base](base/dtu_lorawan.html) * [UiFlow2 Example](base/dtu_lorawan.html#uiflow2-example) * [MicroPython Example](base/dtu_lorawan.html#micropython-example) * [**API**](base/dtu_lorawan.html#api) * [Atomic CAN Base](base/atom_can.html) * [UiFlow2 Example](base/atom_can.html#uiflow2-example) * [MicroPython Example](base/atom_can.html#micropython-example) * [**API**](base/atom_can.html#api) * [Atomic GPS Base](base/atom_gps.html) * [UiFlow2 Example](base/atom_gps.html#uiflow2-example) * [MicroPython Example](base/atom_gps.html#micropython-example) * [**API**](base/atom_gps.html#api) * [Atomic Display Base](base/display.html) * [UiFlow2 Example](base/display.html#uiflow2-example) * [MicroPython Example](base/display.html#micropython-example) * [**API**](base/display.html#api) * [Atomic Echo Base](base/echo.html) * [class ATOMEchoBase](base/echo.html#class-atomechobase) * [Constructors](base/echo.html#constructors) * [Attributes](base/echo.html#attributes) * [Atomic HDriver Base](base/hdriver.html) * [UiFlow2 Example:](base/hdriver.html#uiflow2-example) * [MicroPython Example:](base/hdriver.html#micropython-example) * [**API**](base/hdriver.html#api) * [Atomic Motion Base](base/motion.html) * [UiFlow2 Example:](base/motion.html#uiflow2-example) * [MicroPython Example:](base/motion.html#micropython-example) * [**API**](base/motion.html#api) * [Atomic PWM Base](base/pwm.html) * [UiFlow2 Example:](base/pwm.html#uiflow2-example) * [MicroPython Example:](base/pwm.html#micropython-example) * [**API**](base/pwm.html#api) * [Atomic QRCode Base](base/qrcode.html) * [UiFlow2 Example:](base/qrcode.html#uiflow2-example) * [MicroPython Example:](base/qrcode.html#micropython-example) * [**API**](base/qrcode.html#api) * [Atomic QRCode2 Base](base/qrcode2.html) * [UiFlow2 Example:](base/qrcode2.html#uiflow2-example) * [MicroPython Example:](base/qrcode2.html#micropython-example) * [**API**](base/qrcode2.html#api) * [Atomic RS232 Base](base/rs232.html) * [UiFlow2 Example](base/rs232.html#uiflow2-example) * [MicroPython Example](base/rs232.html#micropython-example) * [**API**](base/rs232.html#api) * [Atomic RS485 Base](base/rs485.html) * [UiFlow2 Example](base/rs485.html#uiflow2-example) * [MicroPython Example](base/rs485.html#micropython-example) * [**API**](base/rs485.html#api) * [Atomic Speaker Base](base/speaker.html) * [class SpeakerBase](base/speaker.html#class-speakerbase) * [Constructors](base/speaker.html#constructors) * [class SDCard](base/speaker.html#class-sdcard) * [Constructors](base/speaker.html#id1) * [Atomic Stepmotor Base](base/stepmotor.html) * [UiFlow2 Example:](base/stepmotor.html#uiflow2-example) * [MicroPython Example:](base/stepmotor.html#micropython-example) * [**API**](base/stepmotor.html#api) * [Atomic TFCard Base](base/tfcard.html) * [UiFlow2 Example](base/tfcard.html#uiflow2-example) * [MicroPython Example](base/tfcard.html#micropython-example) * [**API**](base/tfcard.html#api) * [Advanced](advanced/index.html) * [USB Drivers](advanced/usb/index.html) * [Modules](advanced/usb/index.html#modules) * [camera](advanced/camera.html) * [Micropython Example](advanced/camera.html#micropython-example) * [UIFlow2.0 Example](advanced/camera.html#uiflow2-0-example) * [Functions](advanced/camera.html#functions) * [code\_scanner](advanced/code_scanner.html) * [Micropython Example](advanced/code_scanner.html#micropython-example) * [UIFlow2.0 Example](advanced/code_scanner.html#uiflow2-0-example) * [Methods](advanced/code_scanner.html#methods) * [class image.QRCode](advanced/code_scanner.html#class-image-qrcode) * [dl — deep learning](advanced/dl.html) * [Micropython Example](advanced/dl.html#micropython-example) * [UIFlow2.0 Example](advanced/dl.html#uiflow2-0-example) * [Funtions](advanced/dl.html#funtions) * [class ObjectDetector](advanced/dl.html#class-objectdetector) * [class HumanFaceRecognizer](advanced/dl.html#class-humanfacerecognizer) * [class DetectionResult – DetectionResult object](advanced/dl.html#class-detectionresult-detectionresult-object) * [class RecognitionResult – RecognitionResult object](advanced/dl.html#class-recognitionresult-recognitionresult-object) * [image](advanced/image.html) * [Micropython Example](advanced/image.html#micropython-example) * [UIFlow2.0 Example](advanced/image.html#uiflow2-0-example) * [class image.Image](advanced/image.html#class-image-image) * [Basic Methods](advanced/image.html#basic-methods) * [Drawing Methods](advanced/image.html#drawing-methods) * [Constants](advanced/image.html#constants) * [jpg](advanced/jpg.html) * [Micropython Example](advanced/jpg.html#micropython-example) * [UIFlow2.0 Example](advanced/jpg.html#uiflow2-0-example) * [Methods](advanced/jpg.html#methods) * [Quick Reference](quick-reference/index.html) * [Get Started](quick-reference/get-started.html) * [Preparation](quick-reference/get-started.html#preparation) * [Installation UIFLOW2](quick-reference/get-started.html#installation-uiflow2) * [Start using UIFLOW2](quick-reference/get-started.html#start-using-uiflow2) * [USB Mode](quick-reference/usb-mode.html) * [Switch to USB Mode](quick-reference/usb-mode.html#switch-to-usb-mode) * [Run the Program](quick-reference/usb-mode.html#run-the-program) * [Terminate the Program Execution](quick-reference/usb-mode.html#terminate-the-program-execution) * [Save the Program to the Device and Run](quick-reference/usb-mode.html#save-the-program-to-the-device-and-run) * [File Operations](quick-reference/usb-mode.html#file-operations) * [Browse Directories](quick-reference/usb-mode.html#browse-directories) * [Upload an Image to the Device](quick-reference/usb-mode.html#upload-an-image-to-the-device) * [Use Images from the Device](quick-reference/usb-mode.html#use-images-from-the-device) * [Contributions Guide](contribute/index.html) * [API Documentation Template](contribute/template.html) * [UiFlow2 Example](contribute/template.html#uiflow2-example) * [MicroPython Example](contribute/template.html#micropython-example) * [API](contribute/template.html#api) * [Copyrights and Licenses](COPYRIGHT.html) * [Software Copyrights](COPYRIGHT.html#software-copyrights) * [Third Party](COPYRIGHT.html#third-party) * [Documentation](COPYRIGHT.html#documentation) --- # MicroPython libraries — UIFlow2 Programming Guide master documentation * [](../index.html) * MicroPython libraries * [View page source](../_sources/library/index.rst.txt) * * * MicroPython libraries[](#micropython-libraries "Link to this heading") ======================================================================== [https://docs.micropython.org/en/v1.22.0/library/index.html](https://docs.micropython.org/en/v1.22.0/library/index.html) --- # System — UIFlow2 Programming Guide master documentation * [](../index.html) * System * [View page source](../_sources/system/index.rst.txt) * * * System[](#system "Link to this heading") ========================================== * [`audio` — player and recorder](audio.html) * [`bleuart` — UART/Serial Port Emulation over BLE](bleuart.html) * [M5 BLE](m5ble.html) * [Power](power.html) * [`time` – time related functions](time.html) * [M5-ESPNOW](m5espnow.html) * [WLAN STA – control built-in WiFi interfaces](wlan.sta.html) * [WLAN AP – control built-in WiFi interfaces](wlan.ap.html) --- # Get Started — UIFlow2 Programming Guide master documentation * [](../index.html) * Get Started * [View page source](../_sources/get-started/index.rst.txt) * * * Get Started[](#get-started "Link to this heading") ==================================================== Currently UIFLOW2 supports the following boards: CORE[](#core "Link to this heading") -------------------------------------- | | | | | --- | --- | --- | | [![CoreS3](https://static-cdn.m5stack.com/resource/docs/products/core/CoreS3/img-96063e2a-637a-4d11-ac47-1ce4f1cdfd3e.webp)](https://docs.m5stack.com/zh_CN/core/CoreS3) | [![Core2](https://static-cdn.m5stack.com/resource/docs/products/core/core2/core2_01.webp)](https://docs.m5stack.com/zh_CN/core/core2) | [![TOUGH](https://static-cdn.m5stack.com/resource/docs/products/core/tough/tough_01.webp)](https://docs.m5stack.com/zh_CN/core/tough) | | [CoreS3](https://docs.m5stack.com/zh_CN/core/CoreS3) | [Core2](https://docs.m5stack.com/zh_CN/core/core2) | [TOUGH](https://docs.m5stack.com/zh_CN/core/tough) | | [![BASIC](https://static-cdn.m5stack.com/resource/docs/products/core/basic/basic_01.webp)](https://docs.m5stack.com/zh_CN/core/basic) | [![BASIC v2.6](https://static-cdn.m5stack.com/resource/docs/products/core/BASIC%20v2.6/img-92a921e7-32c9-4b79-b6cf-1e140742179f.webp)](https://docs.m5stack.com/zh_CN/core/BASIC%20v2.6) | [![BASIC v2.7](https://static-cdn.m5stack.com/resource/docs/products/core/basic_v2.7/basic_v2.7_01.webp)](https://docs.m5stack.com/zh_CN/core/basic_v2.7) | | [BASIC](https://docs.m5stack.com/zh_CN/core/basic) | [BASIC v2.6](https://docs.m5stack.com/zh_CN/core/BASIC%20v2.6) | [BASIC v2.7](https://docs.m5stack.com/zh_CN/core/basic_v2.7) | | [![GRAY](https://static-cdn.m5stack.com/resource/docs/products/core/gray/gray_01.webp)](https://docs.m5stack.com/zh_CN/core/gray) | [![FIRE](https://static-cdn.m5stack.com/resource/docs/products/core/fire/fire_01.webp)](https://docs.m5stack.com/zh_CN/core/fire) | [![FIRE v2.6](https://static-cdn.m5stack.com/resource/docs/products/core/fire_v2.6/fire_v2.6_01.webp)](https://docs.m5stack.com/zh_CN/core/fire_v2.6) | | [GRAY](https://docs.m5stack.com/zh_CN/core/gray) | [FIRE](https://docs.m5stack.com/zh_CN/core/fire) | [FIRE v2.6](https://docs.m5stack.com/zh_CN/core/fire_v2.6) | | [![FIRE v2.7](https://static-cdn.m5stack.com/resource/docs/products/core/fire_v2.7/fire_v2.6_01.webp)](https://docs.m5stack.com/zh_CN/core/fire_v2.7) | [![M5Capsule](https://static-cdn.m5stack.com/resource/docs/products/core/M5Capsule/4.webp)](https://docs.m5stack.com/zh_CN/core/M5Capsule) | [![M5Dial](https://static-cdn.m5stack.com/resource/docs/products/core/M5Dial/img-2afd549e-8af8-47b4-823a-e90e063a0139.webp)](https://docs.m5stack.com/zh_CN/core/M5Dial) | | [FIRE v2.7](https://docs.m5stack.com/zh_CN/core/fire_v2.7) | [M5Capsule](https://docs.m5stack.com/zh_CN/core/M5Capsule) | [M5Dial](https://docs.m5stack.com/zh_CN/core/M5Dial) | | [![Cardputer](https://static-cdn.m5stack.com/resource/docs/products/core/Cardputer/4.webp)](https://docs.m5stack.com/zh_CN/core/Cardputer) | [![Core2 v1.1](https://static-cdn.m5stack.com/resource/docs/products/core/Core2%20v1.1/img-1a949091-da2c-4fbb-bf4f-bce108cb43ec.webp)](https://docs.m5stack.com/zh_CN/core/core2_v1.1) | | | [Cardputer](https://docs.m5stack.com/zh_CN/core/Cardputer) | [Core2 v1.1](https://docs.m5stack.com/zh_CN/core/core2_v1.1) | | STICK[](#stick "Link to this heading") ---------------------------------------- | | | | | --- | --- | --- | | [![M5StickC PLUS](https://static-cdn.m5stack.com/resource/docs/products/core/m5stickc_plus/m5stickc_plus_01.webp)](https://docs.m5stack.com/zh_CN/core/m5stickc_plus) | [![M5StickC PLUS2](https://static-cdn.m5stack.com/resource/docs/products/core/M5StickC%20PLUS2/4.webp)](https://docs.m5stack.com/zh_CN/core/M5StickC%20PLUS2) | | | [M5StickC PLUS](https://docs.m5stack.com/zh_CN/core/m5stickc_plus) | [M5StickC PLUS2](https://docs.m5stack.com/zh_CN/core/M5StickC%20PLUS2) | | ATOM[](#atom "Link to this heading") -------------------------------------- | | | | | --- | --- | --- | | [![AtomS3](https://static-cdn.m5stack.com/resource/docs/products/core/AtomS3/img-ee8b91d5-f96a-4605-bd05-420ecde256c4.webp)](https://docs.m5stack.com/zh_CN/core/AtomS3) | [![AtomS3 Lite](https://static-cdn.m5stack.com/resource/docs/products/core/AtomS3%20Lite/img-dc6432b6-fd9b-4066-9a4d-49786503d1a3.webp)](https://docs.m5stack.com/zh_CN/core/AtomS3%20Lite) | [![AtomS3U](https://static-cdn.m5stack.com/resource/docs/products/core/AtomS3U/img-82d5d251-1bfd-4133-9324-404242e5acc7.webp)](https://docs.m5stack.com/zh_CN/core/AtomS3U) | | [AtomS3](https://docs.m5stack.com/zh_CN/core/AtomS3) | [AtomS3 Lite](https://docs.m5stack.com/zh_CN/core/AtomS3%20Lite) | [AtomS3U](https://docs.m5stack.com/zh_CN/core/AtomS3U) | --- # Widgets — A basic UI library — UIFlow2 Programming Guide master documentation * [](../index.html) * `Widgets` — A basic UI library * [View page source](../_sources/widgets/index.rst.txt) * * * [`Widgets`](#module-Widgets "Widgets: A basic UI library") — A basic UI library[](#module-Widgets "Link to this heading") ============================================================================================================================ 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 \* > 8 > 9 > 10def setup(): > 11 M5.begin() > 12 Widgets.fillScreen(0x222222) > 13 > 14 Widgets.setBrightness(100) > 15 Widgets.fillScreen(0x6600CC) > 16 Widgets.setRotation(0) > 17 > 18 > 19def loop(): > 20 M5.update() > 21 > 22 > 23if \_\_name\_\_ \== "\_\_main\_\_": > 24 try: > 25 setup() > 26 while True: > 27 loop() > 28 except (Exception, KeyboardInterrupt) as e: > 29 try: > 30 from utility import print\_error\_msg > 31 > 32 print\_error\_msg(e) > 33 except ImportError: > 34 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/widgets/screen/example.png) [cores3\_widgets\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/widgets/screen/cores3_widgets_example.m5f2) Screen functions[](#screen-functions "Link to this heading") -------------------------------------------------------------- Widgets.setBrightness(_brightness: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Widgets.setBrightness "Link to this definition") Set the backlight of the monitor。`brightness` ranges from 0 to 255. UIFLOW2: > ![setBrightness.png](https://static-cdn.m5stack.com/mpy_docs/widgets/screen/setBrightness.png) Widgets.fillScreen(_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Widgets.fillScreen "Link to this definition") Set the background color of the monitor. `color` accepts the color code of RGB888. UIFLOW2: > ![fillScreen.png](https://static-cdn.m5stack.com/mpy_docs/widgets/screen/fillScreen.png) Widgets.setRotation(_rotation: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Widgets.setRotation "Link to this definition") Set the rotation Angle of the display. The `rotation` parameter only accepts the following values: > * `0`: Portrait (0°C) > > * `1`: Landscape (90°C) > > * `2`: Inverse Portrait (180°C) > > * `3`: Inverse Landscape (270°C) > UIFLOW2: > ![setRotation.png](https://static-cdn.m5stack.com/mpy_docs/widgets/screen/setRotation.png) Classes[](#classes "Link to this heading") -------------------------------------------- * [class Circle – display circle](circle.html) * [class Image – display image](image.html) * [class ImagePlus – display remote image](image%2B.html) * [class Label – display text](label.html) --- # Software — UIFlow2 Programming Guide master documentation * [](../index.html) * Software * [View page source](../_sources/software/index.rst.txt) * * * Software[](#software "Link to this heading") ============================================== * [`modbus` – a Modbus library](modbus.html) * [`requests2` — Network Request Module](requests2.html) * [`umqtt` – a simple MQTT client](umqtt.html) * [TCP](tcp.html) * [UDP](udp.html) --- # Hardware — UIFlow2 Programming Guide master documentation * [](../index.html) * Hardware * [View page source](../_sources/hardware/index.rst.txt) * * * Hardware[](#hardware "Link to this heading") ============================================== * [ADC (analog to digital conversion)](adc.html) * [ALS](als.html) * [Button](button.html) * [CAN](can.html) * [Display](display.html) * [IMU](imu.html) * [IR](ir.html) * [Mic](mic.html) * [Pin](pin.html) * [PLC I/O](plcio.html) * [PWR485](pwr485.html) * [Rotary](rotary.html) * [SCD40](scd40.html) * [SEN55](sen55.html) * [Speaker](speaker.html) * [UART](uart.html) * [WDT](wdt.html) --- # Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * Unit * [View page source](../_sources/units/index.rst.txt) * * * Unit[](#unit "Link to this heading") ====================================== * [ACMeasure Unit](ac_measure.html) * [Accel Unit](accel.html) * [ACSSR Unit](acssr.html) * [ADC Unit](adc.html) * [ADC V1.1 Unit](adc_v11.html) * [AIN4-20mA Unit](ain4.html) * [Angle Unit](angle.html) * [Angle8 Unit](angle8.html) * [ASR Unit](asr.html) * [BPS Unit](bps.html) * [Button Unit](button.html) * [Buzzer Unit](buzzer.html) * [ByteButton Unit](bytebutton.html) * [ByteSwitch Unit](byteswitch.html) * [CAN Unit](can.html) * [CardKB Unit](cardkb.html) * [Catch Unit](catch.html) * [CO2 Unit](co2.html) * [CO2L Unit](co2l.html) * [Color Unit](color.html) * [DAC Unit](dac.html) * [DAC2 Unit](dac2.html) * [DCSSR Unit](dcssr.html) * [DDS Unit](dds.html) * [DigiClock Unit](digi_clock.html) * [DLight Unit](dlight.html) * [DMX512 Unit](dmx.html) * [Dual\_Button Unit](dualbutton.html) * [EARTH Unit](earth.html) * [Encoder Unit](encoder.html) * [Encoder8 Unit](encoder8.html) * [ENV Unit](env.html) * [ENVPRO Unit](envpro.html) * [ExtEncoder Unit](extencoder.html) * [EXTIO Unit](extio.html) * [EXTIO2 Unit](extio2.html) * [Fader Unit](fader.html) * [Finger Unit](finger.html) * [FlashLight Unit](flash_light.html) * [Glass Unit](glass.html) * [Glass2 Unit](glass2.html) * [GPS V1.1(SMA) Unit](gps_v11.html) * [Grove2Grove Unit](grove2grove.html) * [Hall Effect Unit](hall_effect.html) * [Heart Unit](heart.html) * [ID Unit](id.html) * [IMU Unit](imu.html) * [IMU Pro Unit](imupro.html) * [IR Unit](ir.html) * [Joystick Unit](joystick.html) * [Joystick2 Unit](joystick2.html) * [Key Unit](key.html) * [Kmeter ISO Unit](kmeter_iso.html) * [Kmeter Unit](kmeter.html) * [LaserRX Unit](laser_rx.html) * [LaserTX Unit](laser_tx.html) * [LCD Unit](lcd.html) * [Light Unit](light.html) * [Limit Unit](limit.html) * [LoRaE220 Unit](lora_e220.html) * [LoRaE220-433 Unit](lora_e220_433.html) * [LoRaWAN-X Unit](lorawan_rui3.html) * [MIDI Unit](midi.html) * [MiniOLED Unit](minioled.html) * [Miniscale Unit](miniscale.html) * [MQTT Unit](mqtt.html) * [MQTTPoE Unit](mqttpoe.html) * [NB-IoT Unit](nbiot.html) * [NB-IoT2 Unit](nbiot2.html) * [NCIR Unit](ncir.html) * [NECO Unit](neco.html) * [OLED Unit](oled.html) * [OP90 Unit](op90.html) * [OP180 Unit](op180.html) * [PDM Unit](pdm.html) * [PIR Unit](pir.html) * [Puzzle Unit](puzzle.html) * [QRCode Unit](qrcode.html) * [RCA Unit](rca.html) * [Reflective IR Unit](reflective_ir.html) * [RELAY Unit](relay.html) * [Relay4 Unit](relay4.html) * [RF433R Unit](rf433r.html) * [RF433T Unit](rf433t.html) * [RFID Unit](rfid.html) * [RGB Unit](rgb.html) * [Roller485 Unit](roller485.html) * [RollerCAN Unit](rollercan.html) * [Scales Unit](scales.html) * [Scroll Unit](scroll.html) * [SSR Unit](ssr.html) * [Synth Unit](synth.html) * [Thermal Unit](thermal.html) * [TimerPWR Unit](timerpwr.html) * [TMOS Unit](tmos.html) * [ToF Unit](tof.html) * [TVOC Unit](tvoc.html) * [UHF-RFID Unit](uhf_rfid.html) * [Ultrasonic Unit](ultrasonic.html) * [UltrasoundIO Unit](ultrasonic_io.html) * [UWB Unit](uwb.html) * [Vibrator Unit](vibrator.html) * [Watering Unit](watering.html) * [Weight Unit](weight.html) * [Weight I2C Unit](weight_i2c.html) * [Zigbee Unit](zigbee.html) --- # Module — UIFlow2 Programming Guide master documentation * [](../index.html) * Module * [View page source](../_sources/module/index.rst.txt) * * * Module[](#module "Link to this heading") ========================================== * [4In8Out Module](4in8out.html) * [AIN4 Module](ain4.html) * [Bala2 Module](bala2.html) * [Commu Module](commu.html) * [Display Module](display.html) * [DMX512 Module](dmx.html) * [DualKmeter Module](dualkmeter.html) * [ECG Module](ecg.html) * [4EncoderMotor Module](encoder4_motor.html) * [Fan v1.1 Module](fan.html) * [GatewayH2 Module](gateway_h2.html) * [GNSS Module](gnss.html) * [GPS Module](gps.html) * [GPS V2.0 Module](gpsv2.html) * [GRBL Module](grbl.html) * [GoPlus2Module](goplus2.html) * [HMI Module](hmi.html) * [LLM Module](llm.html) * [Lora Module](lora.html) * [LoRa868 v1.2 Module](lora_sx1262.html) * [LoRaWAN868 Module](lorawan868.html) * [COMX LTE Module](lte.html) * [NB-IoT Module](nbiot.html) * [ODrive Module](odrive.html) * [PLUS Module](plus.html) * [PM2.5 Module](pm25.html) * [PPS Module](pps.html) * [PwrCAN Module](pwrcan.html) * [QRCode Module](qrcode.html) * [RCA Module](rca.html) * [Relay2 Module](relay_2.html) * [RS232F/M Module](rs232.html) * [Servo2 Module](servo2.html) * [StepMotorDriver Module](step_motor_driver.html) * [USB Module](usb.html) * [Zigbee Module](zigbee.html) --- # HAT — UIFlow2 Programming Guide master documentation * [](../index.html) * HAT * [View page source](../_sources/hats/index.rst.txt) * * * HAT[](#hat "Link to this heading") ==================================== * [ADC Hat](adc.html) * [CardKB Hat](cardkb.html) * [DAC Hat](dac.html) * [DAC2 Hat](dac2.html) * [DLight Hat](dlight.html) * [ENV Hat](env.html) * [Finger Hat](finger.html) * [Heart Hat](heart.html) * [JoyC Hat](joyc.html) * [Joystick Hat](joystick.html) * [MiniEncoderC Hat](mini_encoder.html) * [MiniJoyC Hat](mini_joy.html) * [NCIR Hat](ncir.html) * [NeoFlash Hat](neoflash.html) * [PIR Hat](pir.html) * [Servo Hat](servo.html) * [Servos8 Hat](servo8.html) * [Speaker Hat](speaker.html) * [Speaker2 Hat](speaker2.html) * [Thermal Hat](thermal.html) * [ToF Hat](tof.html) * [Vibrator HAT](vibrator.html) --- # Controllers — UIFlow2 Programming Guide master documentation * [](../index.html) * Controllers * [View page source](../_sources/controllers/index.rst.txt) * * * Controllers[](#controllers "Link to this heading") ==================================================== * [CoreS3](cores3.html) * [AtomS3](atoms3.html) * [AtomS3 Lite](atoms3-lite.html) * [AtomS3U](atoms3u.html) * [StampS3](stamps3.html) * [Cardputer](cardputer.html) * [CoreInk](coreink.html) * [AirQ](airq.html) * [Paper](paper.html) * [DinMeter](dinmeter.html) --- # Base — UIFlow2 Programming Guide master documentation * [](../index.html) * Base * [View page source](../_sources/base/index.rst.txt) * * * Base[](#base "Link to this heading") ====================================== * [Atom Socket Base](atom_socket.html) * [Atom DTU LoRaWAN-Series Base](dtu_lorawan.html) * [Atomic CAN Base](atom_can.html) * [Atomic GPS Base](atom_gps.html) * [Atomic Display Base](display.html) * [Atomic Echo Base](echo.html) * [Atomic HDriver Base](hdriver.html) * [Atomic Motion Base](motion.html) * [Atomic PWM Base](pwm.html) * [Atomic QRCode Base](qrcode.html) * [Atomic QRCode2 Base](qrcode2.html) * [Atomic RS232 Base](rs232.html) * [Atomic RS485 Base](rs485.html) * [Atomic Speaker Base](speaker.html) * [Atomic Stepmotor Base](stepmotor.html) * [Atomic TFCard Base](tfcard.html) --- # Quick Reference — UIFlow2 Programming Guide master documentation * [](../index.html) * Quick Reference * [View page source](../_sources/quick-reference/index.rst.txt) * * * Quick Reference[](#quick-reference "Link to this heading") ============================================================ * [Get Started](get-started.html) * [USB Mode](usb-mode.html) --- # Advanced — UIFlow2 Programming Guide master documentation * [](../index.html) * Advanced * [View page source](../_sources/advanced/index.rst.txt) * * * Advanced[](#advanced "Link to this heading") ============================================== * [USB Drivers](usb/index.html) * [camera](camera.html) * [code\_scanner](code_scanner.html) * [dl — deep learning](dl.html) * [image](image.html) * [jpg](jpg.html) --- # Contributions Guide — UIFlow2 Programming Guide master documentation * [](../index.html) * Contributions Guide * [View page source](../_sources/contribute/index.rst.txt) * * * Contributions Guide[](#contributions-guide "Link to this heading") ==================================================================== * [API Documentation Template](template.html) * [UiFlow2 Example](template.html#uiflow2-example) * [Example1](template.html#example1) * [MicroPython Example](template.html#micropython-example) * [Example1](template.html#id1) * [API](template.html#api) * [Function](template.html#function) * [Class1](template.html#class1) * [Class2](template.html#class2) --- # UiFlow2 documentation and references — UIFlow2 Programming Guide master documentation * [](#) * UiFlow2 documentation and references * [View page source](_sources/index.rst.txt) * * * UiFlow2 documentation and references[](#uiflow2-documentation-and-references "Link to this heading") ====================================================================================================== * [Get Started](get-started/index.html) * [CORE](get-started/index.html#core) * [STICK](get-started/index.html#stick) * [ATOM](get-started/index.html#atom) * [MicroPython libraries](library/index.html) * [Controllers](controllers/index.html) * [CoreS3](controllers/cores3.html) * [AtomS3](controllers/atoms3.html) * [AtomS3 Lite](controllers/atoms3-lite.html) * [AtomS3U](controllers/atoms3u.html) * [StampS3](controllers/stamps3.html) * [Cardputer](controllers/cardputer.html) * [Startup UI](controllers/cardputer.html#startup-ui) * [CoreInk](controllers/coreink.html) * [UI](controllers/coreink.html#ui) * [AirQ](controllers/airq.html) * [UI](controllers/airq.html#ui) * [Paper](controllers/paper.html) * [UI](controllers/paper.html#ui) * [DinMeter](controllers/dinmeter.html) * [Startup UI](controllers/dinmeter.html#startup-ui) * [System](system/index.html) * [`audio` — player and recorder](system/audio.html) * [Classes](system/audio.html#classes) * [`bleuart` — UART/Serial Port Emulation over BLE](system/bleuart.html) * [Classes](system/bleuart.html#classes) * [M5 BLE](system/m5ble.html) * [M5BLE](system/m5ble.html#m5ble) * [Constructor](system/m5ble.html#constructor) * [Device Methods](system/m5ble.html#device-methods) * [Client Methods](system/m5ble.html#client-methods) * [Server Methods](system/m5ble.html#server-methods) * [Server - connected\_client\_handle Methods](system/m5ble.html#server-connected-client-handle-methods) * [Power](system/power.html) * [class Power](system/power.html#class-power) * [Methods](system/power.html#methods) * [class PORT](system/power.html#class-port) * [Constants](system/power.html#constants) * [`time` – time related functions](system/time.html) * [Functions](system/time.html#functions) * [M5-ESPNOW](system/m5espnow.html) * [class M5ESPNow](system/m5espnow.html#class-m5espnow) * [Constructors](system/m5espnow.html#constructors) * [Methods](system/m5espnow.html#methods) * [WLAN STA – control built-in WiFi interfaces](system/wlan.sta.html) * [Constructors](system/wlan.sta.html#constructors) * [Methods](system/wlan.sta.html#methods) * [WLAN AP – control built-in WiFi interfaces](system/wlan.ap.html) * [Constructors](system/wlan.ap.html#constructors) * [Methods](system/wlan.ap.html#methods) * [Constants](system/wlan.ap.html#constants) * [`Widgets` — A basic UI library](widgets/index.html) * [Screen functions](widgets/index.html#screen-functions) * [`Widgets.setBrightness()`](widgets/index.html#Widgets.Widgets.setBrightness) * [`Widgets.fillScreen()`](widgets/index.html#Widgets.Widgets.fillScreen) * [`Widgets.setRotation()`](widgets/index.html#Widgets.Widgets.setRotation) * [Classes](widgets/index.html#classes) * [class Circle – display circle](widgets/circle.html) * [class Image – display image](widgets/image.html) * [class ImagePlus – display remote image](widgets/image%2B.html) * [class Label – display text](widgets/label.html) * [Software](software/index.html) * [`modbus` – a Modbus library](software/modbus.html) * [Classes](software/modbus.html#classes) * [`requests2` — Network Request Module](software/requests2.html) * [Function](software/requests2.html#function) * [class Response](software/requests2.html#class-response) * [Methods](software/requests2.html#methods) * [`umqtt` – a simple MQTT client](software/umqtt.html) * [Supported MQTT features](software/umqtt.html#supported-mqtt-features) * [Design requirements](software/umqtt.html#design-requirements) * [MQTT client with automatic reconnect](software/umqtt.html#mqtt-client-with-automatic-reconnect) * [MQTT client with SSL file](software/umqtt.html#mqtt-client-with-ssl-file) * [API design](software/umqtt.html#api-design) * [Classes](software/umqtt.html#classes) * [TCP](software/tcp.html) * [API](software/tcp.html#api) * [UDP](software/udp.html) * [API](software/udp.html#api) * [Hardware](hardware/index.html) * [ADC (analog to digital conversion)](hardware/adc.html) * [class ADC](hardware/adc.html#class-adc) * [Methods](hardware/adc.html#methods) * [ALS](hardware/als.html) * [class ALS](hardware/als.html#class-als) * [Methods](hardware/als.html#methods) * [Button](hardware/button.html) * [class Button](hardware/button.html#class-button) * [Methods](hardware/button.html#methods) * [Event Handling](hardware/button.html#event-handling) * [Constants](hardware/button.html#constants) * [class Callback\_Type](hardware/button.html#class-callback-type) * [Constants](hardware/button.html#id1) * [CAN](hardware/can.html) * [Constructors](hardware/can.html#constructors) * [Methods](hardware/can.html#methods) * [Constants](hardware/can.html#constants) * [Display](hardware/display.html) * [Micropython Example](hardware/display.html#micropython-example) * [Functions](hardware/display.html#functions) * [IMU](hardware/imu.html) * [class IMU](hardware/imu.html#class-imu) * [Methods](hardware/imu.html#methods) * [class IMU\_TYPE](hardware/imu.html#class-imu-type) * [Constants](hardware/imu.html#constants) * [IR](hardware/ir.html) * [class IR](hardware/ir.html#class-ir) * [Constructors](hardware/ir.html#constructors) * [Methods](hardware/ir.html#methods) * [Mic](hardware/mic.html) * [class Mic](hardware/mic.html#class-mic) * [Methods](hardware/mic.html#methods) * [class mic\_config\_t](hardware/mic.html#class-mic-config-t) * [Pin](hardware/pin.html) * [class Pin](hardware/pin.html#class-pin) * [Constructors](hardware/pin.html#constructors) * [Methods](hardware/pin.html#methods) * [Constants](hardware/pin.html#constants) * [PLC I/O](hardware/plcio.html) * [UiFlow2 Example](hardware/plcio.html#uiflow2-example) * [MicroPython Example](hardware/plcio.html#micropython-example) * [API](hardware/plcio.html#api) * [PWR485](hardware/pwr485.html) * [UiFlow2 Example](hardware/pwr485.html#uiflow2-example) * [MicroPython Example](hardware/pwr485.html#micropython-example) * [MicroPython Example](hardware/pwr485.html#id2) * [**API**](hardware/pwr485.html#api) * [Rotary](hardware/rotary.html) * [class Rotary](hardware/rotary.html#class-rotary) * [Constructors](hardware/rotary.html#constructors) * [Methods](hardware/rotary.html#methods) * [SCD40](hardware/scd40.html) * [class SCD40](hardware/scd40.html#class-scd40) * [Constructors](hardware/scd40.html#constructors) * [Methods](hardware/scd40.html#methods) * [SEN55](hardware/sen55.html) * [class SEN55](hardware/sen55.html#class-sen55) * [Constructors](hardware/sen55.html#constructors) * [Methods](hardware/sen55.html#methods) * [Speaker](hardware/speaker.html) * [class Speaker](hardware/speaker.html#class-speaker) * [Methods](hardware/speaker.html#methods) * [UART](hardware/uart.html) * [UiFlow2 Example](hardware/uart.html#uiflow2-example) * [MicroPython Example](hardware/uart.html#micropython-example) * [**API**](hardware/uart.html#api) * [WDT](hardware/wdt.html) * [class WDT – watchdog timer](hardware/wdt.html#class-wdt-watchdog-timer) * [Constructors](hardware/wdt.html#constructors) * [Methods](hardware/wdt.html#methods) * [Module](module/index.html) * [4In8Out Module](module/4in8out.html) * [class Module4In8Out](module/4in8out.html#class-module4in8out) * [Constructors](module/4in8out.html#constructors) * [Methods](module/4in8out.html#methods) * [AIN4 Module](module/ain4.html) * [class AIN4Module](module/ain4.html#class-ain4module) * [Constructors](module/ain4.html#constructors) * [Methods](module/ain4.html#methods) * [Bala2 Module](module/bala2.html) * [UiFlow2 Example](module/bala2.html#uiflow2-example) * [MicroPython Example](module/bala2.html#micropython-example) * [**API**](module/bala2.html#api) * [Commu Module](module/commu.html) * [UiFlow2 Example](module/commu.html#uiflow2-example) * [MicroPython Example](module/commu.html#micropython-example) * [**API**](module/commu.html#api) * [Display Module](module/display.html) * [UiFlow2 Example](module/display.html#uiflow2-example) * [MicroPython Example](module/display.html#micropython-example) * [**API**](module/display.html#api) * [DMX512 Module](module/dmx.html) * [class DMX512Module](module/dmx.html#class-dmx512module) * [Constructors](module/dmx.html#constructors) * [Methods](module/dmx.html#methods) * [DualKmeter Module](module/dualkmeter.html) * [class DualKmeterModule](module/dualkmeter.html#class-dualkmetermodule) * [Constructors](module/dualkmeter.html#constructors) * [Methods](module/dualkmeter.html#methods) * [Constants](module/dualkmeter.html#constants) * [ECG Module](module/ecg.html) * [UiFlow2 Example:](module/ecg.html#uiflow2-example) * [MicroPython Example:](module/ecg.html#micropython-example) * [**API**](module/ecg.html#api) * [4EncoderMotor Module](module/encoder4_motor.html) * [UiFlow2 Example](module/encoder4_motor.html#uiflow2-example) * [MicroPython Example](module/encoder4_motor.html#micropython-example) * [**API**](module/encoder4_motor.html#api) * [Fan v1.1 Module](module/fan.html) * [UiFlow2 Example](module/fan.html#uiflow2-example) * [MicroPython Example](module/fan.html#micropython-example) * [**API**](module/fan.html#api) * [GatewayH2 Module](module/gateway_h2.html) * [UiFlow2 Example:](module/gateway_h2.html#uiflow2-example) * [MicroPython Example:](module/gateway_h2.html#micropython-example) * [**API**](module/gateway_h2.html#api) * [GNSS Module](module/gnss.html) * [class GNSSModule](module/gnss.html#class-gnssmodule) * [Constructors](module/gnss.html#constructors) * [Methods](module/gnss.html#methods) * [GPS Module](module/gps.html) * [class GPSModule](module/gps.html#class-gpsmodule) * [Constructors](module/gps.html#constructors) * [Methods](module/gps.html#methods) * [GPS V2.0 Module](module/gpsv2.html) * [class GPSV2Module](module/gpsv2.html#class-gpsv2module) * [Constructors](module/gpsv2.html#constructors) * [Methods](module/gpsv2.html#methods) * [GRBL Module](module/grbl.html) * [class GRBLModule](module/grbl.html#class-grblmodule) * [Constructors](module/grbl.html#constructors) * [Methods](module/grbl.html#methods) * [Constants](module/grbl.html#constants) * [GoPlus2Module](module/goplus2.html) * [class GoPlus2Module](module/goplus2.html#class-goplus2module) * [Constructors](module/goplus2.html#constructors) * [Methods](module/goplus2.html#methods) * [HMI Module](module/hmi.html) * [class HMIModule](module/hmi.html#class-hmimodule) * [Constructors](module/hmi.html#constructors) * [Methods](module/hmi.html#methods) * [LLM Module](module/llm.html) * [class LlmModule](module/llm.html#class-llmmodule) * [Constructors](module/llm.html#constructors) * [Methods](module/llm.html#methods) * [Lora Module](module/lora.html) * [class LoraModule](module/lora.html#class-loramodule) * [Constructors](module/lora.html#constructors) * [Methods](module/lora.html#methods) * [Constants](module/lora.html#constants) * [LoRa868 v1.2 Module](module/lora_sx1262.html) * [UiFlow2 Example](module/lora_sx1262.html#uiflow2-example) * [MicroPython Example](module/lora_sx1262.html#micropython-example) * [**API**](module/lora_sx1262.html#api) * [LoRaWAN868 Module](module/lorawan868.html) * [class LoRaWAN868Module](module/lorawan868.html#class-lorawan868module) * [Constructors](module/lorawan868.html#constructors) * [Methods](module/lorawan868.html#methods) * [Constants](module/lorawan868.html#constants) * [COMX LTE Module](module/lte.html) * [UiFlow2 Example](module/lte.html#uiflow2-example) * [MicroPython Example](module/lte.html#micropython-example) * [**API**](module/lte.html#api) * [NB-IoT Module](module/nbiot.html) * [class NBIOTModule](module/nbiot.html#class-nbiotmodule) * [Constructors](module/nbiot.html#constructors) * [ODrive Module](module/odrive.html) * [class ODriveModule](module/odrive.html#class-odrivemodule) * [Constructors](module/odrive.html#constructors) * [Methods](module/odrive.html#methods) * [Constants](module/odrive.html#constants) * [PLUS Module](module/plus.html) * [class PLUSModule](module/plus.html#class-plusmodule) * [Constructors](module/plus.html#constructors) * [Methods](module/plus.html#methods) * [PM2.5 Module](module/pm25.html) * [class PM25Module](module/pm25.html#class-pm25module) * [Constructors](module/pm25.html#constructors) * [Methods](module/pm25.html#methods) * [PPS Module](module/pps.html) * [class PPSModule](module/pps.html#class-ppsmodule) * [Constructors](module/pps.html#constructors) * [Methods](module/pps.html#methods) * [PwrCAN Module](module/pwrcan.html) * [class PwrCANModule](module/pwrcan.html#class-pwrcanmodule) * [Constructors](module/pwrcan.html#constructors) * [Methods](module/pwrcan.html#methods) * [class PwrCANModuleRS485](module/pwrcan.html#class-pwrcanmodulers485) * [Constructors](module/pwrcan.html#id1) * [Methods](module/pwrcan.html#id2) * [QRCode Module](module/qrcode.html) * [UiFlow2 Example:](module/qrcode.html#uiflow2-example) * [MicroPython Example:](module/qrcode.html#micropython-example) * [**API**](module/qrcode.html#api) * [RCA Module](module/rca.html) * [UiFlow2 Example](module/rca.html#uiflow2-example) * [MicroPython Example](module/rca.html#micropython-example) * [**API**](module/rca.html#api) * [Relay2 Module](module/relay_2.html) * [class Relay2Module](module/relay_2.html#class-relay2module) * [Constructors](module/relay_2.html#constructors) * [Methods](module/relay_2.html#methods) * [RS232F/M Module](module/rs232.html) * [class RS232Module](module/rs232.html#class-rs232module) * [Constructors](module/rs232.html#constructors) * [Methods](module/rs232.html#methods) * [Servo2 Module](module/servo2.html) * [class Servo2Module](module/servo2.html#class-servo2module) * [Constructors](module/servo2.html#constructors) * [Methods](module/servo2.html#methods) * [StepMotorDriver Module](module/step_motor_driver.html) * [class StepMotorDriverModule](module/step_motor_driver.html#class-stepmotordrivermodule) * [Constructors](module/step_motor_driver.html#constructors) * [Methods](module/step_motor_driver.html#methods) * [Constants](module/step_motor_driver.html#constants) * [USB Module](module/usb.html) * [Micropython Example](module/usb.html#micropython-example) * [UIFlow2.0 Example](module/usb.html#uiflow2-0-example) * [class USBModule](module/usb.html#class-usbmodule) * [Constructors](module/usb.html#constructors) * [Zigbee Module](module/zigbee.html) * [class ZigbeeModule](module/zigbee.html#class-zigbeemodule) * [Constructors](module/zigbee.html#constructors) * [Methods](module/zigbee.html#methods) * [Unit](units/index.html) * [ACMeasure Unit](units/ac_measure.html) * [class ACMeasureUnit](units/ac_measure.html#class-acmeasureunit) * [Constructors](units/ac_measure.html#constructors) * [Methods](units/ac_measure.html#methods) * [Accel Unit](units/accel.html) * [UiFlow2 Example](units/accel.html#uiflow2-example) * [MicroPython Example](units/accel.html#micropython-example) * [**API**](units/accel.html#api) * [ACSSR Unit](units/acssr.html) * [class ACSSRUnit](units/acssr.html#class-acssrunit) * [Constructors](units/acssr.html#constructors) * [Methods](units/acssr.html#methods) * [ADC Unit](units/adc.html) * [class ADCUnit](units/adc.html#class-adcunit) * [Constructors](units/adc.html#constructors) * [Methods](units/adc.html#methods) * [ADC V1.1 Unit](units/adc_v11.html) * [class ADCV11Unit](units/adc_v11.html#class-adcv11unit) * [Constructors](units/adc_v11.html#constructors) * [Methods](units/adc_v11.html#methods) * [AIN4-20mA Unit](units/ain4.html) * [class AIN4\_20MAUnit](units/ain4.html#class-ain4-20maunit) * [Constructors](units/ain4.html#constructors) * [Methods](units/ain4.html#methods) * [Angle Unit](units/angle.html) * [class Angle](units/angle.html#class-angle) * [Constructors](units/angle.html#constructors) * [Methods](units/angle.html#methods) * [Angle8 Unit](units/angle8.html) * [class Angle8Unit](units/angle8.html#class-angle8unit) * [Constructors](units/angle8.html#constructors) * [Methods](units/angle8.html#methods) * [ASR Unit](units/asr.html) * [UiFlow2 Example](units/asr.html#uiflow2-example) * [MicroPython Example](units/asr.html#micropython-example) * [**API**](units/asr.html#api) * [BPS Unit](units/bps.html) * [class BPSUnit](units/bps.html#class-bpsunit) * [Constructors](units/bps.html#constructors) * [Methods](units/bps.html#methods) * [Button Unit](units/button.html) * [class ButtonUnit](units/button.html#class-buttonunit) * [Constructors](units/button.html#constructors) * [Methods](units/button.html#methods) * [Buzzer Unit](units/buzzer.html) * [class BuzzerUnit](units/buzzer.html#class-buzzerunit) * [Constructors](units/buzzer.html#constructors) * [Methods](units/buzzer.html#methods) * [ByteButton Unit](units/bytebutton.html) * [class ByteButtonUnit](units/bytebutton.html#class-bytebuttonunit) * [Constructors](units/bytebutton.html#constructors) * [Methods](units/bytebutton.html#methods) * [ByteSwitch Unit](units/byteswitch.html) * [class ByteSwitchUnit](units/byteswitch.html#class-byteswitchunit) * [Constructors](units/byteswitch.html#constructors) * [Methods](units/byteswitch.html#methods) * [CAN Unit](units/can.html) * [class CANUnit](units/can.html#class-canunit) * [Constructors](units/can.html#constructors) * [CardKB Unit](units/cardkb.html) * [class CardKBUnit](units/cardkb.html#class-cardkbunit) * [Constructors](units/cardkb.html#constructors) * [Methods](units/cardkb.html#methods) * [Catch Unit](units/catch.html) * [class CatchUnit](units/catch.html#class-catchunit) * [Constructors](units/catch.html#constructors) * [Methods](units/catch.html#methods) * [CO2 Unit](units/co2.html) * [class CO2Unit](units/co2.html#class-co2unit) * [Constructors](units/co2.html#constructors) * [Methods](units/co2.html#methods) * [CO2L Unit](units/co2l.html) * [class CO2LUnit](units/co2l.html#class-co2lunit) * [Constructors](units/co2l.html#constructors) * [Methods](units/co2l.html#methods) * [Color Unit](units/color.html) * [class ColorUnit](units/color.html#class-colorunit) * [Constructors](units/color.html#constructors) * [Methods](units/color.html#methods) * [DAC Unit](units/dac.html) * [class DACUnit](units/dac.html#class-dacunit) * [Constructors](units/dac.html#constructors) * [Methods](units/dac.html#methods) * [DAC2 Unit](units/dac2.html) * [class DAC2Unit](units/dac2.html#class-dac2unit) * [Constructors](units/dac2.html#constructors) * [Methods](units/dac2.html#methods) * [DCSSR Unit](units/dcssr.html) * [class DCSSRUnit](units/dcssr.html#class-dcssrunit) * [Constructors](units/dcssr.html#constructors) * [DDS Unit](units/dds.html) * [class DDSUnit](units/dds.html#class-ddsunit) * [Constructors](units/dds.html#constructors) * [Methods](units/dds.html#methods) * [Constants](units/dds.html#constants) * [DigiClock Unit](units/digi_clock.html) * [class DigiClockUnit](units/digi_clock.html#class-digiclockunit) * [Constructors](units/digi_clock.html#constructors) * [Methods](units/digi_clock.html#methods) * [DLight Unit](units/dlight.html) * [class DLight](units/dlight.html#class-dlight) * [Constructors](units/dlight.html#constructors) * [Methods](units/dlight.html#methods) * [DMX512 Unit](units/dmx.html) * [class DMX512Unit](units/dmx.html#class-dmx512unit) * [Constructors](units/dmx.html#constructors) * [Methods](units/dmx.html#methods) * [Dual\_Button Unit](units/dualbutton.html) * [class DualButton](units/dualbutton.html#class-dualbutton) * [Constructors](units/dualbutton.html#constructors) * [Methods](units/dualbutton.html#methods) * [EARTH Unit](units/earth.html) * [class Earth](units/earth.html#class-earth) * [Constructors](units/earth.html#constructors) * [Methods](units/earth.html#methods) * [Encoder Unit](units/encoder.html) * [class EncoderUnit](units/encoder.html#class-encoderunit) * [Constructors](units/encoder.html#constructors) * [Methods](units/encoder.html#methods) * [Encoder8 Unit](units/encoder8.html) * [class Encoder8Unit](units/encoder8.html#class-encoder8unit) * [Constructors](units/encoder8.html#constructors) * [Methods](units/encoder8.html#methods) * [ENV Unit](units/env.html) * [class ENVUnit](units/env.html#class-envunit) * [Constructors](units/env.html#constructors) * [Methods](units/env.html#methods) * [ENVPRO Unit](units/envpro.html) * [class ENVPROUnit](units/envpro.html#class-envprounit) * [Constructors](units/envpro.html#constructors) * [Methods](units/envpro.html#methods) * [Constants](units/envpro.html#constants) * [ExtEncoder Unit](units/extencoder.html) * [class ExtEncoderUnit](units/extencoder.html#class-extencoderunit) * [Constructors](units/extencoder.html#constructors) * [Methods](units/extencoder.html#methods) * [EXTIO Unit](units/extio.html) * [class EXTIOUnit](units/extio.html#class-extiounit) * [Constructors](units/extio.html#constructors) * [Methods](units/extio.html#methods) * [class Pin](units/extio.html#class-pin) * [Constructors](units/extio.html#id1) * [Methods](units/extio.html#id2) * [EXTIO2 Unit](units/extio2.html) * [class EXTIO2Unit](units/extio2.html#class-extio2unit) * [Constructors](units/extio2.html#constructors) * [Methods](units/extio2.html#methods) * [Fader Unit](units/fader.html) * [class FaderUnit](units/fader.html#class-faderunit) * [Constructors](units/fader.html#constructors) * [Methods](units/fader.html#methods) * [Finger Unit](units/finger.html) * [class FingerUnit](units/finger.html#class-fingerunit) * [Constructors](units/finger.html#constructors) * [Methods](units/finger.html#methods) * [FlashLight Unit](units/flash_light.html) * [class FlashLightUnit](units/flash_light.html#class-flashlightunit) * [Constructors](units/flash_light.html#constructors) * [Methods](units/flash_light.html#methods) * [Glass Unit](units/glass.html) * [UiFlow2 Example](units/glass.html#uiflow2-example) * [MicroPython Example](units/glass.html#micropython-example) * [**API**](units/glass.html#api) * [Glass2 Unit](units/glass2.html) * [UiFlow2 Example](units/glass2.html#uiflow2-example) * [MicroPython Example](units/glass2.html#micropython-example) * [**API**](units/glass2.html#api) * [class Glass2Unit](units/glass2.html#class-glass2unit) * [GPS V1.1(SMA) Unit](units/gps_v11.html) * [class GPSV11Unit](units/gps_v11.html#class-gpsv11unit) * [Constructors](units/gps_v11.html#constructors) * [Methods](units/gps_v11.html#methods) * [Grove2Grove Unit](units/grove2grove.html) * [class Grove2GroveUnit](units/grove2grove.html#class-grove2groveunit) * [Constructors](units/grove2grove.html#constructors) * [Methods](units/grove2grove.html#methods) * [Hall Effect Unit](units/hall_effect.html) * [class HallEffectUnit](units/hall_effect.html#class-halleffectunit) * [Constructors](units/hall_effect.html#constructors) * [Methods](units/hall_effect.html#methods) * [Constants](units/hall_effect.html#constants) * [Heart Unit](units/heart.html) * [class HeartUnit](units/heart.html#class-heartunit) * [Constructors](units/heart.html#constructors) * [Methods](units/heart.html#methods) * [Constants](units/heart.html#constants) * [ID Unit](units/id.html) * [class IDUnit](units/id.html#class-idunit) * [Constructors](units/id.html#constructors) * [Methods](units/id.html#methods) * [IMU Unit](units/imu.html) * [class IMUUnit](units/imu.html#class-imuunit) * [Constructors](units/imu.html#constructors) * [Methods](units/imu.html#methods) * [IMU Pro Unit](units/imupro.html) * [class IMUProUnit](units/imupro.html#class-imuprounit) * [Constructors](units/imupro.html#constructors) * [Methods](units/imupro.html#methods) * [IR Unit](units/ir.html) * [class IRUnit](units/ir.html#class-irunit) * [Constructors](units/ir.html#constructors) * [Methods](units/ir.html#methods) * [Joystick Unit](units/joystick.html) * [class JoystickUnit](units/joystick.html#class-joystickunit) * [Constructors](units/joystick.html#constructors) * [Methods](units/joystick.html#methods) * [Joystick2 Unit](units/joystick2.html) * [class Joystick2Unit](units/joystick2.html#class-joystick2unit) * [Constructors](units/joystick2.html#constructors) * [Methods](units/joystick2.html#methods) * [Key Unit](units/key.html) * [class KeyUnit](units/key.html#class-keyunit) * [Constructors](units/key.html#constructors) * [Methods](units/key.html#methods) * [Event Handling](units/key.html#event-handling) * [Constants](units/key.html#constants) * [class CB\_TYPE](units/key.html#class-cb-type) * [Constants](units/key.html#id1) * [Kmeter ISO Unit](units/kmeter_iso.html) * [class KmeterISOUnit](units/kmeter_iso.html#class-kmeterisounit) * [Constructors](units/kmeter_iso.html#constructors) * [Methods](units/kmeter_iso.html#methods) * [Constants](units/kmeter_iso.html#constants) * [Kmeter Unit](units/kmeter.html) * [class KmeterUnit](units/kmeter.html#class-kmeterunit) * [Constructors](units/kmeter.html#constructors) * [Methods](units/kmeter.html#methods) * [Constants](units/kmeter.html#constants) * [LaserRX Unit](units/laser_rx.html) * [class LaserRXUnit](units/laser_rx.html#class-laserrxunit) * [Constructors](units/laser_rx.html#constructors) * [Methods](units/laser_rx.html#methods) * [LaserTX Unit](units/laser_tx.html) * [class LaserTXUnit](units/laser_tx.html#class-lasertxunit) * [Constructors](units/laser_tx.html#constructors) * [Methods](units/laser_tx.html#methods) * [LCD Unit](units/lcd.html) * [UiFlow2 Example](units/lcd.html#uiflow2-example) * [MicroPython Example](units/lcd.html#micropython-example) * [**API**](units/lcd.html#api) * [Light Unit](units/light.html) * [class Light](units/light.html#class-light) * [Constructors](units/light.html#constructors) * [Methods](units/light.html#methods) * [Limit Unit](units/limit.html) * [class LimitUnit](units/limit.html#class-limitunit) * [Constructors](units/limit.html#constructors) * [Methods](units/limit.html#methods) * [LoRaE220 Unit](units/lora_e220.html) * [Working Mode](units/lora_e220.html#working-mode) * [class LoRaE220JPUnit](units/lora_e220.html#class-lorae220jpunit) * [Constructors](units/lora_e220.html#constructors) * [Methods](units/lora_e220.html#methods) * [Constants](units/lora_e220.html#constants) * [LoRaE220-433 Unit](units/lora_e220_433.html) * [Working Mode](units/lora_e220_433.html#working-mode) * [class LoRaE220433Unit](units/lora_e220_433.html#class-lorae220433unit) * [Constructors](units/lora_e220_433.html#constructors) * [Methods](units/lora_e220_433.html#methods) * [Constants](units/lora_e220_433.html#constants) * [LoRaWAN-X Unit](units/lorawan_rui3.html) * [class LoRaWAN\_X](units/lorawan_rui3.html#class-lorawan-x) * [Constructors](units/lorawan_rui3.html#constructors) * [Methods](units/lorawan_rui3.html#methods) * [MIDI Unit](units/midi.html) * [class MIDIUnit](units/midi.html#class-midiunit) * [Constructors](units/midi.html#constructors) * [Methods](units/midi.html#methods) * [MiniOLED Unit](units/minioled.html) * [UiFlow2 Example](units/minioled.html#uiflow2-example) * [MicroPython Example](units/minioled.html#micropython-example) * [**API**](units/minioled.html#api) * [Miniscale Unit](units/miniscale.html) * [class MiniScaleUnit](units/miniscale.html#class-miniscaleunit) * [Constructors](units/miniscale.html#constructors) * [Methods](units/miniscale.html#methods) * [MQTT Unit](units/mqtt.html) * [class MQTTUnit](units/mqtt.html#class-mqttunit) * [Constructors](units/mqtt.html#constructors) * [Methods](units/mqtt.html#methods) * [MQTTPoE Unit](units/mqttpoe.html) * [class MQTTPoEUnit](units/mqttpoe.html#class-mqttpoeunit) * [Constructors](units/mqttpoe.html#constructors) * [Methods](units/mqttpoe.html#methods) * [NB-IoT Unit](units/nbiot.html) * [class NBIOTUnit](units/nbiot.html#class-nbiotunit) * [Constructors](units/nbiot.html#constructors) * [Methods](units/nbiot.html#methods) * [NB-IoT2 Unit](units/nbiot2.html) * [class NBIOT2Unit](units/nbiot2.html#class-nbiot2unit) * [Constructors](units/nbiot2.html#constructors) * [Methods](units/nbiot2.html#methods) * [NCIR Unit](units/ncir.html) * [class NCIRUnit](units/ncir.html#class-ncirunit) * [Constructors](units/ncir.html#constructors) * [Methods](units/ncir.html#methods) * [NECO Unit](units/neco.html) * [class NECOUnit](units/neco.html#class-necounit) * [Constructors](units/neco.html#constructors) * [Methods](units/neco.html#methods) * [OLED Unit](units/oled.html) * [UiFlow2 Example](units/oled.html#uiflow2-example) * [MicroPython Example](units/oled.html#micropython-example) * [**API**](units/oled.html#api) * [OP90 Unit](units/op90.html) * [class OPUnit](units/op90.html#class-opunit) * [Constructors](units/op90.html#constructors) * [Methods](units/op90.html#methods) * [OP180 Unit](units/op180.html) * [class OPUnit](units/op180.html#class-opunit) * [Constructors](units/op180.html#constructors) * [Methods](units/op180.html#methods) * [PDM Unit](units/pdm.html) * [UiFlow2 Example](units/pdm.html#uiflow2-example) * [MicroPython Example](units/pdm.html#micropython-example) * [**API**](units/pdm.html#api) * [PIR Unit](units/pir.html) * [class PIR](units/pir.html#class-pir) * [Constructors](units/pir.html#constructors) * [Methods](units/pir.html#methods) * [Puzzle Unit](units/puzzle.html) * [class PuzzleUnit](units/puzzle.html#class-puzzleunit) * [Constructors](units/puzzle.html#constructors) * [Methods](units/puzzle.html#methods) * [QRCode Unit](units/qrcode.html) * [class QRCodeUnit](units/qrcode.html#class-qrcodeunit) * [Constructors](units/qrcode.html#constructors) * [Methods](units/qrcode.html#methods) * [RCA Unit](units/rca.html) * [UiFlow2 Example](units/rca.html#uiflow2-example) * [MicroPython Example](units/rca.html#micropython-example) * [**API**](units/rca.html#api) * [Reflective IR Unit](units/reflective_ir.html) * [class ReflectiveIRUnit](units/reflective_ir.html#class-reflectiveirunit) * [Constructors](units/reflective_ir.html#constructors) * [Methods](units/reflective_ir.html#methods) * [Constants](units/reflective_ir.html#constants) * [RELAY Unit](units/relay.html) * [class RelayUnit](units/relay.html#class-relayunit) * [Constructors](units/relay.html#constructors) * [Methods](units/relay.html#methods) * [Relay4 Unit](units/relay4.html) * [class Relay4Unit](units/relay4.html#class-relay4unit) * [Constructors](units/relay4.html#constructors) * [Methods](units/relay4.html#methods) * [RF433R Unit](units/rf433r.html) * [UiFlow2 Example:](units/rf433r.html#uiflow2-example) * [MicroPython Example:](units/rf433r.html#micropython-example) * [**API**](units/rf433r.html#api) * [RF433T Unit](units/rf433t.html) * [UiFlow2 Example:](units/rf433t.html#uiflow2-example) * [MicroPython Example:](units/rf433t.html#micropython-example) * [**API**](units/rf433t.html#api) * [RFID Unit](units/rfid.html) * [class RFIDUnit](units/rfid.html#class-rfidunit) * [Constructors](units/rfid.html#constructors) * [Methods](units/rfid.html#methods) * [RGB Unit](units/rgb.html) * [class RGB](units/rgb.html#class-rgb) * [Constructors](units/rgb.html#constructors) * [Methods](units/rgb.html#methods) * [Roller485 Unit](units/roller485.html) * [class Roller485Unit](units/roller485.html#class-roller485unit) * [Constructors](units/roller485.html#constructors) * [class RollerBase](units/roller485.html#class-rollerbase) * [Constructors](units/roller485.html#id1) * [Methods](units/roller485.html#methods) * [class RollerI2C(RollerBase)](units/roller485.html#class-rolleri2c-rollerbase) * [Constructors](units/roller485.html#id2) * [Methods](units/roller485.html#id3) * [class Roller485(RollerBase)](units/roller485.html#class-roller485-rollerbase) * [Constructors](units/roller485.html#id4) * [Methods](units/roller485.html#id5) * [class Roller485ToI2CBus(RollerBase)](units/roller485.html#class-roller485toi2cbus-rollerbase) * [Constructors](units/roller485.html#id6) * [Methods](units/roller485.html#id7) * [RollerCAN Unit](units/rollercan.html) * [class RollerCANUnit](units/rollercan.html#class-rollercanunit) * [Constructors](units/rollercan.html#constructors) * [class RollerBase](units/rollercan.html#class-rollerbase) * [Constructors](units/rollercan.html#id1) * [Methods](units/rollercan.html#methods) * [class RollerI2C(RollerBase)](units/rollercan.html#class-rolleri2c-rollerbase) * [Constructors](units/rollercan.html#id2) * [Methods](units/rollercan.html#id3) * [class RollerCAN(RollerBase)](units/rollercan.html#class-rollercan-rollerbase) * [Constructors](units/rollercan.html#id4) * [Methods](units/rollercan.html#id5) * [class RollerCANToI2CBus(RollerBase)](units/rollercan.html#class-rollercantoi2cbus-rollerbase) * [Constructors](units/rollercan.html#id6) * [Methods](units/rollercan.html#id7) * [Scales Unit](units/scales.html) * [class ScalesUnit](units/scales.html#class-scalesunit) * [Constructors](units/scales.html#constructors) * [Methods](units/scales.html#methods) * [Scroll Unit](units/scroll.html) * [class ScrollUnit](units/scroll.html#class-scrollunit) * [Constructors](units/scroll.html#constructors) * [Methods](units/scroll.html#methods) * [SSR Unit](units/ssr.html) * [class SSRUnit](units/ssr.html#class-ssrunit) * [Constructors](units/ssr.html#constructors) * [Methods](units/ssr.html#methods) * [Synth Unit](units/synth.html) * [class SynthUnit](units/synth.html#class-synthunit) * [Constructors](units/synth.html#constructors) * [Methods](units/synth.html#methods) * [Thermal Unit](units/thermal.html) * [class ThermalUnit](units/thermal.html#class-thermalunit) * [Constructors](units/thermal.html#constructors) * [Methods](units/thermal.html#methods) * [TimerPWR Unit](units/timerpwr.html) * [class TimerPWRUnit](units/timerpwr.html#class-timerpwrunit) * [Constructors](units/timerpwr.html#constructors) * [Methods](units/timerpwr.html#methods) * [Constants](units/timerpwr.html#constants) * [TMOS Unit](units/tmos.html) * [class TMOSUnit](units/tmos.html#class-tmosunit) * [Constructors](units/tmos.html#constructors) * [Methods](units/tmos.html#methods) * [ToF Unit](units/tof.html) * [class ToFUnit](units/tof.html#class-tofunit) * [Constructors](units/tof.html#constructors) * [Methods](units/tof.html#methods) * [TVOC Unit](units/tvoc.html) * [class TVOCUnit](units/tvoc.html#class-tvocunit) * [Constructors](units/tvoc.html#constructors) * [Methods](units/tvoc.html#methods) * [UHF-RFID Unit](units/uhf_rfid.html) * [class UHFRFIDUnit](units/uhf_rfid.html#class-uhfrfidunit) * [Constructors](units/uhf_rfid.html#constructors) * [Methods](units/uhf_rfid.html#methods) * [Ultrasonic Unit](units/ultrasonic.html) * [class ULTRASONIC\_I2C](units/ultrasonic.html#class-ultrasonic-i2c) * [Constructors](units/ultrasonic.html#constructors) * [Methods](units/ultrasonic.html#methods) * [UltrasoundIO Unit](units/ultrasonic_io.html) * [class UltrasoundIOUnit](units/ultrasonic_io.html#class-ultrasoundiounit) * [Constructors](units/ultrasonic_io.html#constructors) * [Methods](units/ultrasonic_io.html#methods) * [UWB Unit](units/uwb.html) * [class UWBUnit](units/uwb.html#class-uwbunit) * [Constructors](units/uwb.html#constructors) * [Methods](units/uwb.html#methods) * [Constants](units/uwb.html#constants) * [Vibrator Unit](units/vibrator.html) * [class VibratorUnit](units/vibrator.html#class-vibratorunit) * [Constructors](units/vibrator.html#constructors) * [Methods](units/vibrator.html#methods) * [Watering Unit](units/watering.html) * [class WateringUnit](units/watering.html#class-wateringunit) * [Constructors](units/watering.html#constructors) * [Methods](units/watering.html#methods) * [Weight Unit](units/weight.html) * [class WEIGHTUnit](units/weight.html#class-weightunit) * [Constructors](units/weight.html#constructors) * [Methods](units/weight.html#methods) * [Weight I2C Unit](units/weight_i2c.html) * [class WEIGHT\_I2CUnit](units/weight_i2c.html#class-weight-i2cunit) * [Constructors](units/weight_i2c.html#constructors) * [Methods](units/weight_i2c.html#methods) * [Zigbee Unit](units/zigbee.html) * [class ZigbeeUnit](units/zigbee.html#class-zigbeeunit) * [Constructors](units/zigbee.html#constructors) * [Methods](units/zigbee.html#methods) * [HAT](hats/index.html) * [ADC Hat](hats/adc.html) * [class CANUnit](hats/adc.html#class-canunit) * [Constructors](hats/adc.html#constructors) * [CardKB Hat](hats/cardkb.html) * [class CardKBHat](hats/cardkb.html#class-cardkbhat) * [Constructors](hats/cardkb.html#constructors) * [DAC Hat](hats/dac.html) * [class DACHat](hats/dac.html#class-dachat) * [Constructors](hats/dac.html#constructors) * [DAC2 Hat](hats/dac2.html) * [class DAC2Hat](hats/dac2.html#class-dac2hat) * [Constructors](hats/dac2.html#constructors) * [DLight Hat](hats/dlight.html) * [class DLightHat](hats/dlight.html#class-dlighthat) * [Constructors](hats/dlight.html#constructors) * [ENV Hat](hats/env.html) * [class ENVHat](hats/env.html#class-envhat) * [Constructors](hats/env.html#constructors) * [Methods](hats/env.html#methods) * [Finger Hat](hats/finger.html) * [class FingerHat](hats/finger.html#class-fingerhat) * [Constructors](hats/finger.html#constructors) * [Heart Hat](hats/heart.html) * [class HeartHat](hats/heart.html#class-hearthat) * [Constructors](hats/heart.html#constructors) * [Methods](hats/heart.html#methods) * [Constants](hats/heart.html#constants) * [JoyC Hat](hats/joyc.html) * [class JoyCHat](hats/joyc.html#class-joychat) * [Constructors](hats/joyc.html#constructors) * [Methods](hats/joyc.html#methods) * [Joystick Hat](hats/joystick.html) * [class JoystickHat](hats/joystick.html#class-joystickhat) * [Constructors](hats/joystick.html#constructors) * [Methods](hats/joystick.html#methods) * [MiniEncoderC Hat](hats/mini_encoder.html) * [class MiniEncoderCHat](hats/mini_encoder.html#class-miniencoderchat) * [Constructors](hats/mini_encoder.html#constructors) * [Methods](hats/mini_encoder.html#methods) * [MiniJoyC Hat](hats/mini_joy.html) * [class MiniJoyHat](hats/mini_joy.html#class-minijoyhat) * [Constructors](hats/mini_joy.html#constructors) * [Methods](hats/mini_joy.html#methods) * [NCIR Hat](hats/ncir.html) * [class NCIRHat](hats/ncir.html#class-ncirhat) * [Constructors](hats/ncir.html#constructors) * [NeoFlash Hat](hats/neoflash.html) * [class NeoFlashHat](hats/neoflash.html#class-neoflashhat) * [Constructors](hats/neoflash.html#constructors) * [Methods](hats/neoflash.html#methods) * [Constants](hats/neoflash.html#constants) * [PIR Hat](hats/pir.html) * [class PIRHat](hats/pir.html#class-pirhat) * [Constructors](hats/pir.html#constructors) * [Methods](hats/pir.html#methods) * [Servo Hat](hats/servo.html) * [class ServoHat](hats/servo.html#class-servohat) * [Constructors](hats/servo.html#constructors) * [Methods](hats/servo.html#methods) * [Servos8 Hat](hats/servo8.html) * [class Servos8Hat](hats/servo8.html#class-servos8hat) * [Constructors](hats/servo8.html#constructors) * [Methods](hats/servo8.html#methods) * [Speaker Hat](hats/speaker.html) * [class SpeakerHat](hats/speaker.html#class-speakerhat) * [Constructors](hats/speaker.html#constructors) * [Speaker2 Hat](hats/speaker2.html) * [UiFlow2 Example](hats/speaker2.html#uiflow2-example) * [MicroPython Example](hats/speaker2.html#micropython-example) * [**API**](hats/speaker2.html#api) * [Thermal Hat](hats/thermal.html) * [class ThermalHat](hats/thermal.html#class-thermalhat) * [Constructors](hats/thermal.html#constructors) * [ToF Hat](hats/tof.html) * [class ToFHat](hats/tof.html#class-tofhat) * [Constructors](hats/tof.html#constructors) * [Vibrator HAT](hats/vibrator.html) * [class VibratorHAT](hats/vibrator.html#class-vibratorhat) * [Constructors](hats/vibrator.html#constructors) * [Methods](hats/vibrator.html#methods) * [Base](base/index.html) * [Atom Socket Base](base/atom_socket.html) * [class ATOMSocketBase](base/atom_socket.html#class-atomsocketbase) * [Constructors](base/atom_socket.html#constructors) * [Methods](base/atom_socket.html#methods) * [Atom DTU LoRaWAN-Series Base](base/dtu_lorawan.html) * [UiFlow2 Example](base/dtu_lorawan.html#uiflow2-example) * [MicroPython Example](base/dtu_lorawan.html#micropython-example) * [**API**](base/dtu_lorawan.html#api) * [Atomic CAN Base](base/atom_can.html) * [UiFlow2 Example](base/atom_can.html#uiflow2-example) * [MicroPython Example](base/atom_can.html#micropython-example) * [**API**](base/atom_can.html#api) * [Atomic GPS Base](base/atom_gps.html) * [UiFlow2 Example](base/atom_gps.html#uiflow2-example) * [MicroPython Example](base/atom_gps.html#micropython-example) * [**API**](base/atom_gps.html#api) * [Atomic Display Base](base/display.html) * [UiFlow2 Example](base/display.html#uiflow2-example) * [MicroPython Example](base/display.html#micropython-example) * [**API**](base/display.html#api) * [Atomic Echo Base](base/echo.html) * [class ATOMEchoBase](base/echo.html#class-atomechobase) * [Constructors](base/echo.html#constructors) * [Attributes](base/echo.html#attributes) * [Atomic HDriver Base](base/hdriver.html) * [UiFlow2 Example:](base/hdriver.html#uiflow2-example) * [MicroPython Example:](base/hdriver.html#micropython-example) * [**API**](base/hdriver.html#api) * [Atomic Motion Base](base/motion.html) * [UiFlow2 Example:](base/motion.html#uiflow2-example) * [MicroPython Example:](base/motion.html#micropython-example) * [**API**](base/motion.html#api) * [Atomic PWM Base](base/pwm.html) * [UiFlow2 Example:](base/pwm.html#uiflow2-example) * [MicroPython Example:](base/pwm.html#micropython-example) * [**API**](base/pwm.html#api) * [Atomic QRCode Base](base/qrcode.html) * [UiFlow2 Example:](base/qrcode.html#uiflow2-example) * [MicroPython Example:](base/qrcode.html#micropython-example) * [**API**](base/qrcode.html#api) * [Atomic QRCode2 Base](base/qrcode2.html) * [UiFlow2 Example:](base/qrcode2.html#uiflow2-example) * [MicroPython Example:](base/qrcode2.html#micropython-example) * [**API**](base/qrcode2.html#api) * [Atomic RS232 Base](base/rs232.html) * [UiFlow2 Example](base/rs232.html#uiflow2-example) * [MicroPython Example](base/rs232.html#micropython-example) * [**API**](base/rs232.html#api) * [Atomic RS485 Base](base/rs485.html) * [UiFlow2 Example](base/rs485.html#uiflow2-example) * [MicroPython Example](base/rs485.html#micropython-example) * [**API**](base/rs485.html#api) * [Atomic Speaker Base](base/speaker.html) * [class SpeakerBase](base/speaker.html#class-speakerbase) * [Constructors](base/speaker.html#constructors) * [class SDCard](base/speaker.html#class-sdcard) * [Constructors](base/speaker.html#id1) * [Atomic Stepmotor Base](base/stepmotor.html) * [UiFlow2 Example:](base/stepmotor.html#uiflow2-example) * [MicroPython Example:](base/stepmotor.html#micropython-example) * [**API**](base/stepmotor.html#api) * [Atomic TFCard Base](base/tfcard.html) * [UiFlow2 Example](base/tfcard.html#uiflow2-example) * [MicroPython Example](base/tfcard.html#micropython-example) * [**API**](base/tfcard.html#api) * [Advanced](advanced/index.html) * [USB Drivers](advanced/usb/index.html) * [Modules](advanced/usb/index.html#modules) * [camera](advanced/camera.html) * [Micropython Example](advanced/camera.html#micropython-example) * [UIFlow2.0 Example](advanced/camera.html#uiflow2-0-example) * [Functions](advanced/camera.html#functions) * [code\_scanner](advanced/code_scanner.html) * [Micropython Example](advanced/code_scanner.html#micropython-example) * [UIFlow2.0 Example](advanced/code_scanner.html#uiflow2-0-example) * [Methods](advanced/code_scanner.html#methods) * [class image.QRCode](advanced/code_scanner.html#class-image-qrcode) * [dl — deep learning](advanced/dl.html) * [Micropython Example](advanced/dl.html#micropython-example) * [UIFlow2.0 Example](advanced/dl.html#uiflow2-0-example) * [Funtions](advanced/dl.html#funtions) * [class ObjectDetector](advanced/dl.html#class-objectdetector) * [class HumanFaceRecognizer](advanced/dl.html#class-humanfacerecognizer) * [class DetectionResult – DetectionResult object](advanced/dl.html#class-detectionresult-detectionresult-object) * [class RecognitionResult – RecognitionResult object](advanced/dl.html#class-recognitionresult-recognitionresult-object) * [image](advanced/image.html) * [Micropython Example](advanced/image.html#micropython-example) * [UIFlow2.0 Example](advanced/image.html#uiflow2-0-example) * [class image.Image](advanced/image.html#class-image-image) * [Basic Methods](advanced/image.html#basic-methods) * [Drawing Methods](advanced/image.html#drawing-methods) * [Constants](advanced/image.html#constants) * [jpg](advanced/jpg.html) * [Micropython Example](advanced/jpg.html#micropython-example) * [UIFlow2.0 Example](advanced/jpg.html#uiflow2-0-example) * [Methods](advanced/jpg.html#methods) * [Quick Reference](quick-reference/index.html) * [Get Started](quick-reference/get-started.html) * [Preparation](quick-reference/get-started.html#preparation) * [Installation UIFLOW2](quick-reference/get-started.html#installation-uiflow2) * [Start using UIFLOW2](quick-reference/get-started.html#start-using-uiflow2) * [USB Mode](quick-reference/usb-mode.html) * [Switch to USB Mode](quick-reference/usb-mode.html#switch-to-usb-mode) * [Run the Program](quick-reference/usb-mode.html#run-the-program) * [Terminate the Program Execution](quick-reference/usb-mode.html#terminate-the-program-execution) * [Save the Program to the Device and Run](quick-reference/usb-mode.html#save-the-program-to-the-device-and-run) * [File Operations](quick-reference/usb-mode.html#file-operations) * [Browse Directories](quick-reference/usb-mode.html#browse-directories) * [Upload an Image to the Device](quick-reference/usb-mode.html#upload-an-image-to-the-device) * [Use Images from the Device](quick-reference/usb-mode.html#use-images-from-the-device) * [Contributions Guide](contribute/index.html) * [API Documentation Template](contribute/template.html) * [UiFlow2 Example](contribute/template.html#uiflow2-example) * [MicroPython Example](contribute/template.html#micropython-example) * [API](contribute/template.html#api) * [Copyrights and Licenses](COPYRIGHT.html) * [Software Copyrights](COPYRIGHT.html#software-copyrights) * [Third Party](COPYRIGHT.html#third-party) * [Documentation](COPYRIGHT.html#documentation) --- # Unknown UiFlow2 documentation and references ==================================== .. toctree:: :maxdepth: 3 get-started/index.rst library/index.rst controllers/index.rst system/index.rst widgets/index.rst software/index.rst hardware/index.rst module/index.rst units/index.rst hats/index.rst base/index.rst advanced/index.rst quick-reference/index.rst contribute/index.rst COPYRIGHT.rst --- # Copyrights and Licenses — UIFlow2 Programming Guide master documentation * [](index.html) * Copyrights and Licenses * [View page source](_sources/COPYRIGHT.rst.txt) * * * Copyrights and Licenses[](#copyrights-and-licenses "Link to this heading") ============================================================================ Software Copyrights[](#software-copyrights "Link to this heading") -------------------------------------------------------------------- All original source code in this repository is Copyright (C) 2023 M5Stack. This source code is licensed under the MIT license as described in the file LICENSE. Third Party[](#third-party "Link to this heading") ---------------------------------------------------- * [micropython](https://github.com/micropython/micropython) Copyright (c) 2013-2023 Damien P. George and licensed under MIT License. * [umqtt](https://github.com/micropython/micropython-lib) Copyright (c) 2013-2014 micropython-lib contributors and licensed under MIT License. * [urequests](https://github.com/micropython/micropython-lib) Copyright (c) 2013-2014 micropython-lib contributors and licensed under MIT License. * [ir](https://github.com/peterhinch/micropython_ir) Copyright (c) 2020 Peter Hinch and licensed under MIT License. * [neopixel](https://github.com/micropython/micropython-lib) Copyright (c) 2013-2014 micropython-lib contributors and licensed under MIT License. * [bh1750fvi](https://github.com/gandro/micropython-m5stamp-c3u) Copyright (c) 2022 Sebastian Wicki and licensed under MIT License. * [bmp280](https://github.com/gandro/micropython-m5stickc-plus) Copyright (c) 2020 Sebastian Wicki and licensed under MIT License. * [checksum](https://github.com/gandro/micropython-m5stamp-c3u) Copyright (c) 2022 Sebastian Wicki and licensed under MIT License. * [dht12](https://github.com/gandro/micropython-m5stickc-plus) Copyright (c) 2020 Sebastian Wicki and licensed under MIT License. * [pcf8563](https://github.com/gandro/micropython-m5stickc-plus) Copyright (c) 2020 Sebastian Wicki and licensed under MIT License. * [qmp6988](https://github.com/gandro/micropython-m5stamp-c3u) Copyright (c) 2022 Sebastian Wicki and licensed under MIT License. * [scd40](https://github.com/gandro/micropython-m5stamp-c3u) Copyright (c) 2022 Sebastian Wicki and licensed under MIT License. * [sgp30](https://github.com/gandro/micropython-m5stamp-c3u) Copyright (c) 2022 Sebastian Wicki and licensed under MIT License. * [sht4x](https://github.com/adafruit/Adafruit_CircuitPython_SHT4x) Copyright (c) 2021 ladyada for Adafruit and licensed under MIT License. * [vl53l0x](https://github.com/adafruit/Adafruit_CircuitPython_VL53L0X) Copyright (c) 2017 Tony DiCola for Adafruit Industries and licensed under MIT License. * [camera](https://github.com/lemariva/micropython-camera-driver) Copyright (c) 2021 Mauro Riva and licensed under Apache License Version 2.0. * [haptic](https://github.com/lbuque/haptic) Copyright (c) 2022 lbuque and licensed under MIT License. Documentation[](#documentation "Link to this heading") -------------------------------------------------------- * HTML version of API documentation uses the Sphinx theme sphinx\_idf\_theme, which is Copyright (c) 2013-2020 Dave Snider, Read the Docs. It is licensed under the MIT license. --- # AtomS3 — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * AtomS3 * [View page source](../_sources/controllers/atoms3.rst.txt) * * * AtomS3[](#atoms3 "Link to this heading") ========================================== --- # CoreS3 — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * CoreS3 * [View page source](../_sources/controllers/cores3.rst.txt) * * * CoreS3[](#cores3 "Link to this heading") ========================================== --- # Unknown Get Started ============ .. include:: ../refs/controllers.ref Currently UIFLOW2 supports the following boards: CORE ---- ================== ================== ================== |CoreS3| |Core2| |TOUGH| ------------------ ------------------ ------------------ \`CoreS3\`\_ \`Core2\`\_ \`TOUGH\`\_ ------------------ ------------------ ------------------ |BASIC| |BASIC v2.6| |BASIC v2.7| ------------------ ------------------ ------------------ \`BASIC\`\_ \`BASIC v2.6\`\_ \`BASIC v2.7\`\_ ------------------ ------------------ ------------------ |GRAY| |FIRE| |FIRE v2.6| ------------------ ------------------ ------------------ \`GRAY\`\_ \`FIRE\`\_ \`FIRE v2.6\`\_ ------------------ ------------------ ------------------ |FIRE v2.7| |M5Capsule| |M5Dial| ------------------ ------------------ ------------------ \`FIRE v2.7\`\_ \`M5Capsule\`\_ \`M5Dial\`\_ ------------------ ------------------ ------------------ |Cardputer| |Core2 v1.1| ------------------ ------------------ ------------------ \`Cardputer\`\_ \`Core2 v1.1\`\_ ================== ================== ================== STICK ----- ================== ================== ================== |M5StickC PLUS| |M5StickC PLUS2| ------------------ ------------------ ------------------ \`M5StickC PLUS\`\_ \`M5StickC PLUS2\`\_ ================== ================== ================== ATOM ---- ================== ================== ================== |AtomS3| |AtomS3 Lite| |AtomS3U| ------------------ ------------------ ------------------ \`AtomS3\`\_ \`AtomS3 Lite\`\_ \`AtomS3U\`\_ ================== ================== ================== --- # AtomS3 Lite — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * AtomS3 Lite * [View page source](../_sources/controllers/atoms3-lite.rst.txt) * * * AtomS3 Lite[](#atoms3-lite "Link to this heading") ==================================================== --- # Unknown MicroPython libraries ===================== https://docs.micropython.org/en/v1.22.0/library/index.html --- # audio — player and recorder — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * `audio` — player and recorder * [View page source](../_sources/system/audio.rst.txt) * * * [`audio`](#module-audio "audio: player and recorder") — player and recorder[](#module-audio "Link to this heading") ====================================================================================================================== This module implements player and recorder * player: encapsulates the ADF esp\_audio, support local and online resources. * recorder: record and encoding the voice into file. Below is the detailed audio support for the host: | | AW88298 | ES7210 | ES8311 | I2S Philips | I2S PDM | | --- | --- | --- | --- | --- | --- | | CoreS3 | ✔ | ✔ | | | | | BOX3 | | ✔ | ✔ | | | 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 audio import Recorder > 9from audio import Player > 10 > 11 > 12recorder \= None > 13player \= None > 14 > 15 > 16def setup(): > 17 global recorder, player > 18 > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 > 22 recorder \= Recorder(8000, 16, True) > 23 recorder.record("file://flash/res/audio/test.amr", 5, True) > 24 player \= Player(None) > 25 player.play("file://flash/res/audio/test.amr", pos\=0, volume\=100, sync\=True) > 26 > 27 > 28def loop(): > 29 global recorder, player > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/system/audio/example.png) [cores3\_audio\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/audio/cores3_audio_example.m5f2) Classes[](#classes "Link to this heading") -------------------------------------------- * [class Player](audio.player.html) * [class Recorder](audio.recorder.html) --- # bleuart — UART/Serial Port Emulation over BLE — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * `bleuart` — UART/Serial Port Emulation over BLE * [View page source](../_sources/system/bleuart.rst.txt) * * * `bleuart` — UART/Serial Port Emulation over BLE[](#bleuart-uart-serial-port-emulation-over-ble "Link to this heading") ======================================================================================================================== The Nordic UART Service (NUS) Application is an example that emulates a serial port over BLE. The application includes one service: the Nordic UART Service. The 128-bit vendor-specific UUID of the Nordic UART Service is 6E400001-B5A3-F393-E0A9-E50E24DCCA9E (16-bit offset: 0x0001). This service exposes two characteristics: one for transmitting and one for receiving (as seen from the peer). Classes[](#classes "Link to this heading") -------------------------------------------- * [class BLEUARTServer](bleuart.server.html) * [class BLEUARTClient](bleuart.client.html) --- # AtomS3U — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * AtomS3U * [View page source](../_sources/controllers/atoms3u.rst.txt) * * * AtomS3U[](#atoms3u "Link to this heading") ============================================ --- # modbus – a Modbus library — UIFlow2 Programming Guide master documentation * [](../index.html) * [Software](index.html) * `modbus` – a Modbus library * [View page source](../_sources/software/modbus.rst.txt) * * * `modbus` – a Modbus library[](#modbus-a-modbus-library "Link to this heading") ================================================================================ a Modbus library for MicroPython. Classes[](#classes "Link to this heading") -------------------------------------------- * [class ModbusRTUMaster – Modbus RTU master](modbus.rtu.master.html) * [class ModbusRTUSlave – Modbus RTU slave](modbus.rtu.slave.html) * [class ModbusTCPClient – Modbus TCP client](modbus.tcp.client.html) * [class ModbusTCPServer – Modbus TCP server](modbus.tcp.server.html) --- # class Circle – display circle — UIFlow2 Programming Guide master documentation * [](../index.html) * [`Widgets` — A basic UI library](index.html) * class Circle – display circle * [View page source](../_sources/widgets/circle.rst.txt) * * * class Circle – display circle[](#class-circle-display-circle "Link to this heading") ====================================================================================== Circle is the basic object type used to display text. 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 \* > 8import time > 9 > 10 > 11circle0 \= None > 12title0 \= None > 13 > 14 > 15import random > 16 > 17 > 18def setup(): > 19 global circle0, title0 > 20 > 21 M5.begin() > 22 Widgets.fillScreen(0x222222) > 23 circle0 \= Widgets.Circle(63, 111, 15, 0xFFFFFF, 0xFFFFFF) > 24 title0 \= Widgets.Title("Circle Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 > 26 circle0.setVisible(True) > 27 > 28 > 29def loop(): > 30 global circle0, title0 > 31 M5.update() > 32 circle0.setRadius(r\=(random.randint(1, 30))) > 33 circle0.setColor( > 34 color\=0x000000, > 35 fill\_c\=(random.randint(0, 255) << 16) > 36 | (random.randint(0, 255) << 8) > 37 | random.randint(0, 255), > 38 ) > 39 circle0.setCursor(x\=(random.randint(1, 320)), y\=(random.randint(1, 240))) > 40 time.sleep(0.5) > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/widgets/circle/example.png) [circle\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/widgets/circle/circle_core2_example.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Widgets.Circle(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _fg\_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0xffffff_, _bg\_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0xffffff_)[](#Widgets.Widgets.Circle "Link to this definition") Create a Circle object. It accepts the following parameters: > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > > * `r` is the radius of the circle. > > * `fg_color` is the foreground color of the displayed circle. > > * `bg_color` is the background color of the displayed circle. > Methods[](#methods "Link to this heading") -------------------------------------------- Widgets.setColor(_fg\_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0xffffff_, _bg\_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x000000_)[](#Widgets.Widgets.setColor "Link to this definition") Set the color of the Circle object. Accept the following parameters: > * `fg_color` is the foreground color of the displayed circle. > > * `bg_color` is the background color of the displayed circle. > UIFLOW2: > ![setColor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/circle/setColor.png) Widgets.setCursor(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Widgets.setCursor "Link to this definition") Set the position of the Circle object. Accept the following parameters: > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > UIFLOW2: > ![setCursor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/circle/setCursor.png) Widgets.setRadius(_radius: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Widgets.setRadius "Link to this definition") Set the radius of the Circle object. Accept the following parameters: > * `r` is the radius of the circle. > UIFLOW2: > ![setRadius.png](https://static-cdn.m5stack.com/mpy_docs/widgets/circle/setRadius.png) Widgets.setVisible(_visible: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#Widgets.Widgets.setVisible "Link to this definition") Set the visibility of the Circle object. Accept the following parameters: > * `visible` is the visibility of the displayed circle. > UIFLOW2: > ![setVisible.png](https://static-cdn.m5stack.com/mpy_docs/widgets/circle/setVisible.png) --- # Power — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * Power * [View page source](../_sources/system/power.rst.txt) * * * Power[](#power "Link to this heading") ======================================== class Power[](#class-power "Link to this heading") ---------------------------------------------------- Important Methods of the Power Class depend on `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg). All methods calling the Power object need to be placed after `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg). Methods[](#methods "Link to this heading") -------------------------------------------- Power.setExtOutput(_enable: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _, _port: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0xFF_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setExtOutput "Link to this definition") Set power output of the external ports. When `enable` is True, the power output of the external ports is in output mode. When `enable` is False, the power output of the external ports is in input mode. `port` is the port number, optional values are available in [class PORT](#class-port) , only valid for M5Stack Station. UIFLOW2: > ![setExtOutput1.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setExtOutput1.svg) ![setExtOutput2.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setExtOutput2.svg) Power.getExtOutput() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Power.getExtOutput "Link to this definition") Get power output of the external ports. Returns `True` if the power output of the external ports is in output mode. Returns `False` if the power output of the external ports is in input mode. UIFLOW2: > ![getExtOutput.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getExtOutput.svg) Power.setUsbOutput(_enable: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setUsbOutput "Link to this definition") Set power output of the main USB port. When `enable` is True, the power output of the main USB port is in output mode. When `enable` is False, the power output of the main USB port is in input mode. UIFLOW2: > ![setUsbOutput.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setUsbOutput.svg) Power.getUsbOutput() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Power.getUsbOutput "Link to this definition") Get power output of the main USB port. Returns `True` if the power output of the main USB port is in output mode. Returns `False` if the power output of the main USB port is in input mode. UIFLOW2: > ![getUsbOutput.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getUsbOutput.svg) Power.setLed(_brightness\=255_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setLed "Link to this definition") Turn on/off the power LED. `brightness` is the brightness value, ranging from 0 to 255. 0 is off, 255 is the maximum brightness. UIFLOW2: > ![setLed.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setLed.svg) Power.powerOff()[](#Power.powerOff "Link to this definition") Turn off all power. UIFLOW2: > ![powerOff.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/powerOff.svg) Power.timerSleep(_seconds_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.timerSleep "Link to this definition") Power.timerSleep(_minutes_, _hours_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") Power.timerSleep(_minutes_, _hours_, _date_, _weekDay_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") sleep and timer boot. The boot condition can be specified by the argument. `seconds`: Range is 1 - 15300, in seconds. `minutes`: Range is 0 - 59, in minutes. `hours`: Range is 0 - 23, in hours. `date`: Range is 1 - 31, in days. `weekDay`: Range is 0 - 6. UIFLOW2: > ![timerSleep1.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/timerSleep1.svg) ![timerSleep2.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/timerSleep2.svg) ![timerSleep3.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/timerSleep3.svg) Power.deepSleep(_micro\_seconds: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _wakeup: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_)[](#Power.deepSleep "Link to this definition") ESP32 deepsleep. `micro_seconds`: Number of micro seconds to wakeup. `wakeup`: Whether to wake up. UIFLOW2: > ![deepSleep.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/deepSleep.svg) Power.lightSleep(_micro\_seconds: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _wakeup: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_)[](#Power.lightSleep "Link to this definition") ESP32 lightsleep. `micro_seconds`: Number of micro seconds to wakeup. `wakeup`: Whether to wake up. UIFLOW2: > ![lightSleep.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/lightSleep.svg) Power.getBatteryLevel() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Power.getBatteryLevel "Link to this definition") Get the remaining battery power percentage. Returns a value between 0-100. UIFLOW2: > ![getBatteryLevel.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getBatteryLevel.svg) Power.setBatteryCharge(_enable: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setBatteryCharge "Link to this definition") Set battery charging enable. UIFLOW2: > ![setBatteryCharge.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setBatteryCharge.svg) Power.setChargeCurrent(_max\_mA: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setChargeCurrent "Link to this definition") Set battery charge current. `max_mA`: Range is 0-2000, in milliamps. UIFLOW2: > ![setChargeCurrent.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setChargeCurrent.svg) Power.setChargeVoltage(_max\_mV: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setChargeVoltage "Link to this definition") Set battery charge voltage. `max_mV`: Range is 4100-4600, in millivolts. UIFLOW2: > ![setChargeVoltage.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setChargeVoltage.svg) Power.isCharging() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Power.isCharging "Link to this definition") Get whether the battery is currently charging or not. UIFLOW2: > ![isCharging.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/isCharging.svg) Power.getBatteryVoltage() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Power.getBatteryVoltage "Link to this definition") Get battery voltage. Unit is millivolts. UIFLOW2: > ![getBatteryVoltage.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getBatteryVoltage.svg) Power.getBatteryCurrent() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Power.getBatteryCurrent "Link to this definition") Get battery current. Unit is milliamps. UIFLOW2: > ![getBatteryCurrent.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getBatteryCurrent.svg) Power.getKeyState() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Power.getKeyState "Link to this definition") Get Power Key Press condition. UIFLOW2: > ![getKeyState.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/getKeyState.svg) Power.setVibration(_level: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Power.setVibration "Link to this definition") Operate the vibration motor. `level`: Vibration intensity, ranging from 0-255. UIFLOW2: > ![setVibration.svg](https://static-cdn.m5stack.com/mpy_docs/system/power/setVibration.svg) class PORT[](#class-port "Link to this heading") -------------------------------------------------- Constants[](#constants "Link to this heading") ------------------------------------------------ PORT.A[](#PORT.A "Link to this definition") Port A. PORT.B1[](#PORT.B1 "Link to this definition") Port B1. PORT.B2[](#PORT.B2 "Link to this definition") Port B2. PORT.C1[](#PORT.C1 "Link to this definition") Port C1. PORT.C2[](#PORT.C2 "Link to this definition") Port C2. PORT.USB[](#PORT.USB "Link to this definition") USB Port. PORT.HAT[](#PORT.HAT "Link to this definition") HAT Port. PORT.ALL[](#PORT.ALL "Link to this definition") All Ports. --- # ADC (analog to digital conversion) — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * ADC (analog to digital conversion) * [View page source](../_sources/hardware/adc.rst.txt) * * * ADC (analog to digital conversion)[](#adc-analog-to-digital-conversion "Link to this heading") ================================================================================================ On the ESP32 chip, ADC functionality is available on pins 32-39 (ADC channel 1) and pins 0, 2, 4, 12-15 and 25-27 (ADC channel 2). On the ESP32S3 chip, ADC functionality is available on pins 1-10 (ADC channel 1) and pins 11-14 and 17-20 (ADC block 2). ADC channel 2 is also used by WiFi and so attempting to read analog values from channel 2 pins when WiFi is active will raise an exception. 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 \* > 9 > 10 > 11title0 \= None > 12label0 \= None > 13adc6 \= None > 14 > 15 > 16def setup(): > 17 global title0, label0, adc6 > 18 > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 title0 \= Widgets.Title("CoreS3 ADC Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 22 label0 \= Widgets.Label( > 23 "Read GPIO6 ADC Value:", 4, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 24 ) > 25 > 26 adc6 \= ADC(Pin(6), atten\=ADC.ATTN\_11DB) > 27 > 28 > 29def loop(): > 30 global title0, label0, adc6 > 31 M5.update() > 32 label0.setText(str((str("ADC Value:") + str((adc6.read()))))) > 33 > 34 > 35if \_\_name\_\_ \== "\_\_main\_\_": > 36 try: > 37 setup() > 38 while True: > 39 loop() > 40 except (Exception, KeyboardInterrupt) as e: > 41 try: > 42 from utility import print\_error\_msg > 43 > 44 print\_error\_msg(e) > 45 except ImportError: > 46 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/example.png) [adc\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/adc/adc_cores3_example.m5f2) class ADC[](#class-adc "Link to this heading") ------------------------------------------------ _class_ ADC(_pin_, _\*_, _atten_)[](#ADC "Link to this definition") Return the ADC object for the specified pin. ESP32 does not support different timings for ADC sampling and so the `sample_ns` keyword argument is not supported. To read voltages above the reference voltage, apply input attenuation with the `atten` keyword argument. Valid values (and approximate linear measurement ranges) are: > * `ADC.ATTN_0DB`: No attenuation (100mV - 950mV) > > * `ADC.ATTN_2_5DB`: 2.5dB attenuation (100mV - 1250mV) > > * `ADC.ATTN_6DB`: 6dB attenuation (150mV - 1750mV) > > * `ADC.ATTN_11DB`: 11dB attenuation (150mV - 2450mV) > UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/init.png) Warning Note that the absolute maximum voltage rating for input pins is 3.6V. Going near to this boundary risks damage to the IC! Methods[](#methods "Link to this heading") -------------------------------------------- ADC.read()[](#ADC.read "Link to this definition") This method returns the raw ADC value ranged according to the resolution of the block, e.g., 0-4095 for 12-bit resolution. UIFLOW2: > ![read.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/read.png) ADC.read\_u16()[](#ADC.read_u16 "Link to this definition") Take an analog reading and return an integer in the range 0-65535. The return value represents the raw reading taken by the ADC, scaled such that the minimum value is 0 and the maximum value is 65535. > UIFLOW2: > > > ![read_u16.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/read_u16.png) ADC.read\_uv()[](#ADC.read_uv "Link to this definition") This method uses the known characteristics of the ADC and per-package eFuse values - set during manufacture - to return a calibrated input voltage (before attenuation) in microvolts. The returned value has only millivolt resolution (i.e., will always be a multiple of 1000 microvolts). The calibration is only valid across the linear range of the ADC. In particular, an input tied to ground will read as a value above 0 microvolts. Within the linear range, however, more accurate and consistent results will be obtained than using read\_u16() and scaling the result with a constant. UIFLOW2: > ![read_uv.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/read_uv.png) ADC.atten(_atten_)[](#ADC.atten "Link to this definition") Equivalent to `ADC.init(atten=atten)`. UIFLOW2: > ![atten.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/atten.png) ADC.width(_bits_)[](#ADC.width "Link to this definition") Equivalent to `ADC.block().init(bits=bits)`. For compatibility, the `ADC` object also provides constants matching the supported ADC resolutions: * `ADC.WIDTH_9BIT` = 9 * `ADC.WIDTH_10BIT` = 10 * `ADC.WIDTH_11BIT` = 11 * `ADC.WIDTH_12BIT` = 12 UIFLOW2: > ![width.png](https://static-cdn.m5stack.com/mpy_docs/hardware/adc/width.png) --- # Cardputer — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * Cardputer * [View page source](../_sources/controllers/cardputer.rst.txt) * * * Cardputer[](#cardputer "Link to this heading") ================================================ Startup UI[](#startup-ui "Link to this heading") -------------------------------------------------- ### Launcher[](#launcher "Link to this heading") ![launcher.png](../_images/launcher.png) `FN` + `LEFT` and `FN` + `RIGHT` key cycle through the available applications. `Enter` launches the selected application. ### Setting[](#setting "Link to this heading") ![setting.png](../_images/setting.png) `FN` + `LEFT` and `FN` + `RIGHT` key cycle through the available applications. `Enter` launches the selected application. `BtnA` quits the application. #### WLAN[](#wlan "Link to this heading") ![wlan.png](../_images/wlan.png) `FN` + `UP` and `FN` + `DOWN` keys select the corresponding input box or button. `Enter` performs the corresponding action. `BtnA` quits the application. #### Gerneral[](#gerneral "Link to this heading") ![general.png](../_images/general.png) The `FN` + `UP` and `FN` + `DOWN` keys select menus. `Enter` set. `BtnA` quits the application. ### Develop[](#develop "Link to this heading") ![develop.png](../_images/develop.png) `BtnA` quits the application. ### APP.RUN[](#app-run "Link to this heading") ![apprun.png](../_images/apprun.png) `FN` + `LEFT` and `FN` + `RIGHT` keys select the corresponding execution action. `Enter` runs main.py according to the corresponding action. `BtnA` quits the application. ### APP.LIST[](#app-list "Link to this heading") ![applist.png](../_images/applist.png) `FN` + ```UP` and ``FN``` + `DOWN` key cycle through the available applications. `Enter` key runs the application once. `A` key runs the application always. `BtnA` quits the application. --- # StampS3 — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * StampS3 * [View page source](../_sources/controllers/stamps3.rst.txt) * * * StampS3[](#stamps3 "Link to this heading") ============================================ --- # M5 BLE — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * M5 BLE * [View page source](../_sources/system/m5ble.rst.txt) * * * M5 BLE[](#m5-ble "Link to this heading") ========================================== M5 BLE is a library that M5Stack has developed by wrapping the Low Level BLE of Micropython. It provides simpler and more user-friendly APIs. BLE Client example: \# client from m5ble import M5BLE UUID\_SERVICE1 \= "6E400011-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE1\_WR \= "6E400012-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE1\_RD \= "6E400013-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2 \= "6E400021-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2\_WR \= "6E400022-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2\_RD \= "6E400023-B5A3-F393-E0A9-E50E24DCCA9E" connected \= False def on\_connected(client): global connected print(client.\_service\_handle\_map) connected \= True ble.client.set\_mtu(128) def on\_disconnected(client, conn\_handle, addr\_type, addr): global connected connected \= False ble \= M5BLE.Device(verbose\=True) ble.client.scan(target\_name\_prefix\="M5") ble.client.on\_connected(on\_connected) try: while True: if connected: ble.client.write("Hello Service 1", UUID\_SERVICE1\_WR, UUID\_SERVICE1) ble.client.write("Hello Service 2", UUID\_SERVICE2\_WR, UUID\_SERVICE2) time.sleep(0.1) print(ble.client.read(UUID\_SERVICE1\_RD, UUID\_SERVICE1)) print(ble.client.read(UUID\_SERVICE2\_RD, UUID\_SERVICE2)) time.sleep(1) except KeyboardInterrupt: gc.collect() print("\\nExiting...") BLE Server example: \# server from m5ble import M5BLE UUID\_SERVICE1 \= "6E400011-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE1\_WR \= "6E400012-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE1\_RD \= "6E400013-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2 \= "6E400021-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2\_WR \= "6E400022-B5A3-F393-E0A9-E50E24DCCA9E" UUID\_SERVICE2\_RD \= "6E400023-B5A3-F393-E0A9-E50E24DCCA9E" def onReceive(server, client): print("onReceive") if client.any(UUID\_SERVICE1\_WR): client.write(client.read(UUID\_SERVICE1\_WR), UUID\_SERVICE1\_RD) if client.any(UUID\_SERVICE2\_WR): client.write(client.read(UUID\_SERVICE2\_WR), UUID\_SERVICE2\_RD) ble \= M5BLE.Device(verbose\=True) ble.server.add\_service(UUID\_SERVICE1, \[\ ble.server.create\_characteristic(UUID\_SERVICE1\_RD, notify\=True, read\=True),\ ble.server.create\_characteristic(UUID\_SERVICE1\_WR, write\=True),\ \]) ble.server.add\_service(UUID\_SERVICE2, \[\ ble.server.create\_characteristic(UUID\_SERVICE2\_RD, notify\=True, read\=True),\ ble.server.create\_characteristic(UUID\_SERVICE2\_WR, write\=True),\ \]) ble.server.start() ble.server.on\_receive(onReceive) while True: pass UIFLOW2 client example: > ![client_example.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_example.png) > > [m5ble\_client\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/m5ble/m5ble_client_cores3_example.m5f2) UIFLOW2 server example: > ![server_example.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_example.png) > > [m5ble\_server\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/m5ble/m5ble_server_cores3_example.m5f2) M5BLE[](#m5ble "Link to this heading") ---------------------------------------- Constructor[](#constructor "Link to this heading") ---------------------------------------------------- _class_ M5BLE.Device(_name_)[](#M5BLE.Device "Link to this definition") Creates an M5BLE object. * `name` The BLE broadcast name, used for device discovery and identification. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/init.png) Device Methods[](#device-methods "Link to this heading") ---------------------------------------------------------- M5BLE.Device.get\_mtu()[](#M5BLE.Device.get_mtu "Link to this definition") Retrieves the maximum transmission unit (MTU) for BLE connections, measured in bytes. UIFLOW2: > ![get_mtu.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/get_mtu.png) M5BLE.Device.deinit()[](#M5BLE.Device.deinit "Link to this definition") Closes the BLE connection and releases resources. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/deinit.png) Client Methods[](#client-methods "Link to this heading") ---------------------------------------------------------- M5BLE.Device.client.on\_connected(_callback_)[](#M5BLE.Device.client.on_connected "Link to this definition") Sets the callback function for successful BLE connection. * `callback` Callback function upon connection, parameter is callback(M5BLE.Client). UIFLOW2: > ![client_on_connected.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_connected.png) M5BLE.Device.client.on\_disconnected(_callback_)[](#M5BLE.Device.client.on_disconnected "Link to this definition") Sets the callback function for BLE disconnection. * `callback` Callback function upon disconnection, parameters are callback(M5BLE.Client, conn\_handle, addr\_type, addr). UIFLOW2: > ![client_on_disconnected.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_disconnected.png) M5BLE.Device.client.on\_server\_found(_callback_)[](#M5BLE.Device.client.on_server_found "Link to this definition") Sets the callback function for BLE service discovery. * `callback` Callback function for service discovery, parameters are callback(M5BLE.Client, (name, addr\_type, addr, adv\_type, rssi, adv\_data)). UIFLOW2: > ![client_on_server_found.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_server_found.png) M5BLE.Device.client.on\_scan\_finished(_callback_)[](#M5BLE.Device.client.on_scan_finished "Link to this definition") Sets the callback function for the end of BLE scanning. * `callback` Callback function at the end of scanning, parameter is callback(M5BLE.Client, scan\_result=\[\]). UIFLOW2: > ![client_on_scan_finished.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_scan_finished.png) M5BLE.Device.client.on\_read\_complete(_callback_)[](#M5BLE.Device.client.on_read_complete "Link to this definition") Sets the callback function for completed BLE reads. * `callback` Callback function upon read completion, parameters are callback(M5BLE.Client, conn\_handle, value\_handle, char\_data). UIFLOW2: > ![client_on_read_complete.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_read_complete.png) M5BLE.Device.client.on\_notify(_callback_)[](#M5BLE.Device.client.on_notify "Link to this definition") Sets the callback function for BLE notifications. * `callback` Notification callback function, parameter is callback(M5BLE.Client). UIFLOW2: > ![client_on_notify.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_on_notify.png) M5BLE.Device.client.scan(_timeout\=2000_, _connect\_on\_found\=True_, _target\_name\_prefix\='M5UiFlow'_, _target\_uuid\=None_)[](#M5BLE.Device.client.scan "Link to this definition") Scans for BLE devices. * `timeout` Scan timeout, in milliseconds, default is 2000ms. * `connect_on_found` Whether to automatically connect to devices when found, default is True. * `target_name_prefix` Name prefix for targeted devices, default is ‘M5UiFlow’. * `target_uuid` UUID of the targeted device. UIFLOW2: > ![client_scan.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_scan.png) M5BLE.Device.client.connect(_addr\_type_, _addr_)[](#M5BLE.Device.client.connect "Link to this definition") Connects to a BLE device. * `addr_type` Device address type. * `addr` Device address. UIFLOW2: > ![client_connect.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_connect.png) M5BLE.Device.client.set\_current\_service\_uuid(_service\_uuid_)[](#M5BLE.Device.client.set_current_service_uuid "Link to this definition") Sets the UUID for the current service, allowing the omission of the service\_uuid parameter when using any, read, write. * `service_uuid` UUID of the service. UIFLOW2: > ![client_set_current_service_uuid.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_set_current_service_uuid.png) M5BLE.Device.client.any(_char\_uuid_, _service\_uuid\=None_)[](#M5BLE.Device.client.any "Link to this definition") Checks for data availability for reading, returns the byte size of the buffer if available. * `char_uuid` UUID of the characteristic. * `service_uuid` UUID of the service. UIFLOW2: > ![client_any.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_any.png) M5BLE.Device.client.read(_char\_uuid_, _service\_uuid\=None_, _sz\=None_)[](#M5BLE.Device.client.read "Link to this definition") Reads data from a BLE device. * `char_uuid` UUID of the characteristic. * `service_uuid` UUID of the service. * `sz` Number of bytes to read, None reads all available bytes. UIFLOW2: > ![client_read.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_read.png) M5BLE.Device.client.write(_data_, _char\_uuid_, _service\_uuid\=None_)[](#M5BLE.Device.client.write "Link to this definition") Writes data to a BLE device. * `data` Data to be written. * `char_uuid` UUID of the characteristic. * `service_uuid` UUID of the service. UIFLOW2: > ![client_write.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_write.png) M5BLE.Device.client.close()[](#M5BLE.Device.client.close "Link to this definition") Closes the BLE connection. UIFLOW2: > ![client_close.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_close.png) M5BLE.Device.client.get\_services()[](#M5BLE.Device.client.get_services "Link to this definition") Retrieves a list of BLE services. UIFLOW2: > ![client_get_services.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_get_services.png) M5BLE.Device.client.get\_characteristics(_service\_uuid_)[](#M5BLE.Device.client.get_characteristics "Link to this definition") Retrieves a list of characteristics for a BLE service. * `service_uuid` UUID of the service. UIFLOW2: > ![client_get_characteristics.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_get_characteristics.png) M5BLE.Device.client.set\_mtu(_mtu_)[](#M5BLE.Device.client.set_mtu "Link to this definition") Sets the maximum transmission unit (MTU) for BLE connections, in bytes. * `mtu` Size of the transmission unit, in bytes, ranging from 23-517. Note that not all devices support MTUs larger than 23. UIFLOW2: > ![set_mtu.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/client_set_mtu.png) Server Methods[](#server-methods "Link to this heading") ---------------------------------------------------------- M5BLE.Device.server.clear\_services()[](#M5BLE.Device.server.clear_services "Link to this definition") Clears the added services. UIFLOW2: > ![server_clear_services.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_clear_services.png) M5BLE.Device.server.add\_service(_uuid_, _characteristics_)[](#M5BLE.Device.server.add_service "Link to this definition") Adds a service * `uuid` UUID of the service * `characteristics` List of characteristics included in the service, created using create\_characteristic UIFLOW2: > ![server_add_service.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_add_service.png) M5BLE.Device.server.create\_characteristic(_uuid_, _read_, _write_, _notify_)[](#M5BLE.Device.server.create_characteristic "Link to this definition") Creates a characteristic * `uuid` UUID of the characteristic * `read` Whether the characteristic is readable * `write` Whether the characteristic is writable * `notify` Whether the characteristic can notify UIFLOW2: > ![server_create_characteristic.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_create_characteristic.png) M5BLE.Device.server.start(_interval\_us_)[](#M5BLE.Device.server.start "Link to this definition") Starts the BLE service * `interval_us` Broadcast interval time, in microseconds, default is 500000us. UIFLOW2: > ![server_start.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_start.png) M5BLE.Device.server.on\_receive(_callback_)[](#M5BLE.Device.server.on_receive "Link to this definition") Sets the callback function for receiving data on BLE. * `callback` Data reception callback function, parameters are callback(M5BLE.Server, connected\_client\_handle). UIFLOW2: > ![server_on_receive.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_on_receive.png) M5BLE.Device.server.on\_connected(_callback_)[](#M5BLE.Device.server.on_connected "Link to this definition") Sets the callback function for successful BLE device connection. * `callback` Callback function upon device connection, parameters are callback(M5BLE.Server, connected\_client\_handle). UIFLOW2: > ![server_on_connected.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_on_connected.png) M5BLE.Device.server.on\_disconnected(_callback_)[](#M5BLE.Device.server.on_disconnected "Link to this definition") Sets the callback function for BLE device disconnection. * `callback` Callback function upon device disconnection, parameters are callback(M5BLE.Server, connected\_client\_handle). UIFLOW2: > ![server_on_disconnected.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_on_disconnected.png) M5BLE.Device.server.get\_client(_index_)[](#M5BLE.Device.server.get_client "Link to this definition") Retrieves a connected client * `index` Index of the client UIFLOW2: > ![server_get_client.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_get_client.png) M5BLE.Device.server.get\_clients()[](#M5BLE.Device.server.get_clients "Link to this definition") Retrieves a list of connected clients UIFLOW2: > ![server_get_clients.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/server_get_clients.png) Server - connected\_client\_handle Methods[](#server-connected-client-handle-methods "Link to this heading") -------------------------------------------------------------------------------------------------------------- connected\_client\_handle is passed by the callback function’s parameters, or obtained using get\_client. connected\_client\_handle.any(_uuid_)[](#connected_client_handle.any "Link to this definition") Checks for data availability for reading, returns the byte size of the buffer if available. * `uuid` UUID of the characteristic. UIFLOW2: > ![handle_any.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/handle_any.png) connected\_client\_handle.read(_uuid_, _sz\=None_)[](#connected_client_handle.read "Link to this definition") Reads data from a BLE device. * `uuid` UUID of the characteristic. * `sz` Number of bytes to read, None reads all available bytes. UIFLOW2: > ![handle_read.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/handle_read.png) > > ![handle_read_all.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/handle_read_all.png) connected\_client\_handle.write(_data_, _uuid_)[](#connected_client_handle.write "Link to this definition") Writes data to a BLE device. * `data` Data to be written. * `uuid` UUID of the characteristic. UIFLOW2: > ![handle_write.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/handle_write.png) connected\_client\_handle.close()[](#connected_client_handle.close "Link to this definition") Disconnects the link UIFLOW2: > ![handle_close.png](https://static-cdn.m5stack.com/mpy_docs/system/ble/handle_close.png) --- # class Image – display image — UIFlow2 Programming Guide master documentation * [](../index.html) * [`Widgets` — A basic UI library](index.html) * class Image – display image * [View page source](../_sources/widgets/image.rst.txt) * * * class Image – display image[](#class-image-display-image "Link to this heading") ================================================================================== Image is the basic object type used to display images. 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 \* > 8 > 9 > 10image0 \= None > 11title0 \= None > 12 > 13 > 14def setup(): > 15 global image0, title0 > 16 > 17 M5.begin() > 18 Widgets.fillScreen(0x222222) > 19 image0 \= Widgets.Image("res/img/SCR-20240902-itcy.png", 71, 64) > 20 title0 \= Widgets.Title("Image CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 21 > 22 image0.setImage("res/img/default.png") > 23 image0.setImage("res/img/SCR-20240902-itcy.png") > 24 image0.setCursor(x\=0, y\=0) > 25 image0.setVisible(True) > 26 > 27 > 28def loop(): > 29 global image0, title0 > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image/example.png) [image\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/widgets/image/image_cores3_example.m5f2.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Widgets.Image(_str: file_, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _parent_)[](#Widgets.Widgets.Image "Link to this definition") Create an Image object. It accepts the following parameters: > * `file` is the path to the image file to be displayed. Supported formats are BMP, JPG, and PNG. > > * `x` is the starting X-axis coordinate where the image will be displayed. > > * `y` is the starting Y-axis coordinate where the image will be displayed. > > * `parent` is the graphical object on which the image will be drawn. If not provided, the default display will be used. > Methods[](#methods "Link to this heading") -------------------------------------------- Image.setCursor(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Image.setCursor "Link to this definition") Set the position of the Imgae object. Accept the following parameters: > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > UIFLOW2: > ![setCursor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image/setCursor.png) Image.setImage(_str: file_)[](#Widgets.Image.setImage "Link to this definition") Set the image to be displayed. > * `file` is the path to the new image file to be displayed. > UIFLOW2: > ![setImage.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image/setImage.png) > > ![setImage1.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image/setImage1.png) Image.setVisible(_visible: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#Widgets.Image.setVisible "Link to this definition") Set the visibility of the Imgae object. Accept the following parameters: > * `visible` is the visibility of the displayed image. > UIFLOW2: > ![setVisible.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image/setVisible.png) --- # 4In8Out Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * 4In8Out Module * [View page source](../_sources/module/4in8out.rst.txt) * * * 4In8Out Module[](#in8out-module "Link to this heading") ========================================================= Support the following products: [![Module4In8Out](https://static-cdn.m5stack.com/resource/docs/products/module/4in8out/4in8out_01.webp)](https://docs.m5stack.com/en/module/4in8out) Micropython Example: > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from module import Module4In8Out > 8import time > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16module\_4in8out\_0 \= None > 17 > 18 > 19load\_num \= None > 20switch\_num \= None > 21state \= None > 22 > 23 > 24def setup(): > 25 global title0, label0, label1, label2, label3, module\_4in8out\_0, load\_num, switch\_num, state > 26 > 27 M5.begin() > 28 Widgets.fillScreen(0x222222) > 29 title0 \= Widgets.Title("4In8OutModule Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 30 label0 \= Widgets.Label( > 31 "Switch i Status:", 1, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 32 ) > 33 label1 \= Widgets.Label( > 34 "Load i Status:", 1, 118, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 35 ) > 36 label2 \= Widgets.Label("I2C Addr:", 1, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 37 label3 \= Widgets.Label( > 38 "FW Version:", 176, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 39 ) > 40 > 41 module\_4in8out\_0 \= Module4In8Out(address\=0x45) > 42 label2.setText(str((str("I2C Addr:") + str((module\_4in8out\_0.get\_i2c\_address()))))) > 43 label3.setText(str((str("FW Version:") + str((module\_4in8out\_0.get\_firmware\_version()))))) > 44 load\_num \= 1 > 45 switch\_num \= 1 > 46 state \= 1 > 47 > 48 > 49def loop(): > 50 global title0, label0, label1, label2, label3, module\_4in8out\_0, load\_num, switch\_num, state > 51 M5.update() > 52 load\_num \= load\_num + 1 > 53 switch\_num \= switch\_num + 1 > 54 if load\_num \> 8: > 55 load\_num \= 1 > 56 state \= not state > 57 if switch\_num \> 4: > 58 switch\_num \= 1 > 59 module\_4in8out\_0.set\_load\_state(load\_num, state) > 60 label0.setText( > 61 str( > 62 ( > 63 str("Switch ") > 64 + str( > 65 ( > 66 str(switch\_num) > 67 + str( > 68 ( > 69 str(" Status:") > 70 + str((module\_4in8out\_0.get\_switch\_value(switch\_num))) > 71 ) > 72 ) > 73 ) > 74 ) > 75 ) > 76 ) > 77 ) > 78 label1.setText( > 79 str( > 80 ( > 81 str("Load ") > 82 + str( > 83 ( > 84 str(load\_num) > 85 + str( > 86 (str(" Status:") + str((module\_4in8out\_0.get\_load\_state(switch\_num)))) > 87 ) > 88 ) > 89 ) > 90 ) > 91 ) > 92 ) > 93 time.sleep(1) > 94 > 95 > 96if \_\_name\_\_ \== "\_\_main\_\_": > 97 try: > 98 setup() > 99 while True: > 100 loop() > 101 except (Exception, KeyboardInterrupt) as e: > 102 try: > 103 from utility import print\_error\_msg > 104 > 105 print\_error\_msg(e) > 106 except ImportError: > 107 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/example.png) [module4in8out\_fire\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/4in8out/module4in8out_fire_example.m5f2) class Module4In8Out[](#class-module4in8out "Link to this heading") -------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Module4In8Out(_address_)[](#Module4In8Out "Link to this definition") Init I2C Module 4In8Out I2C Address. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the 4In8OutModule. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Module4In8Out.get\_switch\_value(_switch\_num_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Module4In8Out.get_switch_value "Link to this definition") Get the current value of the rotary. Parameters: **switch\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Switch number (1 to 4). UIFLOW2: > ![get_switch_value.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_switch_value.png) Module4In8Out.get\_load\_state(_load\_num_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Module4In8Out.get_load_state "Link to this definition") Get the state of a specific LED. Parameters: **load\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Load number (1 to 8). UIFLOW2: > ![get_load_state.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_load_state.png) Module4In8Out.set\_load\_state(_load\_num_, _state_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Module4In8Out.set_load_state "Link to this definition") Set the state of a specific Load. Parameters: * **load\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Load number (1 to 8). * **state** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The state to set for the Load. UIFLOW2: > ![set_load_state.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/set_load_state.png) Module4In8Out.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Module4In8Out.get_firmware_version "Link to this definition") Get the firmware version of the 4In8Out module. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_firmware_version.png) Module4In8Out.get\_i2c\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Module4In8Out.get_i2c_address "Link to this definition") Get the current I2C address of the 4In8Out module. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_i2c_address.png) Module4In8Out.set\_i2c\_address(_addr_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Module4In8Out.set_i2c_address "Link to this definition") Set a new I2C address for the 4In8Out module. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address to set. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/4in8out/set_i2c_address.png) --- # CoreInk — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * CoreInk * [View page source](../_sources/controllers/coreink.rst.txt) * * * CoreInk[](#coreink "Link to this heading") ============================================ UI[](#ui "Link to this heading") ---------------------------------- ![op.png](../_images/coreink_op.png) CoreInk has 4 buttons, **Up**, **Down**, **Center**, and **Btn.EXT**. ![flow.png](../_images/coreink_flow.png) **Btn.EXT** key cycles through the available applications. ![config.png](../_images/coreink_config.png) **Down** key toggles between available servers. **Btn.EXT** key cycles through the available applications. ![applist.png](../_images/coreink_applist.png) **Up** and **Down** keys cycle through scripts. **Center** key runs the specified script. **Btn.EXT** key cycles through the available applications. --- # ADC Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * ADC Hat * [View page source](../_sources/hats/adc.rst.txt) * * * ADC Hat[](#adc-hat "Link to this heading") ============================================ The following products are supported: > [![ADC](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-adc/hat-adc_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat-adc) 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 hat import ADCHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_adc\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, hat\_adc\_0 > 19 > 20 M5.begin() > 21 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 24 hat\_adc\_0 \= ADCHat(i2c0) > 25 > 26 > 27def loop(): > 28 global label0, i2c0, hat\_adc\_0 > 29 M5.update() > 30 label0.setText(str(hat\_adc\_0.get\_voltage())) > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/adc/example.png) [stickc\_plus2\_adc\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/adc/stickc_plus2_adc_example.m5f2) class CANUnit[](#class-canunit "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ADCHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x48_)[](#ADCHat "Link to this definition") Create an instance of the ADC Hat. Parameters: * **i2c** – I2C bus * **address** – I2C address of the ADC Hat UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/adc/init.png) ADCHat class inherits ADCUnit class, See [unit.ADCUnit.Methods](../units/adc.html#unit-adcunit-methods) for more details. --- # AIN4 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * AIN4 Module * [View page source](../_sources/module/ain4.rst.txt) * * * AIN4 Module[](#ain4-module "Link to this heading") ==================================================== The following products are supported: [![AIN4Module](https://static-cdn.m5stack.com/resource/docs/products/module/AIN4-20mA%20Module%2013.2/img-ddec758e-78ce-43e8-9af7-bc101f3dc175.webp)](https://docs.m5stack.com/en/module/AIN4-20mA%20Module%2013.2) Micropython Example: import os, sys, io import M5 from M5 import \* from module import AIN4Module title0 \= None label0 \= None label1 \= None label2 \= None label3 \= None ain4\_20ma\_0 \= None def setup(): global title0, label0, label1, label2, label3, ain4\_20ma\_0 M5.begin() Widgets.fillScreen(0x222222) title0 \= Widgets.Title("AIN 4-20mA Module Test", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu18) label0 \= Widgets.Label("CH1 Current:", 1, 60, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label1 \= Widgets.Label("CH2 Current:", 1, 96, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label2 \= Widgets.Label("CH3 Current:", 1, 131, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label3 \= Widgets.Label("CH4 Current:", 1, 164, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) ain4\_20ma\_0 \= AIN4Module(address\=0x55) ain4\_20ma\_0.set\_cal\_current(1, 20) ain4\_20ma\_0.set\_cal\_current(2, 20) ain4\_20ma\_0.set\_cal\_current(3, 20) ain4\_20ma\_0.set\_cal\_current(4, 20) def loop(): global title0, label0, label1, label2, label3, ain4\_20ma\_0 M5.update() label0.setText(str((str('CH1 Current:') + str((ain4\_20ma\_0.get\_current\_value(1)))))) label1.setText(str((str('CH2 Current:') + str((ain4\_20ma\_0.get\_current\_value(2)))))) label2.setText(str((str('CH3 Current:') + str((ain4\_20ma\_0.get\_current\_value(3)))))) label3.setText(str((str('CH4 Current:') + str((ain4\_20ma\_0.get\_current\_value(4)))))) if \_\_name\_\_ \== '\_\_main\_\_': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print\_error\_msg print\_error\_msg(e) except ImportError: print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/example.png) [ain4\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/ain4/ain4_core2_example.m5f2) class AIN4Module[](#class-ain4module "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ AIN4Module(_address_)[](#AIN4Module "Link to this definition") Init I2C Module AIN 4-20mA I2C Address. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the AIN4Module. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- AIN4Module.get\_adc\_raw\_value(_channel_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#AIN4Module.get_adc_raw_value "Link to this definition") > Retrieves the raw ADC value from the specified channel. Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel number (1 to 4) to read the ADC value from. Returns: Raw ADC value as a 12-bit integer. UIFLOW2: > ![get_adc_raw_value.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/get_adc_raw_value.png) AIN4Module.get\_current\_value(_channel_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#AIN4Module.get_current_value "Link to this definition") Retrieves the current value (in mA) from the specified channel. Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel number (1 to 4) to read the current value from. Returns: Current value in milliamperes (mA). UIFLOW2: > ![get_current_value.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/get_current_value.png) AIN4Module.set\_cal\_current(_channel_, _val_)[](#AIN4Module.set_cal_current "Link to this definition") Sets the calibration current for the specified channel. Parameters: * **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel number (1 to 4) to set the calibration for. * **val** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The calibration current value, ranging from 4 to 20 mA. UIFLOW2: > ![set_cal_current.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/set_cal_current.png) AIN4Module.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#AIN4Module.get_firmware_version "Link to this definition") Retrieves the firmware version of the AIN 4-20mA module. Returns: Firmware version. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/get_firmware_version.png) AIN4Module.get\_i2c\_address() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#AIN4Module.get_i2c_address "Link to this definition") Retrieves the current I2C address of the AIN 4-20mA module. Returns: I2C address as a string in hexadecimal format. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/get_i2c_address.png) AIN4Module.set\_i2c\_address(_addr_)[](#AIN4Module.set_i2c_address "Link to this definition") Sets a new I2C address for the AIN 4-20mA module. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address, must be between 0x08 and 0x77. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/ain4_20ma/set_i2c_address.png) --- # AirQ — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * AirQ * [View page source](../_sources/controllers/airq.rst.txt) * * * AirQ[](#airq "Link to this heading") ====================================== UI[](#ui "Link to this heading") ---------------------------------- ![flow.png](../_images/airq_flow.png) **A** key cycles through the available applications. ![config.png](../_images/airq_config.png) **B** key toggles between available servers. **A** key cycles through the available applications. ![applist.png](../_images/airq_applist.png) **B** key cycles through scripts. **A** and **B** keys **pressed simultaneously** run the specified script. **A** key cycles through the available applications. --- # CardKB Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * CardKB Hat * [View page source](../_sources/hats/cardkb.rst.txt) * * * CardKB Hat[](#cardkb-hat "Link to this heading") ================================================== The following products are supported: > [![CardKB Hat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-cardkb/hat-cardkb_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat-cardkb) 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 hat import CardKBHat > 9from hardware import \* > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_cardkb\_0 \= None > 15 > 16 > 17def hat\_cardkb\_0\_pressed\_event(kb): > 18 global label0, i2c0, hat\_cardkb\_0 > 19 label0.setText(str(hat\_cardkb\_0.get\_string())) > 20 > 21 > 22def setup(): > 23 global label0, i2c0, hat\_cardkb\_0 > 24 > 25 M5.begin() > 26 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 > 28 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 29 hat\_cardkb\_0 \= CardKBHat(i2c0, 0x5F) > 30 hat\_cardkb\_0.set\_callback(hat\_cardkb\_0\_pressed\_event) > 31 > 32 > 33def loop(): > 34 global label0, i2c0, hat\_cardkb\_0 > 35 M5.update() > 36 hat\_cardkb\_0.tick() > 37 > 38 > 39if \_\_name\_\_ \== "\_\_main\_\_": > 40 try: > 41 setup() > 42 while True: > 43 loop() > 44 except (Exception, KeyboardInterrupt) as e: > 45 try: > 46 from utility import print\_error\_msg > 47 > 48 print\_error\_msg(e) > 49 except ImportError: > 50 print("please update to latest firmware") UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/hat/cardkb/example.svg) [stickc\_plus2\_cardkb\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/cardkb/stickc_plus2_cardkb_example.m5f2) class CardKBHat[](#class-cardkbhat "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ CardKBHat(_i2c: I2C_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x5F_)[](#CardKBHat "Link to this definition") Create a CardKBHat object. Parameters: * **i2c** – I2C object * **address** – the I2C address of the device. Default is 0x5F. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/cardkb/init.png) CardKBHat class inherits CardKBUnit class, See [unit.CardKBUnit.Methods](../units/cardkb.html#unit-cardkbunit-methods) for more details. --- # USB Drivers — UIFlow2 Programming Guide master documentation * [](../../index.html) * [Advanced](../index.html) * USB Drivers * [View page source](../../_sources/advanced/usb/index.rst.txt) * * * USB Drivers[](#usb-drivers "Link to this heading") ==================================================== These packages allow implementing USB functionality on a MicroPython system using pure Python code. Modules[](#modules "Link to this heading") -------------------------------------------- * [USB Device](device/index.html) --- # DAC Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * DAC Hat * [View page source](../_sources/hats/dac.rst.txt) * * * DAC Hat[](#dac-hat "Link to this heading") ============================================ The following products are supported: > [![DAC](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-dac/hat-dac_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat-dac) 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 hat import DACHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_dac\_0 \= None > 15 > 16 > 17v \= None > 18 > 19 > 20def btnA\_wasClicked\_event(state): \# noqa: N802 > 21 global label0, i2c0, hat\_dac\_0, v > 22 if v \>= 0.1: > 23 v \= v \- 0.1 > 24 hat\_dac\_0.set\_voltage(v) > 25 > 26 > 27def btnB\_wasClicked\_event(state): \# noqa: N802 > 28 global label0, i2c0, hat\_dac\_0, v > 29 if v < 3.3: > 30 v \= v + 0.1 > 31 hat\_dac\_0.set\_voltage(v) > 32 > 33 > 34def btnPWR\_wasClicked\_event(state): \# noqa: N802 > 35 global label0, i2c0, hat\_dac\_0, v > 36 v \= 0 > 37 hat\_dac\_0.set\_voltage(v) > 38 > 39 > 40def setup(): > 41 global label0, i2c0, hat\_dac\_0, v > 42 > 43 M5.begin() > 44 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 45 > 46 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 47 BtnB.setCallback(type\=BtnB.CB\_TYPE.WAS\_CLICKED, cb\=btnB\_wasClicked\_event) > 48 BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btnPWR\_wasClicked\_event) > 49 > 50 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 51 hat\_dac\_0 \= DACHat(i2c0) > 52 v \= 0 > 53 > 54 > 55def loop(): > 56 global label0, i2c0, hat\_dac\_0, v > 57 M5.update() > 58 label0.setText(str(hat\_dac\_0.get\_voltage())) > 59 > 60 > 61if \_\_name\_\_ \== "\_\_main\_\_": > 62 try: > 63 setup() > 64 while True: > 65 loop() > 66 except (Exception, KeyboardInterrupt) as e: > 67 try: > 68 from utility import print\_error\_msg > 69 > 70 print\_error\_msg(e) > 71 except ImportError: > 72 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/dac/example.png) [stickc\_plus2\_dac\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/dac/stickc_plus2_dac_example.m5f2) class DACHat[](#class-dachat "Link to this heading") ------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ DACHat(_i2c: I2C_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x60_, _vdd: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") \= 5.0_, _vout: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") \= 3.3_)[](#DACHat "Link to this definition") Create a DAC Hat object. Parameters: * **i2c** – I2C object * **address** – I2C address of the DAC Hat * **vdd** – VDD voltage of the DAC Hat * **vout** – VOUT voltage of the DAC Hat UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/dac/init.png) DACHat class inherits DACUnit class, See [unit.DACUnit.Methods](../units/dac.html#unit-dacunit-methods) for more details. --- # Bala2 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Bala2 Module * [View page source](../_sources/module/bala2.rst.txt) * * * Bala2 Module[](#bala2-module "Link to this heading") ====================================================== The Bala2 Module is part of the M5Stack stackable module series. The module communicates with the host via the I2C interface, and its built-in microcontroller manages PWM control for the motor, reads the encoder count, and outputs control signals for the servo. Support the following products: > [![Bala2](https://static-cdn.m5stack.com/resource/docs/products/app/bala2/bala2_01.webp)](https://docs.m5stack.com/en/app/bala2) > > [![Bala2-Fire](https://static-cdn.m5stack.com/resource/docs/products/app/bala2fire/bala2_01.webp)](https://docs.m5stack.com/en/app/bala2fire) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Servo control[](#servo-control "Link to this heading") Open the [servo\_control\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/bala2/servo_control_example.m5f2) project in UiFlow2. Control the servo to swing back and forth between 0° and 180°. UiFlow2 Code Block: > ![servo_control_example.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/servo_control_example.png) Example output: > None ### Motor control[](#motor-control "Link to this heading") Open the [motor\_control\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/bala2/motor_control_example.m5f2) project in UiFlow2. Run the program, and the car’s motors will first rotate forward, gradually accelerating to the maximum speed, then gradually decelerating to a stop. Next, the motors will reverse, similarly accelerating to the maximum speed before gradually slowing down to a stop. Finally, the car will come to a complete stop, with the motor speed returning to zero. UiFlow2 Code Block: > ![motor_control_example.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/motor_control_example.png) Example output: > None ### Read encoder[](#read-encoder "Link to this heading") Open the [read\_encoder\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/bala2/read_encoder_example.m5f2) project in UiFlow2. Run the program and manually rotate the wheels to observe the screen display. UiFlow2 Code Block: > ![read_encoder_example.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/read_encoder_example.png) Example output: > None ### Car control[](#car-control "Link to this heading") Open the [car\_control\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/bala2/car_control_example.m5f2) project in UiFlow2. Save the program to the controller, place the car on its side, and turn it on. After the gyroscope calibration is complete, the car will automatically stand upright and maintain balance. It will then perform a series of actions, including turning left, turning right, moving forward, and moving backward. Finally, it will stop and return to the balanced state. UiFlow2 Code Block: > ![car_control_example.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/car_control_example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Servo control[](#id1 "Link to this heading") Control the servo to swing back and forth between 0° and 180°. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import Bala2Module > 9import time > 10 > 11 > 12title0 \= None > 13label\_servo1 \= None > 14label\_servo1\_val \= None > 15module\_bala2\_0 \= None > 16t\_dir \= None > 17last\_time \= None > 18angle \= None > 19 > 20 > 21def setup(): > 22 global title0, label\_servo1, label\_servo1\_val, module\_bala2\_0, t\_dir, last\_time, angle > 23 M5.begin() > 24 Widgets.fillScreen(0x222222) > 25 title0 \= Widgets.Title("Bala2 Servo Control", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 26 label\_servo1 \= Widgets.Label("Angle:", 54, 85, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 label\_servo1\_val \= Widgets.Label("0", 125, 85, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 28 module\_bala2\_0 \= Bala2Module(0) > 29 t\_dir \= True > 30 angle \= 0 > 31 last\_time \= time.ticks\_ms() > 32 > 33 > 34def loop(): > 35 global title0, label\_servo1, label\_servo1\_val, module\_bala2\_0, t\_dir, last\_time, angle > 36 M5.update() > 37 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \> 10: > 38 last\_time \= time.ticks\_ms() > 39 angle \= angle + 1 > 40 if angle \> 180: > 41 angle \= 0 > 42 t\_dir \= not t\_dir > 43 if t\_dir: > 44 module\_bala2\_0.set\_servo\_angle(1, angle) > 45 else: > 46 module\_bala2\_0.set\_servo\_angle(1, 180 \- angle) > 47 label\_servo1\_val.setText(str(angle)) > 48 > 49 > 50if \_\_name\_\_ \== "\_\_main\_\_": > 51 try: > 52 setup() > 53 while True: > 54 loop() > 55 except (Exception, KeyboardInterrupt) as e: > 56 try: > 57 from utility import print\_error\_msg > 58 > 59 print\_error\_msg(e) > 60 except ImportError: > 61 print("please update to latest firmware") Example output: > None ### Motor control[](#id2 "Link to this heading") Run the program, and the car’s motors will first rotate forward, gradually accelerating to the maximum speed, then gradually decelerating to a stop. Next, the motors will reverse, similarly accelerating to the maximum speed before gradually slowing down to a stop. Finally, the car will come to a complete stop, with the motor speed returning to zero. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import Bala2Module > 9import time > 10 > 11 > 12title0 \= None > 13module\_bala2\_0 \= None > 14i \= None > 15 > 16 > 17def setup(): > 18 global title0, module\_bala2\_0, i > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 title0 \= Widgets.Title("Bala2 Motor Control", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 22 > 23 module\_bala2\_0 \= Bala2Module(0) > 24 for i in range(1, 1001): > 25 module\_bala2\_0.set\_motor\_speed(i, i) > 26 time.sleep\_ms(10) > 27 for i in range(1, 1001): > 28 module\_bala2\_0.set\_motor\_speed(1000 \- i, 1000 \- i) > 29 time.sleep\_ms(10) > 30 for i in range(1, 1001): > 31 module\_bala2\_0.set\_motor\_speed(0 \- i, 0 \- i) > 32 time.sleep\_ms(10) > 33 for i in range(\-1000, 1): > 34 module\_bala2\_0.set\_motor\_speed(i, i) > 35 time.sleep\_ms(10) > 36 module\_bala2\_0.set\_motor\_speed(0, 0) > 37 > 38 > 39def loop(): > 40 global title0, module\_bala2\_0, i > 41 M5.update() > 42 > 43 > 44if \_\_name\_\_ \== "\_\_main\_\_": > 45 try: > 46 setup() > 47 while True: > 48 loop() > 49 except (Exception, KeyboardInterrupt) as e: > 50 try: > 51 from utility import print\_error\_msg > 52 > 53 print\_error\_msg(e) > 54 except ImportError: > 55 print("please update to latest firmware") Example output: > None ### Read encoder[](#id3 "Link to this heading") Run the program and manually rotate the wheels to observe the screen display. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import Bala2Module > 9import time > 10 > 11 > 12title0 \= None > 13label\_enc1 \= None > 14label\_enc2 \= None > 15label\_enc1\_val \= None > 16label\_enc2\_val \= None > 17module\_bala2\_0 \= None > 18last\_time \= None > 19enc\_value \= None > 20enc1 \= None > 21enc2 \= None > 22 > 23 > 24def setup(): > 25 global \\ > 26 title0, \\ > 27 label\_enc1, \\ > 28 label\_enc2, \\ > 29 label\_enc1\_val, \\ > 30 label\_enc2\_val, \\ > 31 module\_bala2\_0, \\ > 32 last\_time, \\ > 33 enc\_value, \\ > 34 enc1, \\ > 35 enc2 > 36 M5.begin() > 37 Widgets.fillScreen(0x222222) > 38 title0 \= Widgets.Title("Bala2 Encoder Read", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 39 label\_enc1 \= Widgets.Label("Enc1", 54, 85, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 40 label\_enc2 \= Widgets.Label("Enc2", 208, 85, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 41 label\_enc1\_val \= Widgets.Label("0", 50, 125, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 42 label\_enc2\_val \= Widgets.Label("0", 202, 125, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 43 module\_bala2\_0 \= Bala2Module(0) > 44 module\_bala2\_0.set\_encoder\_value(0, 0) > 45 last\_time \= time.ticks\_ms() > 46 > 47 > 48def loop(): > 49 global \\ > 50 title0, \\ > 51 label\_enc1, \\ > 52 label\_enc2, \\ > 53 label\_enc1\_val, \\ > 54 label\_enc2\_val, \\ > 55 module\_bala2\_0, \\ > 56 last\_time, \\ > 57 enc\_value, \\ > 58 enc1, \\ > 59 enc2 > 60 M5.update() > 61 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \> 100: > 62 last\_time \= time.ticks\_ms() > 63 enc\_value \= module\_bala2\_0.get\_encoder\_value() > 64 enc1 \= enc\_value\[0\] > 65 enc2 \= enc\_value\[1\] > 66 label\_enc1\_val.setText(str(enc1)) > 67 label\_enc2\_val.setText(str(enc2)) > 68 > 69 > 70if \_\_name\_\_ \== "\_\_main\_\_": > 71 try: > 72 setup() > 73 while True: > 74 loop() > 75 except (Exception, KeyboardInterrupt) as e: > 76 try: > 77 from utility import print\_error\_msg > 78 > 79 print\_error\_msg(e) > 80 except ImportError: > 81 print("please update to latest firmware") Example output: > None ### Car control[](#id4 "Link to this heading") Save the program to the controller, place the car on its side, and turn it on. After the gyroscope calibration is complete, the car will automatically stand upright and maintain balance. It will then perform a series of actions, including turning left, turning right, moving forward, and moving backward. Finally, it will stop and return to the balanced state. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import Bala2Module > 9import time > 10 > 11 > 12title0 \= None > 13module\_bala2\_0 \= None > 14i \= None > 15 > 16 > 17def setup(): > 18 global title0, module\_bala2\_0, i > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 title0 \= Widgets.Title("Self-Balancing Robot", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 22 module\_bala2\_0 \= Bala2Module(0) > 23 module\_bala2\_0.calibrate() > 24 module\_bala2\_0.start() > 25 time.sleep\_ms(2000) > 26 module\_bala2\_0.set\_turn\_speed(\-100) > 27 time.sleep\_ms(1000) > 28 module\_bala2\_0.set\_turn\_speed(100) > 29 time.sleep\_ms(1000) > 30 module\_bala2\_0.set\_turn\_speed(0) > 31 time.sleep\_ms(2000) > 32 for i in range(20): > 33 module\_bala2\_0.set\_angle\_pid\_target(0 \- i) > 34 time.sleep\_ms(100) > 35 time.sleep\_ms(2000) > 36 for i in range(20): > 37 module\_bala2\_0.set\_angle\_pid\_target(i \- 20) > 38 time.sleep\_ms(100) > 39 for i in range(20): > 40 module\_bala2\_0.set\_angle\_pid\_target(i) > 41 time.sleep\_ms(100) > 42 time.sleep\_ms(2000) > 43 for i in range(20): > 44 module\_bala2\_0.set\_angle\_pid\_target(20 \- i) > 45 time.sleep\_ms(100) > 46 module\_bala2\_0.set\_angle\_pid\_target(0) > 47 > 48 > 49def loop(): > 50 global title0, module\_bala2\_0, i > 51 M5.update() > 52 > 53 > 54if \_\_name\_\_ \== "\_\_main\_\_": > 55 try: > 56 setup() > 57 while True: > 58 loop() > 59 except (Exception, KeyboardInterrupt) as e: > 60 try: > 61 from utility import print\_error\_msg > 62 > 63 print\_error\_msg(e) > 64 except ImportError: > 65 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Bala2Module[](#bala2module "Link to this heading") _class_ module.bala2.Bala2Module(_timer\_id\=0_)[](#module.bala2.Bala2Module "Link to this definition") Create an Bala2Module object. Parameters: **timer\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Timer ID from 0 to 3 (Use a timer to periodically call the balance control program.) UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/init.png) MicroPython Code Block: > from module import Bala2Module > > module\_bala2\_0 \= Bala2Module(timer\_id \= 0) calibrate()[](#module.bala2.Bala2Module.calibrate "Link to this definition") Calibrate sensor UiFlow2 Code Block: > ![calibrate.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/calibrate.png) MicroPython Code Block: > module\_bala2\_0.calibrate() set\_motor\_speed(_left_, _right_)[](#module.bala2.Bala2Module.set_motor_speed "Link to this definition") Set motor speed Parameters: * **left** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The speed of the left motor. Range: -1023 ~ 1023. * **right** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The speed of the right motor. Range: -1023 ~ 1023. UiFlow2 Code Block: > ![set_motor_speed.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_motor_speed.png) MicroPython Code Block: > module\_bala2\_0.set\_motor\_speed(left, right) set\_encoder\_value(_left_, _right_)[](#module.bala2.Bala2Module.set_encoder_value "Link to this definition") Set encoder value Parameters: * **left** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value of the left encoder. Range: -2^31 ~ 2^31. * **right** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value of the right encoder. Range: -2^31 ~ 2^31. UiFlow2 Code Block: > ![set_encoder_value.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_encoder_value.png) MicroPython Code Block: > module\_bala2\_0.set\_encoder\_value(left, right) get\_encoder\_value()[](#module.bala2.Bala2Module.get_encoder_value "Link to this definition") The left, right encoder value returned in a 2-tuple Returns: left, right encoder value Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_encoder_value.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_encoder_value.png) MicroPython Code Block: > module\_bala2\_0.get\_encoder\_value() set\_servo\_angle(_pos_, _angle_)[](#module.bala2.Bala2Module.set_servo_angle "Link to this definition") Set servo angle Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The position of the output cahnnel. Range: 1 ~ 4. * **angle** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value of the right encoder. Range: 0 ~ 180. UiFlow2 Code Block: > ![set_servo_angle.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_servo_angle.png) MicroPython Code Block: > module\_bala2\_0.set\_servo\_angle(pos, angle) start()[](#module.bala2.Bala2Module.start "Link to this definition") Start the balance car (car upright balance) UiFlow2 Code Block: > ![start.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/start.png) MicroPython Code Block: > module\_bala2\_0.start() stop()[](#module.bala2.Bala2Module.stop "Link to this definition") Stop the balance car (stop the balance control of the car) UiFlow2 Code Block: > ![stop.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/stop.png) MicroPython Code Block: > module\_bala2\_0.stop() get\_angle()[](#module.bala2.Bala2Module.get_angle "Link to this definition") Get the tilt angle of the balance car Returns: The angle of the car Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") Data is valid only when the car is running (start() is called). UiFlow2 Code Block: > ![get_angle.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_angle.png) MicroPython Code Block: > module\_bala2\_0.get\_angle() set\_angle\_pid(_kp_, _ki_, _kd_)[](#module.bala2.Bala2Module.set_angle_pid "Link to this definition") Set angle PID parameters Parameters: * **kp** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Proportional gain * **ki** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Integral gain * **kd** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Derivative gain UiFlow2 Code Block: > ![set_angle_pid.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_angle_pid.png) MicroPython Code Block: > module\_bala2\_0.set\_angle\_pid(kp, ki, kd) get\_angle\_pid()[](#module.bala2.Bala2Module.get_angle_pid "Link to this definition") The angle loop PID parameters returned in a 3-tuple Returns: kp, ki, kd parameters Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_angle_pid.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_angle_pid.png) MicroPython Code Block: > module\_bala2\_0.get\_angle\_pid() set\_angle\_pid\_target(_angle\=0_)[](#module.bala2.Bala2Module.set_angle_pid_target "Link to this definition") Set angle loop PID control target. Parameters: **angle** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The angle of the angle loop PID control target. Default is 0. UiFlow2 Code Block: > ![set_angle_pid_target.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_angle_pid_target.png) MicroPython Code Block: > module\_bala2\_0.set\_angle\_pid\_target(angle) get\_angle\_pid\_target()[](#module.bala2.Bala2Module.get_angle_pid_target "Link to this definition") Get angle loop PID control target Returns: The angle loop PID control target Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_angle_pid_target.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_angle_pid_target.png) MicroPython Code Block: > module\_bala2\_0.get\_angle\_pid\_target() set\_speed\_pid(_kp_, _ki_, _kd_)[](#module.bala2.Bala2Module.set_speed_pid "Link to this definition") Set speed loop PID parameters. Parameters: * **kp** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Proportional gain * **ki** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Integral gain * **kd** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Derivative gain UiFlow2 Code Block: > ![set_speed_pid.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_speed_pid.png) MicroPython Code Block: > module\_bala2\_0.set\_speed\_pid(kp, ki, kd) get\_speed\_pid()[](#module.bala2.Bala2Module.get_speed_pid "Link to this definition") The speed loop PID parameters returned in a 3-tuple Returns: kp, ki, kd parameters Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_speed_pid.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_speed_pid.png",) MicroPython Code Block: > module\_bala2\_0.get\_speed\_pid() set\_speed\_pid\_target(_speed\=0_)[](#module.bala2.Bala2Module.set_speed_pid_target "Link to this definition") Set speed loop PID control target. Parameters: **speed** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The speed of the speed loop PID control target. Default is 0. UiFlow2 Code Block: > ![set_speed_pid_target.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_speed_pid_target.png) MicroPython Code Block: > module\_bala2\_0.set\_speed\_pid\_target(speed) get\_speed\_pid\_target()[](#module.bala2.Bala2Module.get_speed_pid_target "Link to this definition") Get speed loop PID control target Returns: The speed loop PID control target Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_speed_pid_target.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/get_speed_pid_target.png) MicroPython Code Block: > module\_bala2\_0.get\_speed\_pid\_target() set\_turn\_speed(_speed_)[](#module.bala2.Bala2Module.set_turn_speed "Link to this definition") Set turning speed Parameters: **speed** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The speed of the left and right motor offset UiFlow2 Code Block: > ![set_turn_speed.png](https://static-cdn.m5stack.com/mpy_docs/module/bala2/set_turn_speed.png) MicroPython Code Block: > module\_bala2\_0.set\_turn\_speed(speed) --- # Paper — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * Paper * [View page source](../_sources/controllers/paper.rst.txt) * * * Paper[](#paper "Link to this heading") ======================================== UI[](#ui "Link to this heading") ---------------------------------- M5Paper features touch panel, allowing you to directly tap on the tabs on the right side to switch to application. ![flow.png](../_images/flow.png) In the CODE page, you can see your device’s UIFlow mode, MAC address, and account information. You can also confirm the connection status of WiFi and the server at the bottom left corner. ![config.png](../_images/config.png) In the SETTING page, you can view your WiFi and server configuration. ![applist.png](../_images/applist2.png) In the APPLIST page, you can directly tap on the file name and then tap the run button to execute the code. --- # Commu Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Commu Module * [View page source](../_sources/module/commu.rst.txt) * * * Commu Module[](#commu-module "Link to this heading") ====================================================== This is the driver library for the module Commu for receiving and sending CAN / RS485 / I2C data. Support the following products: > [![commu](https://static-cdn.m5stack.com/resource/docs/products/module/commu/commu_01.webp)](https://docs.m5stack.com/en/module/commu) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### CAN, RS485, I2C communication[](#can-rs485-i2c-communication "Link to this heading") Open the [commu\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/commu/commu_core2_example.m5f2) project in UiFlow2. This example shows how to receive and send data using the Commu Module. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/commu/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### CAN, RS485, I2C communication[](#id1 "Link to this heading") This example shows how to receive and send data using the Commu Module. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import CommuModuleCAN > 9from module import CommuModuleRS485 > 10from module import CommuModuleI2C > 11from hardware import Pin > 12 > 13 > 14title0 \= None > 15label0 \= None > 16label1 \= None > 17label2 \= None > 18commu\_0 \= None > 19commu\_1 \= None > 20commu\_2 \= None > 21 > 22 > 23def setup(): > 24 global title0, label0, label1, label2, commu\_0, commu\_1, commu\_2 > 25 > 26 M5.begin() > 27 Widgets.fillScreen(0x222222) > 28 title0 \= Widgets.Title( > 29 "COMMUModule Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 30 ) > 31 label0 \= Widgets.Label("CAN Rec:", 1, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 32 label1 \= Widgets.Label("RS485 Rec:", 1, 121, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 33 label2 \= Widgets.Label("I2C List:", 1, 166, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 34 > 35 commu\_0 \= CommuModuleCAN(0x00, baudrate\=16) > 36 commu\_1 \= CommuModuleRS485(2, baudrate\=115200, bits\=8, parity\=None, stop\=1, tx\=14, rx\=13) > 37 commu\_2 \= CommuModuleI2C(0, scl\=Pin(22), sda\=Pin(21), freq\=100000) > 38 > 39 > 40def loop(): > 41 global title0, label0, label1, label2, commu\_0, commu\_1, commu\_2 > 42 M5.update() > 43 if commu\_0.any(): > 44 label0.setText(str((str("CAN Rec:") + str((commu\_0.recv()))))) > 45 if BtnA.isPressed(): > 46 commu\_0.send("uiflow2", 0, extframe\=False) > 47 elif BtnB.isPressed(): > 48 label2.setText(str((str("I2C List:") + str((commu\_2.scan()))))) > 49 if commu\_1.any(): > 50 label1.setText(str((str("RS485 Rec:") + str((commu\_1.read()))))) > 51 > 52 > 53if \_\_name\_\_ \== "\_\_main\_\_": > 54 try: > 55 setup() > 56 while True: > 57 loop() > 58 except (Exception, KeyboardInterrupt) as e: > 59 try: > 60 from utility import print\_error\_msg > 61 > 62 print\_error\_msg(e) > 63 except ImportError: > 64 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### CommuModule[](#commumodule "Link to this heading") _class_ module.commu.CommuModuleCAN(_mode\=0_, _baudrate\=16_, _spi\_baud\=8000000_, _canIDMode\=0_, _debug\=False_)[](#module.commu.CommuModuleCAN "Link to this definition") Bases: `MCP2515_CAN` Create an CommuModuleCAN object Parameters: * **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The CAN mode to use(NORMAL, LISTEN\_ONLY), Default is NORMAL. Options: * `NORMAL`: Normal mode * `LISTEN_ONLY`: Listen only mode * **baudrate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The baudrate to use, Default is CAN\_1000KBPS. Options: * `CAN_5KBPS`: 5Kbps * `CAN_10KBPS`: 10Kbps * `CAN_20KBPS`: 20Kbps * `CAN_31K25BPS`: 31.25Kbps * `CAN_33KBPS`: 33Kbps * `CAN_40KBPS`: 40Kbps * `CAN_50KBPS`: 50Kbps * `CAN_80KBPS`: 80Kbps * `CAN_83K3BPS`: 83.33Kbps * `CAN_95KBPS`: 95Kbps * `CAN_100KBPS`: 100Kbps * `CAN_125KBPS`: 125Kbps * `CAN_200KBPS`: 200Kbps * `CAN_250KBPS`: 250Kbps * `CAN_500KBPS`: 500Kbps * `CAN_1000KBPS`: 1Mbps * **spi\_baud** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SPI baudrate to use, Default is 8000000. * **canIDMode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The CAN ID mode to use(MCP\_STDEXT, MCP\_EXTDONLY), Default is MCP\_STDEXT. Options: * `MCP_STDEXT`: Standard and Extended * `MCP_EXTDONLY`: Extended only * **debug** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to enable debug mode, Default is False. UiFlow2 Code Block: > ![init.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/init.png) MicroPython Code Block: > from module import CommuModuleCAN > > commu \= CommuModuleCAN(CommuModule.NORMAL, baudrate\=16) any()[](#module.commu.CommuModuleCAN.any "Link to this definition") Check if any message is available. Returns: The current message availability. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![any.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/any.png) MicroPython Code Block: > commu.any() info()[](#module.commu.CommuModuleCAN.info "Link to this definition") Get the state of error information. Returns: The current error information. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![info.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/info.png) MicroPython Code Block: > commu.info() recv(_fifo\=0_, _list\=None_, _timeout\=5000_)[](#module.commu.CommuModuleCAN.recv "Link to this definition") Read a message from the CAN bus. Parameters: * **fifo** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The fifo is an integer, it can be any number and compatible with Pyb.CAN * **list** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") ) – list is an optional list object to be used as the return value. * **timeout** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – timeout is the timeout in milliseconds to wait for the receive. Returns: Tuple containing (can\_id, is\_extended, is\_rtr, fmi, data) Return type: tuple * The id of the message. * A boolean that indicates if the message ID is standard or extended. * A boolean that indicates if the message is an RTR message. * The FMI (Filter Match Index) value. * An array containing the data. UiFlow2 Code Block: > ![recv_message.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/recv_message.png) > > ![recv_message_into.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/recv_message_into.png) MicroPython Code Block: > commu.recv(0) > > buf \= bytearray(8) > lst \= \[0, 0, 0, 0, memoryview(buf)\] > \# No heap memory is allocated in the following call > commu.recv(0, lst) send(_data_, _can\_id_, _extframe\=False_)[](#module.commu.CommuModuleCAN.send "Link to this definition") Send a message to the CAN bus. Parameters: * **data** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The message data. * **can\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The CAN ID. * **extframe** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to use extended frame format. Returns: The message data. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![send.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/module/commu/send.png) MicroPython Code Block: > commu.send('uiflow2', 0, extframe\=False) _class_ module.commu.CommuModuleRS485(_id_, _\*\*kwargs_)[](#module.commu.CommuModuleRS485 "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") The CommuModuleRS485 class wraps an instance of the UART class. For more details, see [hardware.UART](../hardware/uart.html#hardware-uart) . _class_ module.commu.CommuModuleI2C(_id_, _\*\*kwargs_)[](#module.commu.CommuModuleI2C "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") The CommuModuleI2C class wraps an instance of the I2C class. For more details, see [machine.I2C](https://docs.micropython.org/en/v1.22.0/library/machine.I2C.html#machine-i2c "(in MicroPython vv1.22.0)") . – a two-wire serial protocol. --- # camera — UIFlow2 Programming Guide master documentation * [](../index.html) * [Advanced](index.html) * camera * [View page source](../_sources/advanced/camera.rst.txt) * * * camera[](#camera "Link to this heading") ========================================== The camera module is used for taking pictures. Note This module is only applicable to the CoreS3 Controller Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### capture display[](#capture-display "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8 > 9 > 10img \= None > 11 > 12 > 13def setup(): > 14 global img > 15 M5.begin() > 16 Widgets.fillScreen(0x222222) > 17 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 18 > 19 > 20def loop(): > 21 global img > 22 M5.update() > 23 img \= camera.snapshot() > 24 M5.Lcd.show(img, 0, 0, 320, 240) > 25 > 26 > 27if \_\_name\_\_ \== "\_\_main\_\_": > 28 try: > 29 setup() > 30 while True: > 31 loop() > 32 except (Exception, KeyboardInterrupt) as e: > 33 try: > 34 from utility import print\_error\_msg > 35 > 36 print\_error\_msg(e) > 37 except ImportError: > 38 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### capture display[](#id1 "Link to this heading") > ![camera_display_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera_display_example.png) [cores3\_example\_camera\_display.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/camera/cores3_example_camera_display.m5f2) Functions[](#functions "Link to this heading") ------------------------------------------------ camera.init(_pixformat_, _framesize_)[](#camera.camera.init "Link to this definition") Initializes the camera sensor. The `pixformat` supports: * `camera.RGB565` The `framesize` supports: * `camera.QQVGA`: 160x120 * `camera.QCIF`: 176x144 * `camera.HQVGA`: 240x176 * `camera.FRAME_240X240`: 240x240 * `camera.QVGA`: 320x240 UIFlow2.0 > ![init.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/init.png) camera.snapshot() → image.Iamge[](#camera.camera.snapshot "Link to this definition") Capture a single frame. Returns An `image.Image` object. UIFlow2.0 > ![snapshot.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/snapshot.png) camera.set\_hmirror(_enable_)[](#camera.camera.set_hmirror "Link to this definition") Turns horizontal mirror mode on (True) or off (False). Defaults to on. UIFlow2.0 > ![set_hmirror.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/set_hmirror.png) camera.set\_vflip(_enable_)[](#camera.camera.set_vflip "Link to this definition") Turns vertical flip mode on (True) or off (False). Defaults to off. UIFlow2.0 > ![set_vflip.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/set_vflip.png) camera.get\_hmirror()[](#camera.camera.get_hmirror "Link to this definition") Returns if horizontal mirror mode is enabled. UIFlow2.0 > ![get_hmirror.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/get_hmirror.png) camera.get\_vflip()[](#camera.camera.get_vflip "Link to this definition") Returns if vertical flip mode is enabled. UIFlow2.0 > ![get_vflip.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/camera/get_vflip.png) --- # API Documentation Template — UIFlow2 Programming Guide master documentation * [](../index.html) * [Contributions Guide](index.html) * API Documentation Template * [View page source](../_sources/contribute/template.rst.txt) * * * API Documentation Template[](#api-documentation-template "Link to this heading") ================================================================================== Note 1. Please follow the template below to write your API documentation; 2. Strict use of reStructuredText syntax; 3. Write strictly according to the various tags of the template 4. When you are finished, delete all instructions (similar to this one) and any extra header information. Support the following products: > | | | > | --- | --- | > | xxx Unit | xxx Unit | Below is the detailed support for Speaker on the host: | Controller | Atomic Echo Base | | --- | --- | | Atom Echo | ⭕ | | Atom Lite | ✅ | * ✅: Supported. * ⭕: Optional, It conflicts with some internal resource of the host. UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ Note Prepare one or more examples that fully demonstrate the functionality of the API. Delete this part of the description when you are done. ### Example1[](#example1 "Link to this heading") MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Example1[](#id1 "Link to this heading") API[](#api "Link to this heading") ------------------------------------ ### Function[](#function "Link to this heading") func1(_arg1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _arg2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#func1 "Link to this definition") Function 1, please write a detailed description of the function. Parameters: * **arg1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 1. * **arg2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 2. Returns: Return value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: MicroPython Code Block: > pass \# Please put the MicroPython code of the function, and delete this line when you are done ### Class1[](#class1 "Link to this heading") _class_ Class1(_arg1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Class1 "Link to this definition") Constructor. Parameters: **arg1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 1. method1(_arg1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _arg2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Class1.method1 "Link to this definition") Method 1, please write a detailed description of the method. Parameters: * **arg1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 1. * **arg2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 2. Returns: Return value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: MicroPython Code Block: > pass \# Please put the MicroPython code of the function, and delete this line when you are done. _property_ property1_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#Class1.property1 "Link to this definition") Property 1, please write a detailed description of the property. UiFlow2 Code Block: MicroPython Code Block: > pass \# Please put the MicroPython code of the function, and delete this line when you are done. _static_ staticmethod1(_arg1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _arg2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Class1.staticmethod1 "Link to this definition") Static method 1, please write a detailed description of the static method. Parameters: * **arg1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 1. * **arg2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 2. Returns: Return value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: MicroPython Code Block: > pass \# Please put the MicroPython code of the function, and delete this line when you are done. _classmethod_ classmethod1(_arg1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _arg2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Class1.classmethod1 "Link to this definition") Class method 1, please write a detailed description of the class method. Parameters: * **arg1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 1. * **arg2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Parameter 2. Returns: Return value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: MicroPython Code Block: > pass \# Please put the MicroPython code of the function, and delete this line when you are done. b_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#Class1.b "Link to this definition") > Attribute b, please write a detailed description of the attribute. > > UiFlow2 Code Block: > > MicroPython Code Block: > > > pass \# Please put the MicroPython code of the function, and delete this line when you are done. CONSTANT1_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#Class1.CONSTANT1 "Link to this definition") > Constant 1, Please write a detailed description of the constant. Constants are named using uppercase letters. > > UiFlow2 Code Block: > > MicroPython Code Block: > > > pass \# Please put the MicroPython code of the function, and delete this line when you are done. ### Class2[](#class2 "Link to this heading") _class_ Class2[](#Class2 "Link to this definition") Constructor. --- # DinMeter — UIFlow2 Programming Guide master documentation * [](../index.html) * [Controllers](index.html) * DinMeter * [View page source](../_sources/controllers/dinmeter.rst.txt) * * * DinMeter[](#dinmeter "Link to this heading") ============================================== Startup UI[](#startup-ui "Link to this heading") -------------------------------------------------- Note 1. `ENCODER` is used for menu selection. 2. `BtnA` is used to execute menu items. 3. Long press `BtnA` to exit the application. 4. `CardKB Unit` is used for input. ### Launcher[](#launcher "Link to this heading") ![launcher.png](../_images/launcher1.png) `ENCODER` cycles through available applications. `BtnA` click to launch the selected application. ### Setting[](#setting "Link to this heading") ![setting.png](../_images/setting1.png) `ENCODER` cycles through available applications. `BtnA` click to launch the selected application. Long press `BtnA` to exit the application. #### WLAN[](#wlan "Link to this heading") ![wlan.png](../_images/wlan1.png) `ENCODER` selects the corresponding input box or button. `BtnA` click to perform the corresponding action. Long press `BtnA` to exit the application. #### General[](#general "Link to this heading") ![general.png](../_images/general1.png) `ENCODER` selects menu. `BtnA` click to set. Long press `BtnA` to exit the application. ### Develop[](#develop "Link to this heading") ![develop.png](../_images/develop1.png) Long press `BtnA` to exit the application. ### APP.RUN[](#app-run "Link to this heading") ![apprun.png](../_images/apprun1.png) `ENCODER` selects the corresponding action. `BtnA` click to run main.py according to the corresponding action. Long press `BtnA` to exit the application. ### APP.LIST[](#app-list "Link to this heading") ![applist.png](../_images/applist1.png) `ENCODER` cycles through available applications. `BtnA` click to run the application once. Double click `BtnA` to always run the application. Long press `BtnA` to exit the application. --- # DAC2 Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * DAC2 Hat * [View page source](../_sources/hats/dac2.rst.txt) * * * DAC2 Hat[](#dac2-hat "Link to this heading") ============================================== The following products are supported: > [![DAC2Hat](https://static-cdn.m5stack.com/resource/docs/products/hat/Hat-DAC2/img-26204d9b-195c-4c62-afbb-5b3232c09381.webp)](https://docs.m5stack.com/en/hat/Hat-DAC2) 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/dac2/example.png) [stickc\_plus2\_dac2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/dac2/stickc_plus2_dac2_example.m5f2) class DAC2Hat[](#class-dac2hat "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ DAC2Hat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x59_)[](#DAC2Hat "Link to this definition") Create a DAC2 Hat object. Parameters: * **i2c** – I2C object * **address** – I2C address of the DAC2 Hat UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/dac2/init.png) DAC2Hat class inherits DAC2Unit class, See [unit.DAC2Unit.Methods](../units/dac2.html#unit-dac2unit-methods) for more details. --- # DLight Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * DLight Hat * [View page source](../_sources/hats/dlight.rst.txt) * * * DLight Hat[](#dlight-hat "Link to this heading") ================================================== The following products are supported: > [![DLightHAT](https://static-cdn.m5stack.com/resource/docs/products/hat/hat_dlight/hat_dlight_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat_dlight) 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 hat import DLightHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_dlight\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, hat\_dlight\_0 > 19 > 20 M5.begin() > 21 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 24 hat\_dlight\_0 \= DLightHat(i2c0) > 25 hat\_dlight\_0.configure(hat\_dlight\_0.CONTINUOUSLY, hat\_dlight\_0.H\_RESOLUTION\_MODE) > 26 > 27 > 28def loop(): > 29 global label0, i2c0, hat\_dlight\_0 > 30 M5.update() > 31 label0.setText(str(hat\_dlight\_0.get\_lux())) > 32 > 33 > 34if \_\_name\_\_ \== "\_\_main\_\_": > 35 try: > 36 setup() > 37 while True: > 38 loop() > 39 except (Exception, KeyboardInterrupt) as e: > 40 try: > 41 from utility import print\_error\_msg > 42 > 43 print\_error\_msg(e) > 44 except ImportError: > 45 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/dlight/example.png) [stickc\_plus2\_dlight\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/dlight/stickc_plus2_dlight_example.m5f2) class DLightHat[](#class-dlighthat "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ DLightHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x23_)[](#DLightHat "Link to this definition") Create a DLightHat object. Parameters: * **i2c** – I2C object * **address** – the I2C address of the device. Default is 0x23. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/dlight/init.png) DLightHat class inherits DLightUnit class, See [unit.DLightUnit.Methods](../units/dlight.html#unit-dlightunit-methods) for more details. --- # Display Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Display Module * [View page source](../_sources/module/display.rst.txt) * * * Display Module[](#display-module "Link to this heading") ========================================================== Display Module 13.2 is an expansion module for HD audio and video, using GAOYUN GW1NR series FPGA chip to output display signals, and employing the LT8618S chip for signal output conditioning. Support the following products: > [![DisplayModule](https://static-cdn.m5stack.com/resource/docs/products/module/Display%20Module%2013.2/img-cec9dc43-a087-44da-a219-831f70b19314.webp)](https://docs.m5stack.com/en/module/Display%20Module%2013.2) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Draw Text[](#draw-text "Link to this heading") Open the [cores3\_display\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/display/cores3_display_example.m5f2) project in UiFlow2. This example displays the text “Display” on the screen. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/display/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- This example displays the text “Display” on the screen. MicroPython Code Block: > 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 module import DisplayModule > 9 > 10 > 11label0 \= None > 12label1 \= None > 13module\_display \= None > 14 > 15 > 16def setup(): > 17 global label0, label1, module\_display > 18 > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 label0 \= Widgets.Label("CoreS3", 127, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 module\_display \= DisplayModule( > 24 width\=1280, > 25 height\=720, > 26 output\_width\=1280, > 27 output\_height\=720, > 28 refresh\_rate\=60, > 29 pixel\_clock\=74250000, > 30 scale\_w\=1, > 31 scale\_h\=1, > 32 ) > 33 label1 \= Widgets.Label( > 34 "Display", 506, 318, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu72, module\_display > 35 ) > 36 > 37 > 38def loop(): > 39 global label0, label1, module\_display > 40 M5.update() > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Class DisplayModule[](#class-displaymodule "Link to this heading") _class_ module.display.DisplayModule(_width\=1280_, _height\=720_, _refresh\_rate\=60_, _output\_width\=1280_, _output\_height\=720_, _scale\_w\=1_, _scale\_h\=1_, _pixel\_clock\=74250000_)[](#module.display.DisplayModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Initialize the Display Module. Parameters: * **width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The logical width of the Display Module. Default is 1280px. * **height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The logical height of the Display Module. Default is 720px. * **refresh\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The refresh rate of the Display Module. Default is 60Hz. * **output\_width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The width of the output of the Display Module. Default is 1280px. * **output\_height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The height of the output of the Display Module. Default is 720px. * **scale\_w** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The scale width of the Display Module. Default is 1. * **scale\_h** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The scale height of the Display Module. Default is 1. * **pixel\_clock** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The pixel clock of the Display Module. Default is 74250000. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/display/init.png) MicroPython Code Block: > from module import DisplayModule > module\_display \= DisplayModule(1280, 720, 60, 1280, 720, 1, 1, 74250000) DisplayModule class inherits Display class, See [hardware.Display](../hardware/display.html#hardware-display) for more details. --- # code_scanner — UIFlow2 Programming Guide master documentation * [](../index.html) * [Advanced](index.html) * code\_scanner * [View page source](../_sources/advanced/code_scanner.rst.txt) * * * code\_scanner[](#code-scanner "Link to this heading") ======================================================= Note This module is only applicable to the CoreS3 Controller `code_scanner` module for qrcode scanning recognition Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### qrcode detect[](#qrcode-detect "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8import code\_scanner > 9import image > 10 > 11 > 12img \= None > 13qrcode \= None > 14 > 15 > 16def setup(): > 17 global img, qrcode > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 21 camera.set\_hmirror(False) > 22 > 23 > 24def loop(): > 25 global img, qrcode > 26 M5.update() > 27 img \= camera.snapshot() > 28 qrcode \= code\_scanner.find\_qrcodes(img) > 29 if qrcode: > 30 print(qrcode.payload()) > 31 print(qrcode.type\_name()) > 32 img.draw\_string(10, 10, str(qrcode.payload()), color\=0x3333FF, scale\=2) > 33 M5.Lcd.show(img, 0, 0, 320, 240) > 34 > 35 > 36if \_\_name\_\_ \== "\_\_main\_\_": > 37 try: > 38 setup() > 39 while True: > 40 loop() > 41 except (Exception, KeyboardInterrupt) as e: > 42 try: > 43 from utility import print\_error\_msg > 44 > 45 print\_error\_msg(e) > 46 except ImportError: > 47 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### qrcode detect[](#id1 "Link to this heading") > ![qrcode_detect_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/qrcode_detect_example.png) [qrcode\_detect\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/camera/qrcode_detect_example.m5f2) Methods[](#methods "Link to this heading") -------------------------------------------- code\_scanner.find\_qrcodes(_img: image.Image_) → image.qrcode[](#code_scanner.find_qrcodes "Link to this definition") QR code recognition * `img` Image to be recognized Returns `image.qrcode` instance UIFlow2.0 > ![find_qrcodes.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/code_scanner/find_qrcodes.png) class image.QRCode[](#class-image-qrcode "Link to this heading") ------------------------------------------------------------------ `QRCode` The QRCode object is returned by code\_scanner.find\_qrcodes(img: image.Image). code\_scanner.payload() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#code_scanner.payload "Link to this definition") Return the payload string of the QR code UIFlow2.0 > ![payload.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/code_scanner/payload.png) code\_scanner.type\_name() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#code_scanner.type_name "Link to this definition") Return the type of the QR code UIFlow2.0 > ![type_name.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/code_scanner/type_name.png) --- # DMX512 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * DMX512 Module * [View page source](../_sources/module/dmx.rst.txt) * * * DMX512 Module[](#dmx512-module "Link to this heading") ======================================================== DMX-Base is a functional base specially designed for DMX-512 data transmission scenarios, communicating and enabling control with M5 host through serial port, equipped with XLR-5 and XLR-3 male and female interfaces, convenient for users to connect DMX devices with different interfaces, in addition, the module has HT3.96 pitch 485 interface to facilitate connection to Expansion 485 devices. Support the following products: [![dmx](https://static-cdn.m5stack.com/resource/docs/products/module/DMX_Base/img-3ff79a98-9198-428f-a4ea-f50c58d834d1.webp)](https://docs.m5stack.com/en/module/DMX_Base) Micropython Example Send Data: > 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 module import DMX512Module > 9import time > 10 > 11 > 12Title \= None > 13label1 \= None > 14label0 \= None > 15module\_dmx\_0 \= None > 16 > 17 > 18ch\_data \= None > 19 > 20 > 21def setup(): > 22 global Title, label1, label0, module\_dmx\_0, ch\_data > 23 > 24 M5.begin() > 25 Widgets.fillScreen(0x222222) > 26 Title \= Widgets.Title( > 27 "DMX512Module Send example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 28 ) > 29 label1 \= Widgets.Label("Not Sent", 2, 129, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 label0 \= Widgets.Label( > 31 "Not initialized", 2, 76, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 32 ) > 33 > 34 module\_dmx\_0 \= DMX512Module(2, mode\=1) > 35 ch\_data \= 0 > 36 label0.setText(str("Initialized")) > 37 > 38 > 39def loop(): > 40 global Title, label1, label0, module\_dmx\_0, ch\_data > 41 M5.update() > 42 label1.setText(str("Not Sent")) > 43 ch\_data \= ch\_data + 1 > 44 if ch\_data \>= 255: > 45 ch\_data \= 0 > 46 module\_dmx\_0.write\_data(1, ch\_data) > 47 module\_dmx\_0.write\_data(2, ch\_data) > 48 module\_dmx\_0.write\_data(3, ch\_data) > 49 label1.setText(str("Sent")) > 50 time.sleep(0.7) > 51 > 52 > 53if \_\_name\_\_ \== "\_\_main\_\_": > 54 try: > 55 setup() > 56 while True: > 57 loop() > 58 except (Exception, KeyboardInterrupt) as e: > 59 try: > 60 from utility import print\_error\_msg > 61 > 62 print\_error\_msg(e) > 63 except ImportError: > 64 print("please update to latest firmware") Micropython Example Receive Data: > 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 module import DMX512Module > 9 > 10 > 11Title \= None > 12label0 \= None > 13label1 \= None > 14module\_dmx\_0 \= None > 15 > 16 > 17dmx\_data \= None > 18dmx\_data2 \= None > 19 > 20 > 21def module\_dmx\_0\_channel1\_receive\_event(received\_data): > 22 global Title, label0, label1, module\_dmx\_0, dmx\_data, dmx\_data2 > 23 dmx\_data \= received\_data > 24 label0.setText(str((str("Channel 1:") + str(dmx\_data)))) > 25 > 26 > 27def module\_dmx\_0\_channel2\_receive\_event(received\_data): > 28 global Title, label0, label1, module\_dmx\_0, dmx\_data, dmx\_data2 > 29 dmx\_data2 \= received\_data > 30 label1.setText(str((str("Channel 2:") + str(dmx\_data2)))) > 31 > 32 > 33def setup(): > 34 global Title, label0, label1, module\_dmx\_0, dmx\_data, dmx\_data2 > 35 > 36 M5.begin() > 37 Widgets.fillScreen(0x222222) > 38 Title \= Widgets.Title( > 39 "DMX512Module Rec example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 40 ) > 41 label0 \= Widgets.Label("Channel 1:", 0, 82, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 42 label1 \= Widgets.Label("Channel 2:", 0, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 43 > 44 module\_dmx\_0 \= DMX512Module(1, mode\=2) > 45 module\_dmx\_0.attach\_channel(1, module\_dmx\_0\_channel1\_receive\_event) > 46 module\_dmx\_0.attach\_channel(2, module\_dmx\_0\_channel2\_receive\_event) > 47 module\_dmx\_0.receive\_none\_block() > 48 > 49 > 50def loop(): > 51 global Title, label0, label1, module\_dmx\_0, dmx\_data, dmx\_data2 > 52 M5.update() > 53 > 54 > 55if \_\_name\_\_ \== "\_\_main\_\_": > 56 try: > 57 setup() > 58 while True: > 59 loop() > 60 except (Exception, KeyboardInterrupt) as e: > 61 try: > 62 from utility import print\_error\_msg > 63 > 64 print\_error\_msg(e) > 65 except ImportError: > 66 print("please update to latest firmware") UIFLOW2 Master Example: > ![tx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/send_example.png) UIFLOW2 Slave Example: > ![rx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/receive_example.png) [dmx512\_core2\_send\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/dmx/dmx512_core2_send_example.m5f2) [dmx512\_core2\_receive\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/dmx/dmx512_core2_receive_example.m5f2) class DMX512Module[](#class-dmx512module "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ DMX512Module(_id_, _mode\=DMX\_MASTER_)[](#DMX512Module "Link to this definition") Initializes the DMX512 module with a specified UART ID and port pins. Parameters: * **id** (_Literal__\[__0__,__1__,__2__\]_) – UART device ID(DMX port id). * **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Operating mode (1 for Master, 2 for Slave). UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- DMX512Module.dmx\_init(_mode_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.dmx_init "Link to this definition") Initializes the DMX512 communication with UART pins and mode. Parameters: **mode** – Operating mode (1 for Master, 2 for Slave). UIFLOW2: > ![dmx_init.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/dmx_init.png) DMX512Module.deinit() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.deinit "Link to this definition") Deinitializes the DMX512 module and stops any ongoing operations. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/deinit.png) DMX512Module.write\_data(_channel_, _data_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.write_data "Link to this definition") Updates the data for a specified DMX channel. Data is sent on the next update cycle. Parameters: * **channel** – DMX channel number (1-512). * **data** – Data value to be sent (0-255). @raises ValueError if the channel number is out of range. UIFLOW2: > ![write_data.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/write_data.png) DMX512Module.clear\_buffer() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.clear_buffer "Link to this definition") Clears the DMX buffer and resets the data. UIFLOW2: > ![clear_buffer.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/clear_buffer.png) DMX512Module.read\_data(_channel_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#DMX512Module.read_data "Link to this definition") Reads data from a specified DMX channel in Slave mode. Parameters: **channel** – DMX channel number (1-512). UIFLOW2: > ![read_data.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/read_data.png) DMX512.receive\_none\_block() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") Starts non-blocking data reception for the specified channels with associated callbacks. UIFLOW2: > ![receive_none_block.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/receive_none_block.png) DMX512Module.attach\_channel(_channel_, _callback_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.attach_channel "Link to this definition") Attaches a callback function to a specified DMX channel. Parameters: * **channel** – DMX channel number (1-512) to attach the callback to. * **callback** – The function to be called when data changes on the specified channel. UIFLOW2: > ![receive_data_event.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/receive_event.png) DMX512.stop\_receive() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") Stops the non-blocking data reception task. UIFLOW2: > ![stop_receive.png](https://static-cdn.m5stack.com/mpy_docs/module/dmx/stop_receive.png) DMX512Module.detach\_channel(_channel_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DMX512Module.detach_channel "Link to this definition") Detaches the callback function from a specified DMX channel. Parameters: **channel** – DMX channel number (1-512) to detach the callback from. --- # ENV Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * ENV Hat * [View page source](../_sources/hats/env.rst.txt) * * * ENV Hat[](#env-hat "Link to this heading") ============================================ The following products are supported: > | | | > | --- | --- | > | [![ENV II](https://static-cdn.m5stack.com/resource/docs/products/hat/hat_envII/hat_envII_01.webp)](https://docs.m5stack.com/en/hat/hat_envII) | [![ENV III](https://static-cdn.m5stack.com/resource/docs/products/hat/hat_envIII/hat_envIII_01.webp)](https://docs.m5stack.com/en/hat/hat_envIII) | 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 hat import ENVHat > 10 > 11 > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15i2c0 \= None > 16hat\_env3\_0 \= None > 17 > 18 > 19def setup(): > 20 global label0, label1, label2, i2c0, hat\_env3\_0 > 21 > 22 M5.begin() > 23 label0 \= Widgets.Label("label0", 9, 15, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 24 label1 \= Widgets.Label("label1", 9, 44, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 label2 \= Widgets.Label("label2", 9, 72, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 > 27 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 28 hat\_env3\_0 \= ENVHat(i2c0, type\=3) > 29 > 30 > 31def loop(): > 32 global label0, label1, label2, i2c0, hat\_env3\_0 > 33 M5.update() > 34 label0.setText(str(hat\_env3\_0.read\_temperature())) > 35 label1.setText(str(hat\_env3\_0.read\_pressure())) > 36 label2.setText(str(hat\_env3\_0.read\_humidity())) > 37 > 38 > 39if \_\_name\_\_ \== "\_\_main\_\_": > 40 try: > 41 setup() > 42 while True: > 43 loop() > 44 except (Exception, KeyboardInterrupt) as e: > 45 try: > 46 from utility import print\_error\_msg > 47 > 48 print\_error\_msg(e) > 49 except ImportError: > 50 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/env/example.png) [stickc\_plus2\_env\_hat\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/env/stickc_plus2_env_hat_example.m5f2) class ENVHat[](#class-envhat "Link to this heading") ------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ENVHat(_i2c: I2C | PAHUBHat_, _type: Literal\[1, 2, 3\]_)[](#ENVHat "Link to this definition") Create an ENVHat object. parameter is: > * `i2c` is an I2C object. > > * `type` is the type of ENVHat > > > * `1` - ENV > > > > * `2` - ENV II > > > > * `3` - ENV III > > > UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/env/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ENVHat.read\_temperature()[](#ENVHat.read_temperature "Link to this definition") This method allows to read the temperature value collected by ENV and returns a floating point value. The hat of measurement is °C. UIFLOW2: > ![read_temperature.png](https://static-cdn.m5stack.com/mpy_docs/hat/env/read_temperature.png) ENVHat.read\_humidity()[](#ENVHat.read_humidity "Link to this definition") This method allows to read the relative humidity value collected by ENV and returns a floating point value. The hat of measurement is %RH. UIFLOW2: > ![read_humidity.png](https://static-cdn.m5stack.com/mpy_docs/hat/env/read_humidity.png) ENVHat.read\_pressure()[](#ENVHat.read_pressure "Link to this definition") This method allows to read the atmospheric pressure collected by ENV and returns a floating point value. The hat of measurement is Pa. UIFLOW2: > ![read_pressure.png](https://static-cdn.m5stack.com/mpy_docs/hat/env/read_pressure.png) --- # dl — deep learning — UIFlow2 Programming Guide master documentation * [](../index.html) * [Advanced](index.html) * dl — deep learning * [View page source](../_sources/advanced/dl.rst.txt) * * * dl — deep learning[](#dl-deep-learning "Link to this heading") ================================================================ Note This module is only applicable to the CoreS3 Controller Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### human face detect[](#human-face-detect "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8import dl > 9import image > 10 > 11 > 12img \= None > 13detector \= None > 14detection\_result \= None > 15res \= None > 16kp \= None > 17 > 18 > 19def setup(): > 20 global img, detector, detection\_result, kp > 21 M5.begin() > 22 Widgets.fillScreen(0x222222) > 23 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 24 detector \= dl.ObjectDetector(dl.model.HUMAN\_FACE\_DETECT) > 25 > 26 > 27def loop(): > 28 global img, detector, detection\_result, kp > 29 M5.update() > 30 img \= camera.snapshot() > 31 detection\_result \= detector.infer(img) > 32 if detection\_result: > 33 for res in detection\_result: > 34 kp \= res.keypoint() > 35 img.draw\_circle(kp\[0\], kp\[1\], 3, color\=0x0000FF, thickness\=1, fill\=True) > 36 img.draw\_circle(kp\[2\], kp\[3\], 3, color\=0x00FF00, thickness\=1, fill\=True) > 37 img.draw\_circle(kp\[4\], kp\[5\], 3, color\=0xFF0000, thickness\=1, fill\=True) > 38 img.draw\_circle(kp\[6\], kp\[7\], 3, color\=0x0000FF, thickness\=1, fill\=True) > 39 img.draw\_circle(kp\[8\], kp\[9\], 3, color\=0x00FF00, thickness\=1, fill\=True) > 40 img.draw\_rectangle( > 41 res.x(), res.y(), res.w(), res.h(), color\=0x3366FF, thickness\=3, fill\=False > 42 ) > 43 M5.Lcd.show(img, 0, 0, 320, 240) > 44 > 45 > 46if \_\_name\_\_ \== "\_\_main\_\_": > 47 try: > 48 setup() > 49 while True: > 50 loop() > 51 except (Exception, KeyboardInterrupt) as e: > 52 try: > 53 from utility import print\_error\_msg > 54 > 55 print\_error\_msg(e) > 56 except ImportError: > 57 print("please update to latest firmware") ### pedestrain detect[](#pedestrain-detect "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8import dl > 9import image > 10 > 11 > 12img \= None > 13detector \= None > 14detection\_result \= None > 15res \= None > 16kp \= None > 17 > 18 > 19def setup(): > 20 global img, detector, detection\_result, kp > 21 M5.begin() > 22 Widgets.fillScreen(0x222222) > 23 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 24 detector \= dl.ObjectDetector(dl.model.PEDESTRIAN\_DETECT) > 25 > 26 > 27def loop(): > 28 global img, detector, detection\_result, kp > 29 M5.update() > 30 img \= camera.snapshot() > 31 detection\_result \= detector.infer(img) > 32 if detection\_result: > 33 for res in detection\_result: > 34 kp \= res.keypoint() > 35 img.draw\_rectangle( > 36 res.x(), res.y(), res.w(), res.h(), color\=0x3366FF, thickness\=3, fill\=False > 37 ) > 38 M5.Lcd.show(img, 0, 0, 320, 240) > 39 > 40 > 41if \_\_name\_\_ \== "\_\_main\_\_": > 42 try: > 43 setup() > 44 while True: > 45 loop() > 46 except (Exception, KeyboardInterrupt) as e: > 47 try: > 48 from utility import print\_error\_msg > 49 > 50 print\_error\_msg(e) > 51 except ImportError: > 52 print("please update to latest firmware") ### human face recognition[](#human-face-recognition "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from unit import DualButtonUnit > 8from hardware import \* > 9import camera > 10import dl > 11import image > 12 > 13 > 14dual\_button\_0\_blue \= None > 15dual\_button\_0\_red \= None > 16sys\_state \= None > 17FACE\_RECOGNIZE \= None > 18FACE\_ENROLL \= None > 19FACE\_DELETE \= None > 20detector \= None > 21img \= None > 22dl\_recognizer \= None > 23detection\_result \= None > 24IDLE \= None > 25res \= None > 26kp \= None > 27sys\_state\_prev \= None > 28frame\_count \= None > 29dl\_recognize\_result \= None > 30 > 31 > 32def dual\_button\_0\_blue\_wasClicked\_event(state): \# noqa: N802 > 33 global \\ > 34 dual\_button\_0\_blue, \\ > 35 dual\_button\_0\_red, \\ > 36 sys\_state, \\ > 37 FACE\_RECOGNIZE, \\ > 38 FACE\_ENROLL, \\ > 39 FACE\_DELETE, \\ > 40 detector, \\ > 41 img, \\ > 42 dl\_recognizer, \\ > 43 detection\_result, \\ > 44 IDLE, \\ > 45 kp, \\ > 46 sys\_state\_prev, \\ > 47 frame\_count, \\ > 48 res, \\ > 49 dl\_recognize\_result > 50 sys\_state \= FACE\_RECOGNIZE > 51 > 52 > 53def dual\_button\_0\_red\_wasClicked\_event(state): \# noqa: N802 > 54 global \\ > 55 dual\_button\_0\_blue, \\ > 56 dual\_button\_0\_red, \\ > 57 sys\_state, \\ > 58 FACE\_RECOGNIZE, \\ > 59 FACE\_ENROLL, \\ > 60 FACE\_DELETE, \\ > 61 detector, \\ > 62 img, \\ > 63 dl\_recognizer, \\ > 64 detection\_result, \\ > 65 IDLE, \\ > 66 kp, \\ > 67 sys\_state\_prev, \\ > 68 frame\_count, \\ > 69 res, \\ > 70 dl\_recognize\_result > 71 sys\_state \= FACE\_ENROLL > 72 > 73 > 74def btnPWR\_wasClicked\_event(state): \# noqa: N802 > 75 global \\ > 76 dual\_button\_0\_blue, \\ > 77 dual\_button\_0\_red, \\ > 78 sys\_state, \\ > 79 FACE\_RECOGNIZE, \\ > 80 FACE\_ENROLL, \\ > 81 FACE\_DELETE, \\ > 82 detector, \\ > 83 img, \\ > 84 dl\_recognizer, \\ > 85 detection\_result, \\ > 86 IDLE, \\ > 87 kp, \\ > 88 sys\_state\_prev, \\ > 89 frame\_count, \\ > 90 res, \\ > 91 dl\_recognize\_result > 92 sys\_state \= FACE\_DELETE > 93 > 94 > 95def setup(): > 96 global \\ > 97 dual\_button\_0\_blue, \\ > 98 dual\_button\_0\_red, \\ > 99 sys\_state, \\ > 100 FACE\_RECOGNIZE, \\ > 101 FACE\_ENROLL, \\ > 102 FACE\_DELETE, \\ > 103 detector, \\ > 104 img, \\ > 105 dl\_recognizer, \\ > 106 detection\_result, \\ > 107 IDLE, \\ > 108 kp, \\ > 109 sys\_state\_prev, \\ > 110 frame\_count, \\ > 111 res, \\ > 112 dl\_recognize\_result > 113 M5.begin() > 114 Widgets.fillScreen(0x222222) > 115 BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btnPWR\_wasClicked\_event) > 116 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 117 dual\_button\_0\_blue, dual\_button\_0\_red \= DualButtonUnit((8, 9)) > 118 dual\_button\_0\_blue.setCallback( > 119 type\=dual\_button\_0\_blue.CB\_TYPE.WAS\_CLICKED, cb\=dual\_button\_0\_blue\_wasClicked\_event > 120 ) > 121 dual\_button\_0\_red.setCallback( > 122 type\=dual\_button\_0\_red.CB\_TYPE.WAS\_CLICKED, cb\=dual\_button\_0\_red\_wasClicked\_event > 123 ) > 124 detector \= dl.ObjectDetector(dl.model.HUMAN\_FACE\_DETECT) > 125 dl\_recognizer \= dl.HumanFaceRecognizer() > 126 IDLE \= 0 > 127 FACE\_ENROLL \= 1 > 128 FACE\_RECOGNIZE \= 2 > 129 FACE\_DELETE \= 3 > 130 sys\_state \= IDLE > 131 sys\_state\_prev \= IDLE > 132 frame\_count \= 0 > 133 > 134 > 135def loop(): > 136 global \\ > 137 dual\_button\_0\_blue, \\ > 138 dual\_button\_0\_red, \\ > 139 sys\_state, \\ > 140 FACE\_RECOGNIZE, \\ > 141 FACE\_ENROLL, \\ > 142 FACE\_DELETE, \\ > 143 detector, \\ > 144 img, \\ > 145 dl\_recognizer, \\ > 146 detection\_result, \\ > 147 IDLE, \\ > 148 kp, \\ > 149 sys\_state\_prev, \\ > 150 frame\_count, \\ > 151 res, \\ > 152 dl\_recognize\_result > 153 M5.update() > 154 dual\_button\_0\_blue.tick(None) > 155 dual\_button\_0\_red.tick(None) > 156 img \= camera.snapshot() > 157 detection\_result \= detector.infer(img) > 158 if detection\_result: > 159 for res in detection\_result: > 160 kp \= res.keypoint() > 161 img.draw\_string(10, 10, str("face"), color\=0x3333FF, scale\=1) > 162 img.draw\_circle(kp\[0\], kp\[1\], 3, color\=0x3333FF, thickness\=1, fill\=True) > 163 img.draw\_circle(kp\[2\], kp\[3\], 3, color\=0x33FF33, thickness\=1, fill\=True) > 164 img.draw\_circle(kp\[4\], kp\[5\], 3, color\=0xFF0000, thickness\=1, fill\=True) > 165 img.draw\_circle(kp\[6\], kp\[7\], 3, color\=0x3333FF, thickness\=1, fill\=True) > 166 img.draw\_circle(kp\[8\], kp\[9\], 3, color\=0x33FF33, thickness\=1, fill\=True) > 167 img.draw\_rectangle( > 168 res.x(), res.y(), res.w(), res.h(), color\=0x3366FF, thickness\=3, fill\=False > 169 ) > 170 if sys\_state \== FACE\_DELETE: > 171 dl\_recognizer.delete\_id() > 172 sys\_state\_prev \= sys\_state > 173 sys\_state \= IDLE > 174 frame\_count \= 15 > 175 elif sys\_state != IDLE: > 176 if detection\_result: > 177 if len(detection\_result) \== 1: > 178 res \= detection\_result\[0\] > 179 if sys\_state \== FACE\_ENROLL: > 180 dl\_recognizer.enroll\_id(img, res.keypoint()) > 181 elif sys\_state \== FACE\_RECOGNIZE: > 182 dl\_recognize\_result \= dl\_recognizer.recognize(img, res.keypoint()) > 183 if (dl\_recognize\_result.id()) \> 0: > 184 print((str("similarity: ") + str((dl\_recognize\_result.similarity())))) > 185 sys\_state\_prev \= sys\_state > 186 sys\_state \= IDLE > 187 frame\_count \= 15 > 188 else: > 189 img.draw\_string(104, 10, str("face no detect"), color\=0xFF0000, scale\=1) > 190 if frame\_count \> 0: > 191 frame\_count \= frame\_count \- 1 > 192 if sys\_state\_prev \== FACE\_ENROLL: > 193 img.draw\_string(116, 10, str("face enroll"), color\=0x33FF33, scale\=1) > 194 elif sys\_state\_prev \== FACE\_RECOGNIZE: > 195 if (dl\_recognize\_result.id()) \> 0: > 196 img.draw\_string( > 197 100, > 198 10, > 199 str((str("recognize id: ") + str((dl\_recognize\_result.id())))), > 200 color\=0x33FF33, > 201 scale\=1, > 202 ) > 203 else: > 204 img.draw\_string(96, 10, str("no recognized"), color\=0xFF0000, scale\=1) > 205 elif sys\_state\_prev \== FACE\_DELETE: > 206 img.draw\_string( > 207 100, > 208 10, > 209 str((str("remaining id: ") + str((dl\_recognizer.enrolled\_id\_num())))), > 210 color\=0xFF0000, > 211 scale\=1, > 212 ) > 213 M5.Lcd.show(img, 0, 0, 320, 240) > 214 > 215 > 216if \_\_name\_\_ \== "\_\_main\_\_": > 217 try: > 218 setup() > 219 while True: > 220 loop() > 221 except (Exception, KeyboardInterrupt) as e: > 222 try: > 223 from utility import print\_error\_msg > 224 > 225 print\_error\_msg(e) > 226 except ImportError: > 227 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### human face detect[](#id1 "Link to this heading") > ![human_face_detect_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/human_face_detect_example.png) [cores3\_example\_human\_face\_detect.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/dl/cores3_example_human_face_detect.m5f2) ### pedestrain detect[](#id2 "Link to this heading") > ![pedestrian_detect_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/pedestrian_detect_example.png) [cores3\_example\_pedestrian\_detect.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/dl/cores3_example_pedestrian_detect.m5f2) ### human face recognition[](#id3 "Link to this heading") > ![human_face_recognition_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/human_face_recognition_example.png) [cores3\_example\_human\_face\_recognition.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/dl/cores3_example_human_face_recognition.m5f2) Funtions[](#funtions "Link to this heading") ---------------------------------------------- dl.ObjectDetector(_model_) → ObjectDetector[](#dl.dl.ObjectDetector "Link to this definition") Create an object detector instance. Parameters: **model** – Load a detection model. Supported values: * `dl.model.HUMAN_FACE_DETECT`: Human face detection. * `dl.model.PEDESTRIAN_DETECT`: Pedestrian detection. Returns An `ObjectDetector` instance. UIFlow2.0 > ![ObjectDetector.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/ObjectDetector.png) **Example**: detector \= dl.ObjectDetector(dl.model.HUMAN\_FACE\_DETECT) detector \= dl.ObjectDetector(dl.model.PEDESTRIAN\_DETECT) dl.HumanFaceRecognizer() → HumanFaceRecognizer[](#dl.dl.HumanFaceRecognizer "Link to this definition") Create a human face recognizer instance. Returns: A `HumanFaceRecognizer` instance. UIFlow2.0 > ![HumanFaceRecognizer.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/HumanFaceRecognizer.png) class ObjectDetector[](#class-objectdetector "Link to this heading") ---------------------------------------------------------------------- The ObjectDetector object is returned by dl.ObjectDetector(model). ObjectDetector.infer(_img: image.Image_) → DetectionResult[](#dl.ObjectDetector.infer "Link to this definition") Returns: A `DetectionResult` instance. UIFlow2.0 > ![infer.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/infer.png) class HumanFaceRecognizer[](#class-humanfacerecognizer "Link to this heading") -------------------------------------------------------------------------------- The HumanFaceRecognizer object is returned by dl.HumanFaceRecognizer(). HumanFaceRecognizer.recognize(_img: image:Image_, _keypoint: tuple_) → RecognitionResult[](#dl.HumanFaceRecognizer.recognize "Link to this definition") Face recognize * `img` imput image * `keypoint` face keypoint, ref: DetectionResult.keypoint() Returns an `RecognitionResult` object UIFlow2.0 > ![recognize.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/recognize.png) HumanFaceRecognizer.clear\_id()[](#dl.HumanFaceRecognizer.clear_id "Link to this definition") clear id UIFlow2.0 > ![clear_id.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/clear_id.png) HumanFaceRecognizer.enroll\_id(_img: image:Image_, _keypoint: tuple_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#dl.HumanFaceRecognizer.enroll_id "Link to this definition") enroll id * `img` imput image * `keypoint` face keypoint, ref: DetectionResult.keypoint() UIFlow2.0 > ![enroll_id.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/enroll_id.png) HumanFaceRecognizer.delete\_id(\[_id_\])[](#dl.HumanFaceRecognizer.delete_id "Link to this definition") delete id id is an optional parameter. If provided, it deletes the specified face information. By default, it deletes the most recently recorded id. UIFlow2.0 > ![delete_id.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/delete_id.png) > > ![delete_last_id.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/delete_last_id.png) HumanFaceRecognizer.enrolled\_id\_num() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.HumanFaceRecognizer.enrolled_id_num "Link to this definition") get enrolled id num UIFlow2.0 > ![enrolled_id_num.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/enrolled_id_num.png) class DetectionResult – DetectionResult object[](#class-detectionresult-detectionresult-object "Link to this heading") ------------------------------------------------------------------------------------------------------------------------ The line object is returned by ObjectDetector.infer(). DetectionResult.bbox()[](#dl.DetectionResult.bbox "Link to this definition") Get the bounding box of the object detection. UIFlow2.0 > ![get_bbox.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_bbox.png) DetectionResult.x() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.DetectionResult.x "Link to this definition") The x-coordinate of the top-left corner of the bounding box. UIFlow2.0 > ![get_x.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_x.png) DetectionResult.y() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.DetectionResult.y "Link to this definition") The y-coordinate of the top-left corner of the bounding box. UIFlow2.0 > ![get_y.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_y.png) DetectionResult.w() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.DetectionResult.w "Link to this definition") The width of the bounding box. UIFlow2.0 > ![get_w.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_w.png) DetectionResult.h() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.DetectionResult.h "Link to this definition") The height of the bounding box. UIFlow2.0 > ![get_h.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_h.png) DetectionResult.category() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.DetectionResult.category "Link to this definition") The detected object’s category. UIFlow2.0 > ![get_category.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_category.png) DetectionResult.keypoint() → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") [](#dl.DetectionResult.keypoint "Link to this definition") Keypoint information (currently, only the face detection model outputs this data): * `keypoint()[0], keypoint()[1]` are the coordinates of the left eye. * `keypoint()[2], keypoint()[3]` are the coordinates of the left corner of the mouth. * `keypoint()[4], keypoint()[5]` are the coordinates of the nose. * `keypoint()[6], keypoint()[7]` are the coordinates of the right eye. * `keypoint()[8], keypoint()[9]` are the coordinates of the right corner of the mouth. UIFlow2.0 > ![get_keypoint.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/get_keypoint.png) class RecognitionResult – RecognitionResult object[](#class-recognitionresult-recognitionresult-object "Link to this heading") -------------------------------------------------------------------------------------------------------------------------------- The `RecognitionResult` is returned by HumanFaceRecognizer.recognize(img, keypoint). RecognitionResult.similarity() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#dl.RecognitionResult.similarity "Link to this definition") Gets the face similarity, with a value closer to 1 indicating higher similarity. UIFlow2.0 > ![similarity.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/similarity.png) RecognitionResult.id() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#dl.RecognitionResult.id "Link to this definition") Gets the face ID. A value greater than 0 indicates that the face recognition was successful. UIFlow2.0 > ![id.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/esp_dl/id.png) --- # Unknown \=================== Contributions Guide =================== .. toctree:: :maxdepth: 3 template.rst --- # USB Mode — UIFlow2 Programming Guide master documentation * [](../index.html) * [Quick Reference](index.html) * USB Mode * [View page source](../_sources/quick-reference/usb-mode.rst.txt) * * * USB Mode[](#usb-mode "Link to this heading") ============================================== Switch to USB Mode[](#switch-to-usb-mode "Link to this heading") ------------------------------------------------------------------ Select the device under `USB Device` to enter USB mode. ![usb-mode-1.gif](../_images/usb-mode-1.gif) Run the Program[](#run-the-program "Link to this heading") ------------------------------------------------------------ Click the run button to execute the current program. ![usb-mode-2.gif](../_images/usb-mode-2.gif) Terminate the Program Execution[](#terminate-the-program-execution "Link to this heading") -------------------------------------------------------------------------------------------- Use `Ctrl + C` to terminate the execution of the program. ![usb-mode-3.gif](../_images/usb-mode-3.gif) Save the Program to the Device and Run[](#save-the-program-to-the-device-and-run "Link to this heading") ---------------------------------------------------------------------------------------------------------- Click the save button to save the program to the device and run it. ![usb-mode-4.gif](../_images/usb-mode-4.gif) File Operations[](#file-operations "Link to this heading") ------------------------------------------------------------ Click the `Get File` button to export the program from the device to the computer. Click the `Delete File` button to delete the program from the device. ![usb-mode-5.gif](../_images/usb-mode-5.gif) Browse Directories[](#browse-directories "Link to this heading") ------------------------------------------------------------------ Double-click with the mouse to enter a directory; single-click on the path bar to return to the previous directory level. ![usb-mode-6.gif](../_images/usb-mode-6.gif) Upload an Image to the Device[](#upload-an-image-to-the-device "Link to this heading") ---------------------------------------------------------------------------------------- Navigate to a specific directory within the device, click the `Send File to Here` button, select an image from your computer, and then upload it to that directory. Image resources need to be saved under the `res/img` directory. ![usb-mode-7.gif](../_images/usb-mode-7.gif) Use Images from the Device[](#use-images-from-the-device "Link to this heading") ---------------------------------------------------------------------------------- Use the ![setImage.svg](https://static-cdn.m5stack.com/mpy_docs/widgets/image/setImage.svg) block to set the filename of the image to be displayed, and show the image on the screen. ![usb-mode-8.gif](../_images/usb-mode-8.gif) --- # DualKmeter Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * DualKmeter Module * [View page source](../_sources/module/dualkmeter.rst.txt) * * * DualKmeter Module[](#dualkmeter-module "Link to this heading") ================================================================ Supported Products: > [![DualKmeter Module13.2](https://static-cdn.m5stack.com/resource/docs/products/module/DualKmeter%20Module13.2/img-91942504-2fb3-4d8e-90d2-fbf0761bb1d1.webp)](https://docs.m5stack.com/zh_CN/module/DualKmeter%20Module13.2) Micropython Example: import os, sys, io import M5 from M5 import \* from module import DualKmeterModule M5.begin() km\_0 \= DualKmeterModule(address\=0x11) while True: if km\_0.is\_ready(): print(km\_0.get\_thermocouple\_temperature(scale\=km\_0.CELSIUS)) UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/example.svg) [dualkmeter\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/dualkmeter/dualkmeter_cores3.m5f2) class DualKmeterModule[](#class-dualkmetermodule "Link to this heading") -------------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ DualKmeterModule(_address\=0x11_)[](#DualKmeterModule "Link to this definition") Create a DualKmeterModule object. `address` accepts values from 0x11 to 0x20. UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- DualKmeterModule.get\_thermocouple\_temperature(_scale\=0_) → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#DualKmeterModule.get_thermocouple_temperature "Link to this definition") Get the temperature of the thermocouple in the DualKmeter Module. Returns a float value. `scale` accepts values of `DualKmeter.CELSIUS` or `DualKmeter.FAHRENHEIT`. UIFLOW2: > ![get_thermocouple_temperature.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_thermocouple_temperature.svg) DualKmeterModule.get\_kmeter\_temperature(_scale\=0_) → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#DualKmeterModule.get_kmeter_temperature "Link to this definition") Get the internal temperature of the DualKmeter Module. Returns a float value. `scale` accepts values of `DualKmeter.CELSIUS` or `DualKmeter.FAHRENHEIT`. UIFLOW2: > ![get_kmeter_temperature.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_kmeter_temperature.svg) DualKmeterModule.get\_kmeter\_channel() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#DualKmeterModule.get_kmeter_channel "Link to this definition") Get the current thermocouple channel being used in the DualKmeter Module. `0` represents channel 1, and `1` represents channel 2. UIFLOW2: > ![get_kmeter_channel.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_kmeter_channel.svg) DualKmeterModule.set\_kmeter\_channel(_channel_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#DualKmeterModule.set_kmeter_channel "Link to this definition") Set the thermocouple channel to be used in the DualKmeter Module. `0` represents channel 1, and `1` represents channel 2. UIFLOW2: > ![set_kmeter_channel.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/set_kmeter_channel.svg) DualKmeterModule.is\_ready() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#DualKmeterModule.is_ready "Link to this definition") Check if the measurement result is ready. UIFLOW2: > ![is_ready.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/is_ready.svg) DualKmeterModule.get\_thermocouple\_temperature\_string(_scale\=0_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#DualKmeterModule.get_thermocouple_temperature_string "Link to this definition") Get the temperature of the thermocouple in the DualKmeter Module as a string with a sign. `scale` accepts values of `DualKmeter.CELSIUS` or `DualKmeter.FAHRENHEIT`. UIFLOW2: > ![get_thermocouple_temperature_string.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_thermocouple_temperature_string.svg) DualKmeterModule.get\_kmeter\_temperature\_string(_scale\=0_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#DualKmeterModule.get_kmeter_temperature_string "Link to this definition") Get the internal temperature of the DualKmeter Module as a string with a sign. `scale` accepts values of `DualKmeter.CELSIUS` or `DualKmeter.FAHRENHEIT`. UIFLOW2: > ![get_kmeter_temperature_string.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_kmeter_temperature_string.svg) DualKmeterModule.get\_fw\_ver() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#DualKmeterModule.get_fw_ver "Link to this definition") Get the firmware version of the DualKmeter Module. Returns an integer version number. UIFLOW2: > ![get_fw_ver.svg](https://static-cdn.m5stack.com/mpy_docs/module/dualkmeter/get_fw_ver.svg) Constants[](#constants "Link to this heading") ------------------------------------------------ DualKmeterModule.CELSIUS_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#DualKmeterModule.CELSIUS "Link to this definition") Celsius scale. DualKmeterModule.FAHRENHEIT_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#DualKmeterModule.FAHRENHEIT "Link to this definition") Fahrenheit scale. --- # image — UIFlow2 Programming Guide master documentation * [](../index.html) * [Advanced](index.html) * image * [View page source](../_sources/advanced/image.rst.txt) * * * image[](#image "Link to this heading") ======================================== Note This module is only applicable to the CoreS3 Controller Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### draw test[](#draw-test "Link to this heading") > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8import image > 9 > 10img \= None > 11 > 12 > 13def setup(): > 14 global img > 15 M5.begin() > 16 Widgets.fillScreen(0x222222) > 17 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 18 > 19 > 20def loop(): > 21 global img > 22 M5.update() > 23 img \= camera.snapshot() > 24 img.draw\_string(10, 10, str("M5Stack"), color\=0x3366FF, scale\=2) > 25 img.draw\_rectangle(60, 80, 50, 40, color\=0x33CC00, thickness\=3, fill\=False) > 26 img.draw\_line(200, 60, 260, 100, color\=0xFF0000, thickness\=3) > 27 img.draw\_circle(160, 120, 30, color\=0xFFCC00, thickness\=2, fill\=False) > 28 M5.Lcd.show(img, 0, 0, 320, 240) > 29 > 30 > 31if \_\_name\_\_ \== "\_\_main\_\_": > 32 try: > 33 setup() > 34 while True: > 35 loop() > 36 except (Exception, KeyboardInterrupt) as e: > 37 try: > 38 from utility import print\_error\_msg > 39 > 40 print\_error\_msg(e) > 41 except ImportError: > 42 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### draw test[](#id1 "Link to this heading") > ![image_draw_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image_draw_example.png) [cores3\_example\_draw\_test.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/image/cores3_example_draw_test.m5f2) class image.Image[](#class-image-image "Link to this heading") ---------------------------------------------------------------- The line object is returned by camera.snapshot(). Basic Methods[](#basic-methods "Link to this heading") -------------------------------------------------------- image.width() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#image.width "Link to this definition") Returns the image width in pixels. UIFlow2.0 > ![width.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/width.png) image.height() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#image.height "Link to this definition") Returns the image height in pixels. UIFlow2.0 > ![height.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/height.png) image.format() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#image.format "Link to this definition") Returns the image format UIFlow2.0 > ![format.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/format.png) image.size() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#image.size "Link to this definition") Returns the image size in bytes. UIFlow2.0 > ![size.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/size.png) image.bytearray() → [bytearray](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.13)") [](#image.bytearray "Link to this definition") Returns a bytearray object that points to the image data for byte-level read/write access. UIFlow2.0 > ![bytearray.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/bytearray.png) Drawing Methods[](#drawing-methods "Link to this heading") ------------------------------------------------------------ image.draw\_line(_x0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _x1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | Tuple\[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] | [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") \= None_, _thickness\=1_) → [Image](../widgets/image.html#Widgets.Widgets.Image "Widgets.Widgets.Image") [](#image.draw_line "Link to this definition") Draws a line from (x0, y0) to (x1, y1) on the image. You may either pass x0, y0, x1, y1 separately or as a tuple (x0, y0, x1, y1). * `color` is an RGB888 tuple for Grayscale or RGB565 images. Defaults to white. However, you may also pass the underlying pixel value (0-255) for grayscale images or a RGB565 value for RGB565 images. * `thickness` controls how thick the line is in pixels. Returns the image object so you can call another method using `.` notation. UIFlow2.0 > ![draw_line.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/draw_line.png) image.draw\_rectangle(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | Tuple\[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] | [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") \= None_, _thickness\=1_, _fill\=False_) → [Image](../widgets/image.html#Widgets.Widgets.Image "Widgets.Widgets.Image") [](#image.draw_rectangle "Link to this definition") Draws a rectangle on the image. You may either pass x, y, w, h separately or as a tuple (x, y, w, h). * `color` is an RGB888 tuple for Grayscale or RGB565 images. Defaults to white. However, you may also pass the underlying pixel value (0-255) for grayscale images or a RGB565 value for RGB565 images. * `thickness` controls how thick the lines are in pixels. * `fill` set to True to fill the rectangle. Returns the image object so you can call another method using `.` notation. UIFlow2.0 > ![draw_rectangle.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/draw_rectangle.png) image.draw\_circle(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _radius: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | Tuple\[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] | [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") \= None_, _thickness\=1_, _fill\=False_) → [Image](../widgets/image.html#Widgets.Widgets.Image "Widgets.Widgets.Image") [](#image.draw_circle "Link to this definition") Draws a circle on the image. You may either pass x, y, radius separately or as a tuple (x, y, radius). * `color` is an RGB888 tuple for Grayscale or RGB565 images. Defaults to white. However, you may also pass the underlying pixel value (0-255) for grayscale images or a RGB565 value for RGB565 images. * `thickness` controls how thick the edges are in pixels. * `fill` set to True to fill the circle. Returns the image object so you can call another method using `.` notation. UIFlow2.0 > ![draw_circle.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/draw_circle.png) image.draw\_string(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | Tuple\[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] | [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") \= None_, _scale\=1_) → [Image](../widgets/image.html#Widgets.Widgets.Image "Widgets.Widgets.Image") [](#image.draw_string "Link to this definition") Draws 8x16 text starting at location (x, y) in the image. You may either pass x, y separately or as a tuple (x, y). * `text` is a string to write to the image. `\n`, `\r`, and `\r\n` line endings move the cursor to the next line. * `color` is an RGB888 tuple for Grayscale or RGB565 images. Defaults to white. However, you may also pass the underlying pixel value (0-255) for grayscale images or a RGB565 value for RGB565 images. * `scale` may be increased to increase/decrease the size of the text on the image. You can pass greater than 0 integer or floating point values. Returns the image object so you can call another method using `.` notation. UIFlow2.0 > ![draw_string.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/draw_string.png) Constants[](#constants "Link to this heading") ------------------------------------------------ image.RGB565_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#image.RGB565 "Link to this definition") RGB565 pixel format. Each pixel is 16-bits, 2-bytes. 5-bits are used for red, 6-bits are used for green, and 5-bits are used for blue. image.GRAYSCALE_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#image.GRAYSCALE "Link to this definition") GRAYSCALE pixel format. Each pixel is 8-bits, 1-byte. image.JPEG_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#image.JPEG "Link to this definition") A JPEG image. image.YUV422_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#image.YUV422 "Link to this definition") A pixel format that is very easy to jpeg compress. Each pixel is stored as a grayscale 8-bit Y value followed by alternating 8-bit U/V color values that are shared between two Y values (8-bits Y1, 8-bits U, 8-bits Y2, 8-bits V, etc.). Only some image processing methods work with YUV422. > UIFlow2.0 > > > ![format_option.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/image/format_option.png) --- # ECG Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * ECG Module * [View page source](../_sources/module/ecg.rst.txt) * * * ECG Module[](#ecg-module "Link to this heading") ================================================== This library is the driver for Module13.2 ECG, and the module communicates via UART. Support the following products: > [![Module13.2 ECG](https://static-cdn.m5stack.com/resource/docs/products/module/ecg/ecg_01.webp)](https://docs.m5stack.com/zh_CN/module/ecg) UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### Heart Rate Monitoring Display[](#heart-rate-monitoring-display "Link to this heading") Open the [cores3\_ecg\_module\_base\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/ecg/cores3_ecg_module_base_example.m5f2) project in UiFlow2. This example program is used for real-time heart rate monitoring and ECG waveform display. During measurement, the device continuously plots the ECG (Electrocardiogram) waveform and automatically calculates and displays the heart rate data once the signal stabilizes. **Electrode Placement Instructions**: Please follow the guidelines below to correctly connect the ECG electrodes: * `Right Arm (RA)`: Place the right arm electrode on the right edge of the sternum, at the 2nd intercostal space along the midclavicular line, near the right shoulder. * `Left Arm (LA)`: Place the left arm electrode on the left edge of the sternum, at the 2nd intercostal space along the midclavicular line, near the left shoulder. * `Left Leg (LL)`: Place the left leg electrode above the iliac crest (hip bone) on the left lower abdomen, or on the lower left side of the abdomen. **Measurement Precautions**: To ensure stable and accurate ECG signals, please follow these precautions: * `Stay relaxed`: Avoid muscle tension to reduce signal interference. * `Remain still`: Minimize movement during measurement to obtain a stable ECG signal. UiFlow2 Code Block: > ![cores3_ecg_module_base_example.png](https://static-cdn.m5stack.com/mpy_docs/module/ecg/example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### Heart Rate Monitoring Display[](#id1 "Link to this heading") This example program is used for real-time heart rate monitoring and ECG waveform display. During measurement, the device continuously plots the ECG (Electrocardiogram) waveform and automatically calculates and displays the heart rate data once the signal stabilizes. **Electrode Placement Instructions**: Please follow the guidelines below to correctly connect the ECG electrodes: * `Right Arm (RA)`: Place the right arm electrode on the right edge of the sternum, at the 2nd intercostal space along the midclavicular line, near the right shoulder. * `Left Arm (LA)`: Place the left arm electrode on the left edge of the sternum, at the 2nd intercostal space along the midclavicular line, near the left shoulder. * `Left Leg (LL)`: Place the left leg electrode above the iliac crest (hip bone) on the left lower abdomen, or on the lower left side of the abdomen. **Measurement Precautions**: To ensure stable and accurate ECG signals, please follow these precautions: * `Stay relaxed`: Avoid muscle tension to reduce signal interference. * `Remain still`: Minimize movement during measurement to obtain a stable ECG signal. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import ECGModule > 9import time > 10import m5utils > 11 > 12 > 13label0 \= None > 14title0 \= None > 15label\_hr \= None > 16ecg\_0 \= None > 17display\_width \= None > 18ecg\_data \= None > 19last\_time \= None > 20points \= None > 21heartrate \= None > 22new\_ecg\_data \= None > 23new\_ecg\_data\_len \= None > 24data\_max \= None > 25data\_min \= None > 26i \= None > 27y0 \= None > 28y1 \= None > 29 > 30 > 31def setup(): > 32 global \\ > 33 label0, \\ > 34 title0, \\ > 35 label\_hr, \\ > 36 ecg\_0, \\ > 37 display\_width, \\ > 38 ecg\_data, \\ > 39 last\_time, \\ > 40 points, \\ > 41 heartrate, \\ > 42 new\_ecg\_data, \\ > 43 new\_ecg\_data\_len, \\ > 44 data\_max, \\ > 45 data\_min, \\ > 46 y0, \\ > 47 i, \\ > 48 y1 > 49 > 50 M5.begin() > 51 label0 \= Widgets.Label("HearRate:", 5, 35, 1.0, 0xFF0000, 0x000000, Widgets.FONTS.DejaVu24) > 52 title0 \= Widgets.Title("ECGModule Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 53 label\_hr \= Widgets.Label(" BPM", 142, 35, 1.0, 0xFF0000, 0x000000, Widgets.FONTS.DejaVu24) > 54 > 55 ecg\_0 \= ECGModule(1, tx\=7, rx\=1) > 56 display\_width \= M5.Lcd.width() > 57 ecg\_data \= \[0\] \* display\_width > 58 points \= \[0\] \* display\_width > 59 > 60 > 61def loop(): > 62 global \\ > 63 label0, \\ > 64 title0, \\ > 65 label\_hr, \\ > 66 ecg\_0, \\ > 67 display\_width, \\ > 68 ecg\_data, \\ > 69 last\_time, \\ > 70 points, \\ > 71 heartrate, \\ > 72 new\_ecg\_data, \\ > 73 new\_ecg\_data\_len, \\ > 74 data\_max, \\ > 75 data\_min, \\ > 76 y0, \\ > 77 i, \\ > 78 y1 > 79 M5.update() > 80 ecg\_0.poll\_data() > 81 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \> 200: > 82 last\_time \= time.ticks\_ms() > 83 heartrate \= ecg\_0.read\_heartrate() > 84 if heartrate \> 0: > 85 label0.setColor(0x00FF00, 0x000000) > 86 label\_hr.setColor(0x00FF00, 0x000000) > 87 label\_hr.setText(str((str(heartrate) + str("BPM")))) > 88 else: > 89 label0.setColor(0xFF0000, 0x000000) > 90 label\_hr.setText(str(" ")) > 91 new\_ecg\_data \= ecg\_0.read\_raw\_ecg\_data() > 92 if new\_ecg\_data: > 93 new\_ecg\_data\_len \= len(new\_ecg\_data) > 94 ecg\_data \= ecg\_data\[int((new\_ecg\_data\_len + 1) \- 1) :\] > 95 ecg\_data \= ecg\_data + new\_ecg\_data > 96 data\_max \= max(ecg\_data) > 97 data\_min \= min(ecg\_data) > 98 data\_max \= data\_max + data\_max / 10 > 99 data\_min \= data\_min \- data\_min / 10 > 100 if data\_min < 0: > 101 data\_min \= 0 > 102 for i in range(display\_width): > 103 points\[int((i + 1) \- 1)\] \= m5utils.remap( > 104 ecg\_data\[int((i + 1) \- 1)\], data\_min, data\_max, 150, 0 > 105 ) > 106 > 107 M5.Lcd.fillRect(0, 70, display\_width, 155, 0x000000) > 108 for i in range(display\_width \- 1): > 109 y0 \= int(70 + points\[int((i + 1) \- 1)\]) > 110 y1 \= int(70 + points\[int((i + 2) \- 1)\]) > 111 M5.Lcd.drawLine(i + 1, y0, i + 2, y1, 0xFF0000) > 112 > 113 > 114if \_\_name\_\_ \== "\_\_main\_\_": > 115 try: > 116 setup() > 117 while True: > 118 loop() > 119 except (Exception, KeyboardInterrupt) as e: > 120 try: > 121 from utility import print\_error\_msg > 122 > 123 print\_error\_msg(e) > 124 except ImportError: > 125 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### ECGModule[](#ecgmodule "Link to this heading") _class_ module.ecg.ECGModule(_id\=1_, _tx\=7_, _rx\=1_)[](#module.ecg.ECGModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an ECGModule object. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART id. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART TX pin. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART RX pin. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/ecg/init.png) MicroPython Code Block: > from module import ECGModule > > module\_ecg \= ECGModule(id \= 1, tx \= 7, rx \= 1) poll\_data()[](#module.ecg.ECGModule.poll_data "Link to this definition") Poll data. This function checks for new data from the module and should be called repeatedly in a loop to ensure continuous data retrieval. UiFlow2 Code Block: > ![poll_data.png](https://static-cdn.m5stack.com/mpy_docs/module/ecg/poll_data.png) MicroPython Code Block: > module\_ecg.poll\_data() Return type: None read\_heartrate()[](#module.ecg.ECGModule.read_heartrate "Link to this definition") Read heartrate. Returns: heart rate Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") If heart rate is no valid, return -1. UiFlow2 Code Block: > ![read_heartrate.png](https://static-cdn.m5stack.com/mpy_docs/module/ecg/read_heartrate.png) MicroPython Code Block: > module\_ecg.read\_heartrate() read\_raw\_ecg\_data()[](#module.ecg.ECGModule.read_raw_ecg_data "Link to this definition") Read raw ECG data. Returns: ECG data Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") UiFlow2 Code Block: > ![read_raw_ecg_data.png](https://static-cdn.m5stack.com/mpy_docs/module/ecg/read_raw_ecg_data.png) MicroPython Code Block: > module\_ecg.read\_raw\_ecg\_data() --- # Finger Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Finger Hat * [View page source](../_sources/hats/finger.rst.txt) * * * Finger Hat[](#finger-hat "Link to this heading") ================================================== The following products are supported: > [![FingerHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-finger/hat-finger_01.webp)](https://docs.m5stack.com/en/hat/hat-finger) 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 hat import FingerHat > 9 > 10 > 11label0 \= None > 12hat\_finger\_0 \= None > 13 > 14 > 15def setup(): > 16 global label0, hat\_finger\_0 > 17 > 18 M5.begin() > 19 label0 \= Widgets.Label("label0", 4, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 20 > 21 hat\_finger\_0 \= FingerHat(1, (26, 0)) > 22 > 23 > 24def loop(): > 25 global label0, hat\_finger\_0 > 26 M5.update() > 27 label0.setText(str(hat\_finger\_0.get\_user\_list())) > 28 > 29 > 30if \_\_name\_\_ \== "\_\_main\_\_": > 31 try: > 32 setup() > 33 while True: > 34 loop() > 35 except (Exception, KeyboardInterrupt) as e: > 36 try: > 37 from utility import print\_error\_msg > 38 > 39 print\_error\_msg(e) > 40 except ImportError: > 41 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/finger/example.png) [stickc\_plus2\_finger\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/finger/stickc_plus2_finger_example.m5f2) class FingerHat[](#class-fingerhat "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ FingerHat(_id: Literal\[0, 1, 2\] \= 2_, _port: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= None_)[](#FingerHat "Link to this definition") Create a FingerHat object. Parameters: * **id** – The ID of the UART, 0 or 1 or 2. * **port** – UART pin numbers. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/finger/init.png) FingerUnit class inherits FingerUnit class, See [unit.FingerUnit.Methods](../units/finger.html#unit-fingerunit-methods) for more details. --- # jpg — UIFlow2 Programming Guide master documentation * [](../index.html) * [Advanced](index.html) * jpg * [View page source](../_sources/advanced/jpg.rst.txt) * * * jpg[](#jpg "Link to this heading") ==================================== Note This module is only applicable to the CoreS3 Controller `jpg` module for encoding and decoding operations of JPG format images Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### take photo[](#take-photo "Link to this heading") Click the screen to start the countdown and take a photo > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7import camera > 8import image > 9import time > 10import jpg > 11 > 12 > 13file\_0 \= None > 14img \= None > 15cnt \= None > 16last\_time \= None > 17index \= None > 18img\_jpg \= None > 19 > 20 > 21def setup(): > 22 global file\_0, img, cnt, last\_time, index, img\_jpg > 23 M5.begin() > 24 Widgets.fillScreen(0x222222) > 25 camera.init(pixformat\=camera.RGB565, framesize\=camera.QVGA) > 26 cnt \= 0 > 27 last\_time \= 0 > 28 index \= 0 > 29 > 30 > 31def loop(): > 32 global file\_0, img, cnt, last\_time, index, img\_jpg > 33 M5.update() > 34 img \= camera.snapshot() > 35 if (M5.Touch.getCount()) \> 0: > 36 cnt \= 5 > 37 print("hello M5") > 38 if cnt \> 0: > 39 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \>= 1000: > 40 last\_time \= time.ticks\_ms() > 41 cnt \= cnt \- 1 > 42 if cnt \== 0: > 43 img\_jpg \= jpg.encode(img, 80) > 44 index \= index + 1 > 45 file\_0 \= open( > 46 "/flash/" + str((str("photo") + str((str(index) + str(".jpg"))))), "w" > 47 ) > 48 file\_0.write(img\_jpg.bytearray()) > 49 file\_0.close() > 50 img.draw\_string(140, 80, str(cnt), color\=0x000099, scale\=5) > 51 M5.Lcd.show(img, 0, 0, 320, 240) > 52 > 53 > 54if \_\_name\_\_ \== "\_\_main\_\_": > 55 try: > 56 setup() > 57 while True: > 58 loop() > 59 except (Exception, KeyboardInterrupt) as e: > 60 try: > 61 from utility import print\_error\_msg > 62 > 63 print\_error\_msg(e) > 64 except ImportError: > 65 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### take photo[](#id1 "Link to this heading") Click the screen to start the countdown and take a photo > ![take_photo_example.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/take_photo_example.png) [take\_photo\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/advanced/camera/take_photo_example.m5f2) Methods[](#methods "Link to this heading") -------------------------------------------- jpg.encode(_img: image.Image_, _quality\=60_) → image.Image[](#jpg.encode "Link to this definition") encode to jog photo * `img` Image to be encoded, in the format of image.RGB565 Return `image.Image` instance, image format image.JPEG UIFlow2.0 > ![encode.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/jpg/encode.png) jpg.decode(_img\_jpg: image.Image_) → image.Image[](#jpg.decode "Link to this definition") jpg photo decode * `img` Image to be decoded, in the format of image.JPEG Return `image.Image` instance, image format image.RGB565 UIFlow2.0 > ![decode.png](https://static-cdn.m5stack.com/mpy_docs/advanced/openmv/jpg/decode.png) --- # Heart Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Heart Hat * [View page source](../_sources/hats/heart.rst.txt) * * * Heart Hat[](#heart-hat "Link to this heading") ================================================ MAX30102 is a complete pulse oximetry and heart-rate sensor system solution designed for the demanding requirements of wearable devices. Support the following products: [![HeartHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat_heart_rate/hat_heart_rate_01.webp)](https://docs.m5stack.com/en/hat/hat_heart_rate) 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 hat import HeartHat > 10 > 11 > 12Heart \= None > 13SPO2 \= None > 14label0 \= None > 15label1 \= None > 16i2c0 \= None > 17hat\_heart\_0 \= None > 18 > 19 > 20def setup(): > 21 global Heart, SPO2, label0, label1, i2c0, hat\_heart\_0 > 22 > 23 M5.begin() > 24 Heart \= Widgets.Label("Heart", 1, 2, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 SPO2 \= Widgets.Label("SPO2", 3, 122, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 label0 \= Widgets.Label("0", 5, 45, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu40) > 27 label1 \= Widgets.Label("0", 7, 169, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu40) > 28 > 29 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 30 hat\_heart\_0 \= HeartHat(i2c0, 0x57) > 31 hat\_heart\_0.start() > 32 > 33 > 34def loop(): > 35 global Heart, SPO2, label0, label1, i2c0, hat\_heart\_0 > 36 M5.update() > 37 label0.setText(str(hat\_heart\_0.get\_heart\_rate())) > 38 label1.setText(str(hat\_heart\_0.get\_spo2())) > 39 > 40 > 41if \_\_name\_\_ \== "\_\_main\_\_": > 42 try: > 43 setup() > 44 while True: > 45 loop() > 46 except (Exception, KeyboardInterrupt) as e: > 47 try: > 48 from utility import print\_error\_msg > 49 > 50 print\_error\_msg(e) > 51 except ImportError: > 52 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/example.png) [stickc\_heart\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/heart/stickc_heart_example.m5f2) class HeartHat[](#class-hearthat "Link to this heading") ---------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ HeartHat(_i2c_, _address_)[](#HeartHat "Link to this definition") Initialize the HeartHat. * `i2c`: I2C port to use. * `address`: I2C address of the HeartHat. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- HeartHat.stop()[](#HeartHat.stop "Link to this definition") Stop the HeartHat. UIFLOW2: > ![stop.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/stop.png) HeartHat.start()[](#HeartHat.start "Link to this definition") Start the HeartHat. UIFLOW2: > ![start.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/start.png) HeartHat.deinit()[](#HeartHat.deinit "Link to this definition") Deinitialize the HeartHat. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/deinit.png) HeartHat.get\_heart\_rate()[](#HeartHat.get_heart_rate "Link to this definition") Get the heart rate. UIFLOW2: > ![get_heart_rate.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/get_heart_rate.png) HeartHat.get\_spo2()[](#HeartHat.get_spo2 "Link to this definition") Get the SpO2. UIFLOW2: > ![get_spo2.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/get_spo2.png) HeartHat.get\_ir()[](#HeartHat.get_ir "Link to this definition") Get the IR value. UIFLOW2: > ![get_ir.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/get_ir.png) HeartHat.get\_red()[](#HeartHat.get_red "Link to this definition") Get the red value. UIFLOW2: > ![get_red.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/get_red.png) HeartHat.set\_mode(_mode_)[](#HeartHat.set_mode "Link to this definition") Set the mode of the HeartHat. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The detect mode of the HeartHat. Options: - `HeartHat.MODE_HR_ONLY`: Only heart rate - `HeartHat.MODE_SPO2_HR`: Heart rate and SpO2 UIFLOW2: > ![set_mode.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/set_mode.png) HeartHat.set\_led\_current(_led\_current_)[](#HeartHat.set_led_current "Link to this definition") Set the LED current of the HeartHat. Parameters: **led\_current** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The LED current of the HeartHat. Options: - `HeartHat.LED_CURRENT_0MA`: 0mA - `HeartHat.LED_CURRENT_4_4MA`: 4.4mA - `HeartHat.LED_CURRENT_7_6MA`: 7.6mA - `HeartHat.LED_CURRENT_11MA`: 11mA - `HeartHat.LED_CURRENT_14_2MA`: 14.2mA - `HeartHat.LED_CURRENT_17_4MA`: 17.4mA - `HeartHat.LED_CURRENT_20_8MA`: 20.8mA - `HeartHat.LED_CURRENT_24MA`: 24mA - `HeartHat.LED_CURRENT_27_1MA`: 27.1mA - `HeartHat.LED_CURRENT_30_6MA`: 30.6mA - `HeartHat.LED_CURRENT_33_8MA`: 33.8mA - `HeartHat.LED_CURRENT_37MA`: 37mA - `HeartHat.LED_CURRENT_40_2MA`: 40.2mA - `HeartHat.LED_CURRENT_43_6MA`: 43.6mA - `HeartHat.LED_CURRENT_46_8MA`: 46.8mA - `HeartHat.LED_CURRENT_50MA`: 50mA UIFLOW2: > ![set_led_current.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/set_led_current.png) HeartHat.set\_pulse\_width(_pulse\_width_)[](#HeartHat.set_pulse_width "Link to this definition") Set the pulse width of the HeartHat. Parameters: **pulse\_width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The pulse width of the HeartHat. Options: - `HeartHat.PULSE_WIDTH_200US_ADC_13`: 200us - `HeartHat.PULSE_WIDTH_400US_ADC_14`: 400us - `HeartHat.PULSE_WIDTH_800US_ADC_15`: 800us - `HeartHat.PULSE_WIDTH_1600US_ADC_16`: 1600us UIFLOW2: > ![set_pulse_width.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/set_pulse_width.png) HeartHat.set\_sampling\_rate(_sampling\_rate_)[](#HeartHat.set_sampling_rate "Link to this definition") Set the sampling rate of the HeartHat. Parameters: **sampling\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The sampling rate of the HeartHat. Options: - `HeartHat.SAMPLING_RATE_50HZ`: 50Hz - `HeartHat.SAMPLING_RATE_100HZ`: 100Hz - `HeartHat.SAMPLING_RATE_167HZ`: 167Hz - `HeartHat.SAMPLING_RATE_200HZ`: 200Hz - `HeartHat.SAMPLING_RATE_400HZ`: 400Hz - `HeartHat.SAMPLING_RATE_600HZ`: 600Hz - `HeartHat.SAMPLING_RATE_800HZ`: 800Hz - `HeartHat.SAMPLING_RATE_1000HZ`: 1000Hz UIFLOW2: > ![set_sampling_rate.png](https://static-cdn.m5stack.com/mpy_docs/hat/heart/set_sampling_rate.png) Constants[](#constants "Link to this heading") ------------------------------------------------ HeartHat.MODE\_HR\_ONLY[](#HeartHat.MODE_HR_ONLY "Link to this definition") Detect heart rate only. HeartHat.MODE\_SPO2\_HR[](#HeartHat.MODE_SPO2_HR "Link to this definition") Detect heart rate and SpO2. --- # JoyC Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * JoyC Hat * [View page source](../_sources/hats/joyc.rst.txt) * * * JoyC Hat[](#joyc-hat "Link to this heading") ============================================== The following products are supported: > [![JoyCHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-joyc/hat-joyc_01.webp)](https://docs.m5stack.com/en/hat/hat-joyc) 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 hat import JoyCHat > 10 > 11 > 12circle0 \= None > 13circle1 \= None > 14label0 \= None > 15label1 \= None > 16label2 \= None > 17label3 \= None > 18i2c0 \= None > 19hat\_joyc\_0 \= None > 20 > 21 > 22value \= None > 23in\_min \= None > 24in\_max \= None > 25out\_min \= None > 26out\_range \= None > 27x \= None > 28y \= None > 29last\_x \= None > 30last\_y \= None > 31 > 32 > 33\# Describe this function... > 34def map\_to\_range(value, in\_min, in\_max, out\_min, out\_range): > 35 global x, y, last\_x, last\_y, circle0, circle1, label0, label1, label2, label3, i2c0, hat\_joyc\_0 > 36 return int((value \- in\_min) \* out\_range / (in\_max \- in\_min) + out\_min) > 37 > 38 > 39def setup(): > 40 global \\ > 41 circle0, \\ > 42 circle1, \\ > 43 label0, \\ > 44 label1, \\ > 45 label2, \\ > 46 label3, \\ > 47 i2c0, \\ > 48 hat\_joyc\_0, \\ > 49 x, \\ > 50 out\_range, \\ > 51 out\_min, \\ > 52 y, \\ > 53 value, \\ > 54 in\_min, \\ > 55 in\_max, \\ > 56 last\_x, \\ > 57 last\_y > 58 > 59 M5.begin() > 60 circle0 \= Widgets.Circle(67, 120, 50, 0xFFFFFF, 0x000000) > 61 circle1 \= Widgets.Circle(67, 120, 4, 0xFFFFFF, 0xFFFFFF) > 62 label0 \= Widgets.Label("X:", 6, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 63 label1 \= Widgets.Label("Y:", 6, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 64 label2 \= Widgets.Label("0", 25, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 65 label3 \= Widgets.Label("0", 21, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 66 > 67 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 68 hat\_joyc\_0 \= JoyCHat(i2c0, 0x38) > 69 hat\_joyc\_0.swap\_x(True) > 70 hat\_joyc\_0.swap\_y(True) > 71 last\_x \= 67 > 72 last\_y \= 120 > 73 > 74 > 75def loop(): > 76 global \\ > 77 circle0, \\ > 78 circle1, \\ > 79 label0, \\ > 80 label1, \\ > 81 label2, \\ > 82 label3, \\ > 83 i2c0, \\ > 84 hat\_joyc\_0, \\ > 85 x, \\ > 86 out\_range, \\ > 87 out\_min, \\ > 88 y, \\ > 89 value, \\ > 90 in\_min, \\ > 91 in\_max, \\ > 92 last\_x, \\ > 93 last\_y > 94 M5.update() > 95 x \= last\_x + map\_to\_range(hat\_joyc\_0.get\_x(0), \-128, 127, \-43, 86) > 96 y \= last\_y + map\_to\_range(hat\_joyc\_0.get\_y(0), \-128, 127, \-43, 86) > 97 circle1.setCursor(x\=x, y\=y) > 98 if hat\_joyc\_0.get\_button\_status(0): > 99 circle1.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 100 else: > 101 circle1.setColor(color\=0xFFFFFF, fill\_c\=0x6600CC) > 102 label2.setText(str(hat\_joyc\_0.get\_x(0))) > 103 label3.setText(str(hat\_joyc\_0.get\_y(0))) > 104 > 105 > 106if \_\_name\_\_ \== "\_\_main\_\_": > 107 try: > 108 setup() > 109 while True: > 110 loop() > 111 except (Exception, KeyboardInterrupt) as e: > 112 try: > 113 from utility import print\_error\_msg > 114 > 115 print\_error\_msg(e) > 116 except ImportError: > 117 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/example.png) [stickc\_plus2\_joyc\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/joyc/stickc_plus2_joyc_example.m5f2) class JoyCHat[](#class-joychat "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ JoyCHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x38_)[](#JoyCHat "Link to this definition") Create a new instance of the JoyCHat class. Parameters: * **i2c** – I2C bus * **address** – I2C address UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- JoyCHat.get\_x\_raw(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoyCHat.get_x_raw "Link to this definition") Get the raw x-axis value. Parameters: **channel** – 0 or 1 Returns: x-axis value UIFLOW2: > ![get_x_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/get_x_raw.png) JoyCHat.get\_y\_raw(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoyCHat.get_y_raw "Link to this definition") Get the raw y-axis value. Parameters: **channel** – 0 or 1 Returns: y-axis value UIFLOW2: > ![get_y_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/get_y_raw.png) JoyCHat.get\_x(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoyCHat.get_x "Link to this definition") Get the x-axis value. Parameters: **channel** – 0 or 1 Returns: x-axis value UIFLOW2: > ![get_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/get_x.png) JoyCHat.get\_y(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoyCHat.get_y "Link to this definition") Get the y-axis value. Parameters: **channel** – 0 or 1 Returns: y-axis value UIFLOW2: > ![get_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/get_y.png) JoyCHat.swap\_x(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#JoyCHat.swap_x "Link to this definition") Swap x-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/swap_x.png) JoyCHat.swap\_y(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#JoyCHat.swap_y "Link to this definition") Swap y-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/swap_y.png) JoyCHat.get\_button\_status(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#JoyCHat.get_button_status "Link to this definition") Get the button status. Parameters: **channel** – 0 or 1 Returns: True or False UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/get_button_status.png) JoyCHat.fill\_color() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#JoyCHat.fill_color "Link to this definition") Fill the screen with a color. UIFLOW2: > ![fill_color.png](https://static-cdn.m5stack.com/mpy_docs/hat/joyc/fill_color.png) --- # Unknown Controllers ============ .. toctree:: :maxdepth: 1 cores3.rst atoms3.rst atoms3-lite.rst atoms3u.rst stamps3.rst cardputer.rst coreink.rst airq.rst paper.rst dinmeter.rst --- # 4EncoderMotor Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * 4EncoderMotor Module * [View page source](../_sources/module/encoder4_motor.rst.txt) * * * 4EncoderMotor Module[](#encodermotor-module "Link to this heading") ===================================================================== 4EncoderMotor Module is a 4-channel encoder motor driver module that utilizes the STM32+BL5617 solution. It is suitable for various applications such as robot motion control, automation equipment, smart vehicles, laboratory equipment, and industrial automation systems. This is the driver library for the 4EncoderMotor Module, use to control motor and read encoder value. Support the following products: > | | | > | --- | --- | > | [![4EncoderMotor](https://static-cdn.m5stack.com/resource/docs/products/module/Module-4EncoderMotor/img-b0ee8659-161f-4ffd-ac50-3702aa06a60b.webp)](https://docs.m5stack.com/en/module/Module-4EncoderMotor) | [![4EncoderMotor-V11](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/module/Module_4EncoderMotor_V1.1/4.webp)](https://docs.m5stack.com/en/module/Module_4EncoderMotor_V1.1) | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Motor control[](#motor-control "Link to this heading") Open the [encoder4motor\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/encoder4_motor/encoder4motor_core2_example.m5f2) project in UiFlow2. This example shows how to control the motor and read the encoder value. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Motor control[](#id1 "Link to this heading") This example shows how to control the motor and read the encoder value. MicroPython Code Block: > 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 module import Encoder4MotorModule > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16encoder4\_motor\_0 \= None > 17 > 18 > 19def setup(): > 20 global title0, label0, label1, label2, label3, encoder4\_motor\_0 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title( > 25 "4EncoderMotor Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 26 ) > 27 label0 \= Widgets.Label("label0", 1, 56, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 28 label1 \= Widgets.Label("label1", 1, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label2 \= Widgets.Label("label2", 1, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 label3 \= Widgets.Label("label3", 1, 185, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 31 > 32 encoder4\_motor\_0 \= Encoder4MotorModule(address\=0x24) > 33 encoder4\_motor\_0.set\_all\_motors\_mode(0x02) > 34 encoder4\_motor\_0.set\_speed\_point\_value(0x00, 50) > 35 encoder4\_motor\_0.set\_speed\_point\_value(0x01, 50) > 36 encoder4\_motor\_0.set\_speed\_point\_value(0x02, 50) > 37 encoder4\_motor\_0.set\_speed\_point\_value(0x03, 50) > 38 > 39 > 40def loop(): > 41 global title0, label0, label1, label2, label3, encoder4\_motor\_0 > 42 M5.update() > 43 label0.setText( > 44 str((str("Motor1 Speed:") + str((encoder4\_motor\_0.get\_motor\_speed\_value(0x00))))) > 45 ) > 46 label1.setText( > 47 str((str("Motor2 Speed:") + str((encoder4\_motor\_0.get\_motor\_speed\_value(0x01))))) > 48 ) > 49 label2.setText( > 50 str((str("Motor3 Speed:") + str((encoder4\_motor\_0.get\_motor\_speed\_value(0x02))))) > 51 ) > 52 label3.setText( > 53 str((str("Motor4 Speed:") + str((encoder4\_motor\_0.get\_motor\_speed\_value(0x03))))) > 54 ) > 55 > 56 > 57if \_\_name\_\_ \== "\_\_main\_\_": > 58 try: > 59 setup() > 60 while True: > 61 loop() > 62 except (Exception, KeyboardInterrupt) as e: > 63 try: > 64 from utility import print\_error\_msg > 65 > 66 print\_error\_msg(e) > 67 except ImportError: > 68 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Encoder4MotorModule[](#encoder4motormodule "Link to this heading") _class_ module.encoder4\_motor.Encoder4MotorModule(_address\=36_)[](#module.encoder4_motor.Encoder4MotorModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an Encoder4MotorModule object Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the device. Default is 0x24. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/init.png) MicroPython Code Block: > from module import Encoder4MotorModule > > encoder4\_motor \= Encoder4MotorModule(0x24) set\_motor\_mode(_motor_, _mode_)[](#module.encoder4_motor.Encoder4MotorModule.set_motor_mode "Link to this definition") Set the motor mode. Parameters: * **motor** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the mode. * **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The mode of the motor. Options: * `NORMAL_MODE`: 0 * `POSITION_MODE`: 1 * `SPEED_MODE`: 2 UiFlow2 Code Block: > ![set_motor_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_motor_mode.png) MicroPython Code Block: > encoder4\_motor.set\_motor\_mode(0, encoder4\_motor.NORMAL\_MODE) set\_all\_motors\_mode(_mode_)[](#module.encoder4_motor.Encoder4MotorModule.set_all_motors_mode "Link to this definition") Set the mode of all motors. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The mode of the motors. Options: * `NORMAL_MODE`: 0 * `POSITION_MODE`: 1 * `SPEED_MODE`: 2 UiFlow2 Code Block: > ![set_all_motors_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_all_motors_mode.png) MicroPython Code Block: > encoder4\_motor.set\_all\_motors\_mode(encoder4\_motor.NORMAL\_MODE) set\_motor\_pwm\_dutycycle(_motor_, _duty_)[](#module.encoder4_motor.Encoder4MotorModule.set_motor_pwm_dutycycle "Link to this definition") Set the PWM duty cycle of a motor. Parameters: * **motor** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the PWM duty cycle. * **duty** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM duty cycle. UiFlow2 Code Block: > ![set_motor_pwm_dutycycle.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_motor_pwm_dutycycle.png) MicroPython Code Block: > encoder4\_motor.set\_motor\_pwm\_dutycycle(0, 127) get\_motor\_encoder\_value(_pos_)[](#module.encoder4_motor.Encoder4MotorModule.get_motor_encoder_value "Link to this definition") Get the encoder value of a motor. Parameters: **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to get the encoder value. Returns: The encoder value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_motor_encoder_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_motor_encoder_value.png) MicroPython Code Block: > encoder4\_motor.get\_motor\_encoder\_value(0) set\_motor\_encoder\_value(_pos_, _value_)[](#module.encoder4_motor.Encoder4MotorModule.set_motor_encoder_value "Link to this definition") Set the encoder value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the encoder value. * **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The encoder value. UiFlow2 Code Block: > ![set_motor_encoder_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_motor_encoder_value.png) MicroPython Code Block: > encoder4\_motor.set\_motor\_encoder\_value(0, 100) get\_encoder\_mode()[](#module.encoder4_motor.Encoder4MotorModule.get_encoder_mode "Link to this definition") Get the encoder mode. Returns: The encoder mode. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_encoder_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_encoder_mode.png) MicroPython Code Block: > encoder4\_motor.get\_encoder\_mode() set\_encoder\_mode(_mode_)[](#module.encoder4_motor.Encoder4MotorModule.set_encoder_mode "Link to this definition") Set the encoder mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The mode of the encoder. Options: * `AB`: 0 * `BA`: 1 UiFlow2 Code Block: > ![set_encoder_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_encoder_mode.png) MicroPython Code Block: > encoder4\_motor.set\_encoder\_mode(0x00) get\_motor\_speed\_value(_pos_)[](#module.encoder4_motor.Encoder4MotorModule.get_motor_speed_value "Link to this definition") Get the speed value of a motor. Parameters: **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to get the speed value. Returns: The speed value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_motor_speed_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_motor_speed_value.png) MicroPython Code Block: > encoder4\_motor.get\_motor\_speed\_value(0) set\_position\_encoder\_value(_pos_, _value_)[](#module.encoder4_motor.Encoder4MotorModule.set_position_encoder_value "Link to this definition") Set the position encoder value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the position encoder value. * **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The position encoder value. UiFlow2 Code Block: > ![set_position_encoder_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_position_encoder_value.png) MicroPython Code Block: > encoder4\_motor.set\_position\_encoder\_value(0, 100) set\_position\_max\_speed\_value(_pos_, _value_)[](#module.encoder4_motor.Encoder4MotorModule.set_position_max_speed_value "Link to this definition") Set the maximum speed value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the maximum speed value. * **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The maximum speed value. UiFlow2 Code Block: > ![set_position_max_speed_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_position_max_speed_value.png) MicroPython Code Block: > encoder4\_motor.set\_position\_max\_speed\_value(0, 127) get\_position\_pid\_value(_pos_)[](#module.encoder4_motor.Encoder4MotorModule.get_position_pid_value "Link to this definition") Get the position PID value of a motor. Parameters: **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to get the position P,I,D value. Returns: The position PID value. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_position_PID_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_position_PID_value.png) MicroPython Code Block: > encoder4\_motor.get\_position\_pid\_value(0) set\_position\_pid\_value(_pos_, _p_, _i_, _d_)[](#module.encoder4_motor.Encoder4MotorModule.set_position_pid_value "Link to this definition") Set the position P,I,D value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the position P,I,D value. * **p** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The P value. * **i** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I value. * **d** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The D value. UiFlow2 Code Block: > ![set_position_PID_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_position_PID_value.png) MicroPython Code Block: > encoder4\_motor.set\_position\_pid\_value(0, 100, 100, 100) get\_speed\_pid\_value(_pos_)[](#module.encoder4_motor.Encoder4MotorModule.get_speed_pid_value "Link to this definition") Get the speed PID value of a motor. Parameters: **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to get the speed P,I,D value. Returns: The speed P,I,D value. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_speed_PID_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_speed_PID_value.png) MicroPython Code Block: > encoder4\_motor.get\_speed\_PID\_value(0) set\_speed\_pid\_value(_pos_, _p_, _i_, _d_)[](#module.encoder4_motor.Encoder4MotorModule.set_speed_pid_value "Link to this definition") Set the speed PID value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the speed PID value. * **p** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The P value. * **i** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I value. * **d** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The D value. UiFlow2 Code Block: > ![set_speed_PID_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_speed_PID_value.png) MicroPython Code Block: > encoder4\_motor.set\_speed\_PID\_value(0, 100, 100, 100) set\_speed\_point\_value(_pos_, _point_)[](#module.encoder4_motor.Encoder4MotorModule.set_speed_point_value "Link to this definition") Set the speed point value of a motor. Parameters: * **pos** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the speed point value. * **point** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The speed point value. UiFlow2 Code Block: > ![set_speed_point_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_speed_point_value.png) MicroPython Code Block: > encoder4\_motor.set\_speed\_point\_value(0, 127) get\_vin\_current\_float\_value()[](#module.encoder4_motor.Encoder4MotorModule.get_vin_current_float_value "Link to this definition") Get the input current value in float. Returns: The input current value. Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_vin_current_float_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_vin_current_float_value.png) MicroPython Code Block: > encoder4\_motor.get\_vin\_current\_float\_value() get\_vin\_current\_int\_value()[](#module.encoder4_motor.Encoder4MotorModule.get_vin_current_int_value "Link to this definition") Get the input current value in int. Returns: The input current value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_vin_current_int_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_vin_current_int_value.png) MicroPython Code Block: > encoder4\_motor.get\_vin\_current\_int\_value() get\_vin\_adc\_raw8\_value()[](#module.encoder4_motor.Encoder4MotorModule.get_vin_adc_raw8_value "Link to this definition") Get the input voltage ADC raw value in 8-bit. Returns: The input voltage ADC raw value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_vin_adc_raw8_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_vin_adc_raw8_value.png) MicroPython Code Block: > encoder4\_motor.get\_vin\_adc\_raw8\_value() get\_vin\_adc\_raw12\_value()[](#module.encoder4_motor.Encoder4MotorModule.get_vin_adc_raw12_value "Link to this definition") Get the input voltage ADC raw value in 12-bit. Returns: The input voltage ADC raw value. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_vin_adc_raw12_value.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_vin_adc_raw12_value.png) MicroPython Code Block: > encoder4\_motor.get\_vin\_adc\_raw12\_value() get\_vin\_voltage()[](#module.encoder4_motor.Encoder4MotorModule.get_vin_voltage "Link to this definition") Get the input voltage value. Returns: The input voltage value. Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_vin_voltage.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_vin_voltage.png) MicroPython Code Block: > encoder4\_motor.get\_vin\_voltage() get\_device\_spec(_info_)[](#module.encoder4_motor.Encoder4MotorModule.get_device_spec "Link to this definition") Get the device specification. Parameters: **info** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The information to get. Returns: The device specification(firmware version/I2C address). Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_device_spec.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_device_spec.png) MicroPython Code Block: > encoder4\_motor.get\_device\_spec(0xFE) get\_soft\_start\_state(_motor_)[](#module.encoder4_motor.Encoder4MotorModule.get_soft_start_state "Link to this definition") Get the soft start state of a motor. Parameters: **motor** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to get the soft start state. Returns: The soft start state. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![get_soft_start_state.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/get_soft_start_state.png) MicroPython Code Block: > encoder4\_motor.get\_soft\_start\_state(0) set\_soft\_start\_state(_motor_, _state_)[](#module.encoder4_motor.Encoder4MotorModule.set_soft_start_state "Link to this definition") Set the soft start state of a motor. Parameters: * **motor** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor to set the soft start state. * **state** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The soft start state. Options: * `True`: 1 * `False`: 0 UiFlow2 Code Block: > ![set_soft_start_state.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_soft_start_state.png) MicroPython Code Block: > encoder4\_motor.set\_soft\_start\_state(0, True) set\_i2c\_address(_addr_)[](#module.encoder4_motor.Encoder4MotorModule.set_i2c_address "Link to this definition") Set the I2C address of the device. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address to set. UiFlow2 Code Block: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/encoder4motor/set_i2c_address.png) MicroPython Code Block: > encoder4\_motor.set\_i2c\_address(0x24) --- # Joystick Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Joystick Hat * [View page source](../_sources/hats/joystick.rst.txt) * * * Joystick Hat[](#joystick-hat "Link to this heading") ====================================================== The following products are supported: > [![JoystickHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-joystick/hat-joystick_01.webp)](https://docs.m5stack.com/en/hat/hat-joystick) 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 hat import JoystickHat > 10 > 11 > 12circle0 \= None > 13circle1 \= None > 14label0 \= None > 15label1 \= None > 16label2 \= None > 17label3 \= None > 18i2c0 \= None > 19i2c1 \= None > 20hat\_joystick\_0 \= None > 21 > 22 > 23x \= None > 24value \= None > 25in\_min \= None > 26in\_max \= None > 27out\_min \= None > 28out\_range \= None > 29y \= None > 30last\_x \= None > 31last\_y \= None > 32 > 33 > 34\# Describe this function... > 35def map\_to\_range(value, in\_min, in\_max, out\_min, out\_range): > 36 global \\ > 37 x, \\ > 38 y, \\ > 39 last\_x, \\ > 40 last\_y, \\ > 41 circle0, \\ > 42 circle1, \\ > 43 label0, \\ > 44 label1, \\ > 45 label2, \\ > 46 label3, \\ > 47 i2c0, \\ > 48 i2c1, \\ > 49 hat\_joystick\_0 > 50 return int((value \- in\_min) \* out\_range / (in\_max \- in\_min) + out\_min) > 51 > 52 > 53def setup(): > 54 global \\ > 55 circle0, \\ > 56 circle1, \\ > 57 label0, \\ > 58 label1, \\ > 59 label2, \\ > 60 label3, \\ > 61 i2c0, \\ > 62 i2c1, \\ > 63 hat\_joystick\_0, \\ > 64 x, \\ > 65 out\_range, \\ > 66 out\_min, \\ > 67 y, \\ > 68 value, \\ > 69 in\_min, \\ > 70 in\_max, \\ > 71 last\_x, \\ > 72 last\_y > 73 > 74 M5.begin() > 75 circle0 \= Widgets.Circle(67, 120, 50, 0xFFFFFF, 0x000000) > 76 circle1 \= Widgets.Circle(67, 120, 4, 0xFFFFFF, 0xFFFFFF) > 77 label0 \= Widgets.Label("X:", 6, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 78 label1 \= Widgets.Label("Y:", 6, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 79 label2 \= Widgets.Label("0", 25, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 80 label3 \= Widgets.Label("0", 21, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 81 > 82 i2c0 \= I2C(0, scl\=Pin(33), sda\=Pin(32), freq\=100000) > 83 i2c1 \= I2C(1, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 84 hat\_joystick\_0 \= JoystickHat(i2c1, 0x38) > 85 hat\_joystick\_0.swap\_y(True) > 86 last\_x \= 67 > 87 last\_y \= 120 > 88 > 89 > 90def loop(): > 91 global \\ > 92 circle0, \\ > 93 circle1, \\ > 94 label0, \\ > 95 label1, \\ > 96 label2, \\ > 97 label3, \\ > 98 i2c0, \\ > 99 i2c1, \\ > 100 hat\_joystick\_0, \\ > 101 x, \\ > 102 out\_range, \\ > 103 out\_min, \\ > 104 y, \\ > 105 value, \\ > 106 in\_min, \\ > 107 in\_max, \\ > 108 last\_x, \\ > 109 last\_y > 110 M5.update() > 111 x \= last\_x + map\_to\_range(hat\_joystick\_0.get\_x(), \-128, 127, \-43, 86) > 112 y \= last\_y + map\_to\_range(hat\_joystick\_0.get\_y(), \-128, 127, \-43, 86) > 113 circle1.setCursor(x\=x, y\=y) > 114 if hat\_joystick\_0.get\_button\_status(): > 115 circle1.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 116 else: > 117 circle1.setColor(color\=0xFFFFFF, fill\_c\=0x6600CC) > 118 label2.setText(str(hat\_joystick\_0.get\_x())) > 119 label3.setText(str(hat\_joystick\_0.get\_y())) > 120 > 121 > 122if \_\_name\_\_ \== "\_\_main\_\_": > 123 try: > 124 setup() > 125 while True: > 126 loop() > 127 except (Exception, KeyboardInterrupt) as e: > 128 try: > 129 from utility import print\_error\_msg > 130 > 131 print\_error\_msg(e) > 132 except ImportError: > 133 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/example.png) [stickc\_plus2\_joystick\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/joystick/stickc_plus2_joystick_example.m5f2) class JoystickHat[](#class-joystickhat "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ JoystickHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x38_)[](#JoystickHat "Link to this definition") Create a new instance of the JoystickHat class. Parameters: * **i2c** – I2C bus * **address** – I2C address UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- JoystickHat.get\_x\_raw() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoystickHat.get_x_raw "Link to this definition") Get the raw x-axis value. Returns: x-axis value UIFLOW2: > ![get_x_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/get_x_raw.png) JoystickHat.get\_y\_raw() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoystickHat.get_y_raw "Link to this definition") Get the raw y-axis value. Returns: y-axis value UIFLOW2: > ![get_y_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/get_y_raw.png) JoystickHat.get\_x() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoystickHat.get_x "Link to this definition") Get the x-axis value. Returns: x-axis value UIFLOW2: > ![get_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/get_x.png) JoystickHat.get\_y() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#JoystickHat.get_y "Link to this definition") Get the y-axis value. Returns: y-axis value UIFLOW2: > ![get_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/get_y.png) JoystickHat.swap\_x(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#JoystickHat.swap_x "Link to this definition") Swap x-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/swap_x.png) JoystickHat.swap\_y(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#JoystickHat.swap_y "Link to this definition") Swap y-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/swap_y.png) JoystickHat.get\_button\_status() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#JoystickHat.get_button_status "Link to this definition") Get the button status. Returns: True or False UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/joystick/get_button_status.png) --- # Unknown Advanced ========= .. include:: ../refs/advanced.ref .. toctree:: :maxdepth: 1 usb/index.rst camera.rst code\_scanner.rst dl.rst image.rst jpg.rst --- # Fan v1.1 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Fan v1.1 Module * [View page source](../_sources/module/fan.rst.txt) * * * Fan v1.1 Module[](#fan-v1-1-module "Link to this heading") ============================================================ This is the driver library of Fan Module, which is used to control the fan. Support the following products: > [![FAN](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1125/M013-V11_01.webp)](https://docs.m5stack.com/en/module/Module%20Fan%20v1.1) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### control module fan v1.1[](#control-module-fan-v1-1 "Link to this heading") Open the [fan\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/fan/fan_cores3_example.m5f2) project in UiFlow2. Initializes the fan module, sets the fan status, PWM frequency and duty cycle, and displays the fan status, speed, PWM frequency and duty cycle on the screen in real time. When the user touches the screen, the fan status toggles on/off. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### control module fan v1.1[](#id1 "Link to this heading") Initializes the fan module, sets the fan status, PWM frequency and duty cycle, and displays the fan status, speed, PWM frequency and duty cycle on the screen in real time. When the user touches the screen, the fan status toggles on/off. MicroPython Code Block: > 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 module import FanModule > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15label2 \= None > 16label3 \= None > 17fan\_v11\_0 \= None > 18 > 19 > 20def setup(): > 21 global title0, label0, label1, label2, label3, fan\_v11\_0 > 22 > 23 M5.begin() > 24 Widgets.fillScreen(0x222222) > 25 title0 \= Widgets.Title( > 26 "FanModuleV1.1 CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 27 ) > 28 label0 \= Widgets.Label("label0", 0, 57, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label1 \= Widgets.Label("label1", 0, 94, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 label2 \= Widgets.Label("label2", 0, 133, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 31 label3 \= Widgets.Label("label3", 0, 168, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 32 > 33 fan\_v11\_0 \= FanModule(address\=0x18) > 34 fan\_v11\_0.set\_fan\_state(True) > 35 fan\_v11\_0.set\_pwm\_frequency(0) > 36 fan\_v11\_0.set\_pwm\_duty\_cycle(80) > 37 > 38 > 39def loop(): > 40 global title0, label0, label1, label2, label3, fan\_v11\_0 > 41 M5.update() > 42 label0.setText(str((str("Fan State:") + str((fan\_v11\_0.get\_fan\_state()))))) > 43 label1.setText(str((str("Fan PWM Freq:") + str((fan\_v11\_0.get\_single\_frequency()))))) > 44 label2.setText(str((str("Fan PWM duty cycle:") + str((fan\_v11\_0.get\_pwm\_duty\_cycle()))))) > 45 label3.setText(str((str("Fan rpm:") + str((fan\_v11\_0.get\_fan\_rpm()))))) > 46 if M5.Touch.getCount(): > 47 fan\_v11\_0.set\_fan\_state(not (fan\_v11\_0.get\_fan\_state())) > 48 time.sleep\_ms(50) > 49 > 50 > 51if \_\_name\_\_ \== "\_\_main\_\_": > 52 try: > 53 setup() > 54 while True: > 55 loop() > 56 except (Exception, KeyboardInterrupt) as e: > 57 try: > 58 from utility import print\_error\_msg > 59 > 60 print\_error\_msg(e) > 61 except ImportError: > 62 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### FanModule[](#fanmodule "Link to this heading") _class_ module.fan.FanModule(_address\=24_)[](#module.fan.FanModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_ [_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_ [_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) set\_fan\_state(_state_)[](#module.fan.FanModule.set_fan_state "Link to this definition") Set the fan state to on or off. Parameters: **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – The state of the fan. UiFlow2 Code Block: > ![set_fan_state.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/set_fan_state.png) MicroPython Code Block: > fan\_v11\_0.set\_fan\_state(True) get\_fan\_state()[](#module.fan.FanModule.get_fan_state "Link to this definition") Get current fan state. Returns: The current fan state. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![get_fan_state.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_fan_state.png) MicroPython Code Block: > fan\_v11\_0.get\_fan\_state() set\_pwm\_frequency(_freq\=2_)[](#module.fan.FanModule.set_pwm_frequency "Link to this definition") Set the PWM frequency of the fan. Parameters: **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency of the fan. Return type: None UiFlow2 Code Block: > ![set_pwm_frequency.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/set_pwm_frequency.png) MicroPython Code Block: > fan\_v11\_0.set\_pwm\_frequency(2) get\_pwm\_frequency()[](#module.fan.FanModule.get_pwm_frequency "Link to this definition") Get current PWM frequency. Returns: The current PWM frequency. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_pwm_frequency.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_pwm_frequency.png) MicroPython Code Block: > fan\_v11\_0.get\_pwm\_frequency() set\_pwm\_duty\_cycle(_duty\_cycle_)[](#module.fan.FanModule.set_pwm_duty_cycle "Link to this definition") Set the PWM duty cycle of the fan. Parameters: **duty\_cycle** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM duty cycle of the fan. Return type: None UiFlow2 Code Block: > ![set_pwm_duty_cycle.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/set_pwm_duty_cycle.png) MicroPython Code Block: > fan\_v11\_0.set\_pwm\_duty\_cycle(50) get\_pwm\_duty\_cycle()[](#module.fan.FanModule.get_pwm_duty_cycle "Link to this definition") Get current PWM duty cycle. Returns: The current PWM duty cycle. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_pwm_duty_cycle.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_pwm_duty_cycle.png) MicroPython Code Block: > fan\_v11\_0.get\_pwm\_duty\_cycle() get\_fan\_rpm()[](#module.fan.FanModule.get_fan_rpm "Link to this definition") Get current fan RPM. Returns: The current fan RPM. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_fan_rpm.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_fan_rpm.png) MicroPython Code Block: > fan\_v11\_0.get\_fan\_rpm() get\_single\_frequency()[](#module.fan.FanModule.get_single_frequency "Link to this definition") Get current single frequency. Returns: The current single frequency. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_single_frequency.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_single_frequency.png) MicroPython Code Block: > fan\_v11\_0.get\_single\_frequency() write\_flash()[](#module.fan.FanModule.write_flash "Link to this definition") Save the current configuration(fan status, PWM frequency, and PWM duty cycle) to the flash. UiFlow2 Code Block: > ![write_flash.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/write_flash.png) MicroPython Code Block: > fan\_v11\_0.write\_flash() Return type: None get\_firmware\_version()[](#module.fan.FanModule.get_firmware_version "Link to this definition") Get current firmware version. Returns: The current firmware version. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_firmware_version.png) MicroPython Code Block: > fan\_v11\_0.get\_firmware\_version() get\_i2c\_address()[](#module.fan.FanModule.get_i2c_address "Link to this definition") Get current I2C address. Returns: The current I2C address. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/get_i2c_address.png) MicroPython Code Block: > fan\_v11\_0.get\_i2c\_address() set\_i2c\_address(_addr_)[](#module.fan.FanModule.set_i2c_address "Link to this definition") Set the I2C address of the fan. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the fan. Return type: None UiFlow2 Code Block: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/fan_v11/set_i2c_address.png) MicroPython Code Block: > fan\_v11\_0.set\_i2c\_address(0x18) --- # MiniEncoderC Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * MiniEncoderC Hat * [View page source](../_sources/hats/mini_encoder.rst.txt) * * * MiniEncoderC Hat[](#miniencoderc-hat "Link to this heading") ============================================================== The following products are supported: > [![Encoder](https://static-cdn.m5stack.com/resource/docs/products/hat/MiniEncoderC%20Hat/img-a743e8b0-eb5e-4dd7-af11-6d02f3e4680f.webp)](https://docs.m5stack.com/zh_CN/hat/MiniEncoderC%20Hat) 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 hat import MiniEncoderCHat > 10 > 11 > 12title0 \= None > 13circle0 \= None > 14circle1 \= None > 15circle2 \= None > 16label0 \= None > 17i2c0 \= None > 18i2c1 \= None > 19hat\_miniencoderc\_0 \= None > 20 > 21 > 22import math > 23 > 24angle \= None > 25x \= None > 26y \= None > 27direction \= None > 28big\_radius \= None > 29small\_radius \= None > 30 > 31 > 32\# Describe this function... > 33def move\_small\_circle(): > 34 global \\ > 35 angle, \\ > 36 x, \\ > 37 y, \\ > 38 direction, \\ > 39 big\_radius, \\ > 40 small\_radius, \\ > 41 title0, \\ > 42 circle0, \\ > 43 circle1, \\ > 44 circle2, \\ > 45 label0, \\ > 46 i2c0, \\ > 47 i2c1, \\ > 48 hat\_miniencoderc\_0 > 49 angle \= ((hat\_miniencoderc\_0.get\_rotary\_value()) / 58) \* 360 > 50 x \= big\_radius \* math.cos(angle / 180.0 \* math.pi) > 51 y \= big\_radius \* math.sin(angle / 180.0 \* math.pi) > 52 circle0.setCursor(x\=67, y\=120) > 53 circle2.setCursor(x\=(67 + (int(x))), y\=(120 + (int(y)))) > 54 > 55 > 56def setup(): > 57 global \\ > 58 title0, \\ > 59 circle0, \\ > 60 circle1, \\ > 61 circle2, \\ > 62 label0, \\ > 63 i2c0, \\ > 64 i2c1, \\ > 65 hat\_miniencoderc\_0, \\ > 66 angle, \\ > 67 x, \\ > 68 y, \\ > 69 direction, \\ > 70 big\_radius, \\ > 71 small\_radius > 72 > 73 M5.begin() > 74 title0 \= Widgets.Title("Mini Encoder", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 75 circle0 \= Widgets.Circle(67, 120, 50, 0xFFFFFF, 0x000000) > 76 circle1 \= Widgets.Circle(67, 120, 10, 0x00FF00, 0x00FF00) > 77 circle2 \= Widgets.Circle(117, 120, 6, 0xFFFFFF, 0xFFFFFF) > 78 label0 \= Widgets.Label("Count: 0", 4, 213, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 79 > 80 i2c0 \= I2C(0, scl\=Pin(33), sda\=Pin(32), freq\=100000) > 81 i2c1 \= I2C(1, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 82 hat\_miniencoderc\_0 \= MiniEncoderCHat(i2c0, 0x42) > 83 big\_radius \= 50 > 84 small\_radius \= 6 > 85 > 86 > 87def loop(): > 88 global \\ > 89 title0, \\ > 90 circle0, \\ > 91 circle1, \\ > 92 circle2, \\ > 93 label0, \\ > 94 i2c0, \\ > 95 i2c1, \\ > 96 hat\_miniencoderc\_0, \\ > 97 angle, \\ > 98 x, \\ > 99 y, \\ > 100 direction, \\ > 101 big\_radius, \\ > 102 small\_radius > 103 M5.update() > 104 if hat\_miniencoderc\_0.get\_rotary\_status(): > 105 direction \= hat\_miniencoderc\_0.get\_rotary\_increments() > 106 move\_small\_circle() > 107 if direction < 0: > 108 hat\_miniencoderc\_0.fill\_color(0xFF0000) > 109 label0.setText(str((str("Count: ") + str((hat\_miniencoderc\_0.get\_rotary\_value()))))) > 110 elif direction \> 0: > 111 hat\_miniencoderc\_0.fill\_color(0x33FF33) > 112 label0.setText(str((str("Count: ") + str((hat\_miniencoderc\_0.get\_rotary\_value()))))) > 113 else: > 114 hat\_miniencoderc\_0.fill\_color(0x000000) > 115 if hat\_miniencoderc\_0.get\_button\_status(): > 116 circle1.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 117 move\_small\_circle() > 118 hat\_miniencoderc\_0.reset\_rotary\_value() > 119 else: > 120 circle1.setColor(color\=0x00FF00, fill\_c\=0x00FF00) > 121 > 122 > 123if \_\_name\_\_ \== "\_\_main\_\_": > 124 try: > 125 setup() > 126 while True: > 127 loop() > 128 except (Exception, KeyboardInterrupt) as e: > 129 try: > 130 from utility import print\_error\_msg > 131 > 132 print\_error\_msg(e) > 133 except ImportError: > 134 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/example.png) [stickc\_plus2\_mini\_encoder\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/mini_encoder/stickc_plus2_mini_encoder_example.m5f2) class MiniEncoderCHat[](#class-miniencoderchat "Link to this heading") ------------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ MiniEncoderCHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x42_)[](#MiniEncoderCHat "Link to this definition") Creates a Rotary object. Parameters: * **i2c** – I2C object. * **address** – I2C address, Default is 0x40. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- MiniEncoderCHat.get\_rotary\_status() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#MiniEncoderCHat.get_rotary_status "Link to this definition") Gets the rotation status of the Rotary object. UIFLOW2: > ![get_rotary_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/get_rotary_status.png) MiniEncoderCHat.get\_rotary\_value() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniEncoderCHat.get_rotary_value "Link to this definition") Gets the rotation value of the Rotary object. UIFLOW2: > ![get_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/get_rotary_value.png) MiniEncoderCHat.get\_rotary\_increments() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniEncoderCHat.get_rotary_increments "Link to this definition") Gets the rotation increment of the Rotary object. Can be used to determine the direction of rotation. UIFLOW2: > ![get_rotary_increments.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/get_rotary_increments.png) MiniEncoderCHat.reset\_rotary\_value() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniEncoderCHat.reset_rotary_value "Link to this definition") Resets the rotation value of the Rotary object. UIFLOW2: > ![reset_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/reset_rotary_value.png) MiniEncoderCHat.get\_button\_status() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#MiniEncoderCHat.get_button_status "Link to this definition") Get the current status of the rotary encoder keys. UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/get_button_status.png) MiniEncoderCHat.set\_rotary\_value(_new\_value: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniEncoderCHat.set_rotary_value "Link to this definition") Sets the rotation value of the Rotary object. Parameters: **new\_value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – adjust the current value. UIFLOW2: > ![set_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/set_rotary_value.png) MiniEncoderCHat.fill\_color(_rgb: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniEncoderCHat.fill_color "Link to this definition") Set the color of the LED Parameters: **rgb** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the color of the LED, 0x000000 - 0xFFFFFF. UIFLOW2: > ![fill_color.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/fill_color.png) MiniEncoderCHat.read\_fw\_version() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#MiniEncoderCHat.read_fw_version "Link to this definition") Get the firmware version of the device. UIFLOW2: > ![read_fw_version.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/read_fw_version.png) MiniEncoderCHat.set\_address(_address_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniEncoderCHat.set_address "Link to this definition") Set the I2C address of the device. UIFLOW2: > ![set_address.png](https://static-cdn.m5stack.com/mpy_docs/hat/miniencoderc/set_address.png) --- # GatewayH2 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GatewayH2 Module * [View page source](../_sources/module/gateway_h2.rst.txt) * * * GatewayH2 Module[](#gatewayh2-module "Link to this heading") ============================================================== This library is the driver for Module Gateway H2, and the module communicates via UART. Support the following products: > [![Module Gateway H2](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/464/M141_01.webp)](https://docs.m5stack.com/zh_CN/module/Module%20Gateway%20H2) Note When using this module, you need to flash the NCP firmware to the module. For details, refer to the [ESP Zigbee NCP](https://docs.m5stack.com/zh_CN/guide/zigbee/module_gateway_h2/zigbee_ncp) documentation. UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### Switch Control[](#switch-control "Link to this heading") Note To use this example, you need to flash this program onto an ESP32C6 or similar module as a light node device. For details, refer to [HA\_on\_off\_light](https://github.com/espressif/esp-zigbee-sdk/tree/main/examples/esp_zigbee_HA_sample/HA_on_off_light) Open the [cores3\_switch\_endpoint\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/gateway_h2/cores3_switch_endpoint_example.m5f2) project in UiFlow2. The example demonstrates group control and targeted device operation for light nodes through SwitchEndpoint of Gateway H2 module. UiFlow2 Code Block: > ![cores3_switch_endpoint_example.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### Switch Control[](#id1 "Link to this heading") The example demonstrates group control and targeted device operation for light nodes through SwitchEndpoint of Gateway H2 module. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import GatewayH2Module > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label\_addr \= None > 16module\_h2\_0 \= None > 17module\_h2\_0\_ep \= None > 18device\_addr \= None > 19device\_count \= None > 20device\_list \= None > 21 > 22 > 23def first\_index(my\_list, elem): > 24 try: > 25 index \= my\_list.index(elem) + 1 > 26 except: > 27 index \= 0 > 28 return index > 29 > 30 > 31def module\_h2\_0\_ep\_bind\_event(addr): > 32 global \\ > 33 title0, \\ > 34 label0, \\ > 35 label1, \\ > 36 label2, \\ > 37 label\_addr, \\ > 38 module\_h2\_0, \\ > 39 module\_h2\_0\_ep, \\ > 40 device\_addr, \\ > 41 device\_count, \\ > 42 device\_list > 43 device\_addr \= addr > 44 print(device\_addr) > 45 if first\_index(device\_list, device\_addr) \== 0: > 46 device\_list.append(device\_addr) > 47 device\_count \= device\_count + 1 > 48 label\_addr.setText(str((str("new device addr: ") + str(device\_addr)))) > 49 > 50 > 51def btn\_pwr\_was\_clicked\_event(state): > 52 global \\ > 53 title0, \\ > 54 label0, \\ > 55 label1, \\ > 56 label2, \\ > 57 label\_addr, \\ > 58 module\_h2\_0, \\ > 59 module\_h2\_0\_ep, \\ > 60 device\_addr, \\ > 61 device\_count, \\ > 62 device\_list > 63 if not not len(device\_list): > 64 module\_h2\_0\_ep.toggle() > 65 > 66 > 67def setup(): > 68 global \\ > 69 title0, \\ > 70 label0, \\ > 71 label1, \\ > 72 label2, \\ > 73 label\_addr, \\ > 74 module\_h2\_0, \\ > 75 module\_h2\_0\_ep, \\ > 76 device\_addr, \\ > 77 device\_count, \\ > 78 device\_list > 79 > 80 M5.begin() > 81 Widgets.fillScreen(0x222222) > 82 title0 \= Widgets.Title( > 83 "Switch Endpoint Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 84 ) > 85 label0 \= Widgets.Label( > 86 "press the power button toggle", 2, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 87 ) > 88 label1 \= Widgets.Label( > 89 "if has device connect", 2, 26, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 90 ) > 91 label2 \= Widgets.Label( > 92 "connect device: ", 2, 90, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 93 ) > 94 label\_addr \= Widgets.Label("None", 5, 115, 1.0, 0x00FF00, 0x222222, Widgets.FONTS.DejaVu18) > 95 BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btn\_pwr\_was\_clicked\_event) > 96 module\_h2\_0 \= GatewayH2Module(2, 17, 10) > 97 module\_h2\_0\_ep \= module\_h2\_0.create\_switch\_ep() > 98 module\_h2\_0\_ep.set\_bind\_callback(module\_h2\_0\_ep\_bind\_event) > 99 device\_count \= 0 > 100 device\_list \= \[\] > 101 > 102 > 103def loop(): > 104 global \\ > 105 title0, \\ > 106 label0, \\ > 107 label1, \\ > 108 label2, \\ > 109 label\_addr, \\ > 110 module\_h2\_0, \\ > 111 module\_h2\_0\_ep, \\ > 112 device\_addr, \\ > 113 device\_count, \\ > 114 device\_list > 115 M5.update() > 116 > 117 > 118if \_\_name\_\_ \== "\_\_main\_\_": > 119 try: > 120 setup() > 121 while True: > 122 loop() > 123 except (Exception, KeyboardInterrupt) as e: > 124 try: > 125 from utility import print\_error\_msg > 126 > 127 print\_error\_msg(e) > 128 except ImportError: > 129 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### GatewayH2Module[](#gatewayh2module "Link to this heading") _class_ module.gateway\_h2.GatewayH2Module[](#module.gateway_h2.GatewayH2Module "Link to this definition") Create an GatewayH2Module object. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART id. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART TX pin. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART RX pin. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/init.png) MicroPython Code Block: > from module import GatewayH2Module > > module\_gateway\_h2 \= GatewayH2Module(id \= 1, tx \= 10, rx \= 17) create\_switch\_endpoint()[](#module.gateway_h2.GatewayH2Module.create_switch_endpoint "Link to this definition") Create Switch Endpoint. Returns SwitchEndpoint: zigbee switch endpoint object. Return type: SwitchEndpoint UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/init.png) MicroPython Code Block: > h2\_switch\_endpoint \= module\_gateway\_h2.create\_switch\_endpoint() _class_ SwitchEndpoint[](#SwitchEndpoint "Link to this definition") Return by GatewayH2Module.create\_switch\_endpoint() on(\[_addr_\])[](#SwitchEndpoint.on "Link to this definition") Turn on the light. Parameters: **addr** – The device address (optional). * If called as `on()`, turn on all devices. * If called as `on(addr)`, turn on special address devices. UiFlow2 Code Block: > ![on.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/on.png) ![all_on.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/all_on.png) MicroPython Code Block: > h2\_switch\_endpoint.on(addr) > h2\_switch\_endpoint.on() off(\[_addr_\])[](#SwitchEndpoint.off "Link to this definition") Turn off the light. Parameters: **addr** – The device address (optional). * If called as `off()`, turn off all devices. * If called as `off(addr)`, turn off special address devices. UiFlow2 Code Block: > ![off.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/off.png) ![all_off.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/all_off.png) MicroPython Code Block: > h2\_switch\_endpoint.off(addr) > h2\_switch\_endpoint.off() toggle(\[_addr_\])[](#SwitchEndpoint.toggle "Link to this definition") Toggle the light state. Parameters: **addr** – The device address (optional). * If called as `toggle()`, toggle all devices. * If called as `toggle(addr)`, toggle special address devices. UiFlow2 Code Block: > ![toggle.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/toggle.png) ![all_toggle.png](https://static-cdn.m5stack.com/mpy_docs/module/gateway_h2/all_toggle.png) MicroPython Code Block: > h2\_switch\_endpoint.toggle(addr) > h2\_switch\_endpoint.toggle() --- # GNSS Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GNSS Module * [View page source](../_sources/module/gnss.rst.txt) * * * GNSS Module[](#gnss-module "Link to this heading") ==================================================== GNSS Module is a global positioning wireless communication module featuring the NEO-M9N-00B GPS module. It incorporates BMI270, BMM150 and a barometric pressure sensor. Support the following products: [![GNSSModule](https://static-cdn.m5stack.com/resource/docs/products/module/GNSS%20Module/img-87c65bc6-1d16-4078-b0dd-4011cbf04d97.webp)](https://docs.m5stack.com/en/module/GNSS%20Module) 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 module import GNSSModule > 9 > 10 > 11title0 \= None > 12label3 \= None > 13label4 \= None > 14label5 \= None > 15label6 \= None > 16label10 \= None > 17label11 \= None > 18label12 \= None > 19label13 \= None > 20label14 \= None > 21label15 \= None > 22label16 \= None > 23label17 \= None > 24label18 \= None > 25label19 \= None > 26label20 \= None > 27label21 \= None > 28label22 \= None > 29label23 \= None > 30line0 \= None > 31gnss\_0 \= None > 32 > 33 > 34list2 \= None > 35 > 36 > 37def setup(): > 38 global \\ > 39 title0, \\ > 40 label3, \\ > 41 label4, \\ > 42 label5, \\ > 43 label6, \\ > 44 label10, \\ > 45 label11, \\ > 46 label12, \\ > 47 label13, \\ > 48 label14, \\ > 49 label15, \\ > 50 label16, \\ > 51 label17, \\ > 52 label18, \\ > 53 label19, \\ > 54 label20, \\ > 55 label21, \\ > 56 label22, \\ > 57 label23, \\ > 58 line0, \\ > 59 gnss\_0, \\ > 60 list2 > 61 > 62 M5.begin() > 63 Widgets.fillScreen(0x222222) > 64 title0 \= Widgets.Title( > 65 " M135 GNSS Demo", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 66 ) > 67 label3 \= Widgets.Label("angle:", 2, 23, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 68 label4 \= Widgets.Label( > 69 "attitude(yaw):", 1, 73, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 70 ) > 71 label5 \= Widgets.Label("temp:", 4, 128, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 72 label6 \= Widgets.Label("pressure:", 2, 180, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 73 label10 \= Widgets.Label("label10", 4, 46, 1.0, 0x3EF815, 0x222222, Widgets.FONTS.DejaVu18) > 74 label11 \= Widgets.Label("label11", 5, 102, 1.0, 0xF60505, 0x222222, Widgets.FONTS.DejaVu18) > 75 label12 \= Widgets.Label("label12", 5, 154, 1.0, 0x3EF815, 0x222222, Widgets.FONTS.DejaVu18) > 76 label13 \= Widgets.Label("label13", 5, 208, 1.0, 0xF60505, 0x222222, Widgets.FONTS.DejaVu18) > 77 label14 \= Widgets.Label("lat:", 158, 51, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 78 label15 \= Widgets.Label("long:", 157, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 79 label16 \= Widgets.Label("sta:", 158, 24, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 80 label17 \= Widgets.Label("date:", 158, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 81 label18 \= Widgets.Label("time:", 159, 168, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 82 label19 \= Widgets.Label("label19", 159, 138, 1.0, 0x15F0FF, 0x222222, Widgets.FONTS.DejaVu18) > 83 label20 \= Widgets.Label("label20", 159, 197, 1.0, 0xEAFF00, 0x222222, Widgets.FONTS.DejaVu18) > 84 label21 \= Widgets.Label("label21", 205, 25, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 85 label22 \= Widgets.Label("label22", 205, 52, 1.0, 0x15F0FF, 0x222222, Widgets.FONTS.DejaVu18) > 86 label23 \= Widgets.Label("label23", 205, 81, 1.0, 0xEAFF00, 0x222222, Widgets.FONTS.DejaVu18) > 87 line0 \= Widgets.Line(142, 27, 142, 232, 0xFFFFFF) > 88 > 89 gnss\_0 \= GNSSModule(2, 13, 14, 0x69) > 90 > 91 > 92def loop(): > 93 global \\ > 94 title0, \\ > 95 label3, \\ > 96 label4, \\ > 97 label5, \\ > 98 label6, \\ > 99 label10, \\ > 100 label11, \\ > 101 label12, \\ > 102 label13, \\ > 103 label14, \\ > 104 label15, \\ > 105 label16, \\ > 106 label17, \\ > 107 label18, \\ > 108 label19, \\ > 109 label20, \\ > 110 label21, \\ > 111 label22, \\ > 112 label23, \\ > 113 line0, \\ > 114 gnss\_0, \\ > 115 list2 > 116 M5.update() > 117 label10.setText(str(gnss\_0.get\_compass())) > 118 label11.setText(str((gnss\_0.get\_attitude())\[0\])) > 119 label12.setText(str(gnss\_0.get\_temperature())) > 120 label13.setText(str(gnss\_0.get\_pressure())) > 121 if gnss\_0.is\_locate\_valid(): > 122 label21.setText(str("OK")) > 123 else: > 124 label21.setText(str("Failed")) > 125 label22.setText(str(gnss\_0.get\_latitude())) > 126 label23.setText(str(gnss\_0.get\_longitude())) > 127 label19.setText(str(gnss\_0.get\_date())) > 128 label20.setText(str(gnss\_0.get\_time())) > 129 > 130 > 131if \_\_name\_\_ \== "\_\_main\_\_": > 132 try: > 133 setup() > 134 while True: > 135 loop() > 136 except (Exception, KeyboardInterrupt) as e: > 137 try: > 138 from utility import print\_error\_msg > 139 > 140 print\_error\_msg(e) > 141 except ImportError: > 142 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/example.png) [gnss\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/gnss/gnss_core2_example.m5f2) class GNSSModule[](#class-gnssmodule "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ GNSSModule(_id_, _rx_, _tx_, _address_)[](#GNSSModule "Link to this definition") initialize Function. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART controllers id, the range is 0 to 2. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART rx pin. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART tx pin. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- GNSSModule.set\_accel\_gyro\_odr(_accel\_odr_, _gyro\_odr_)[](#GNSSModule.set_accel_gyro_odr "Link to this definition") Set the accelerometer and gyroscope output data rate. Parameters: * **accel\_odr** – range of 0.78 Hz … 1.6 kHz. Options: - `25`: 25 - `50`: 50 - `100`: 100 - `200`: 200 - `400`: 400 - `800`: 800 - `1600`: 1600 - `0.78`: 0.78 - `1.5`: 1.5 - `3.1`: 3.1 - `6.25`: 6.25 - `12.5`: 12.5 * **gyro\_odr** – range of 25 Hz … 6.4 kHz. Options: - `25`: 25 - `50`: 50 - `100`: 100 - `200`: 200 - `400`: 400 - `800`: 800 - `1600`: 1600 - `3200`: 3200 UIFLOW2: > ![set_accel_gyro_odr.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_accel_gyro_odr.png) GNSSModule.set\_accel\_range(_accel\_scale_)[](#GNSSModule.set_accel_range "Link to this definition") Set the accelerometer scale range. Parameters: **accel\_scale** – scale range of ±2g, ±4g, ±8g and ±16g. Options: - `2`: 2 - `4`: 4 - `8`: 8 - `16`: 16 UIFLOW2: > ![set_accel_range.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_accel_range.png) GNSSModule.set\_gyro\_range(_gyro\_scale_)[](#GNSSModule.set_gyro_range "Link to this definition") Set the gyroscope scale range. Parameters: **gyro\_scale** – Options: - `125`: 125 - `250`: 250 - `500`: 500 - `1000`: 1000 - `2000`: 2000 UIFLOW2: > ![set_gyro_range.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_gyro_range.png) GNSSModule.set\_magnet\_odr(_magnet\_odr_)[](#GNSSModule.set_magnet_odr "Link to this definition") Parameters: **magnet\_odr** – Options: - `2`: 2 - `6`: 6 - `8`: 8 - `10`: 10 - `15`: 15 - `20`: 20 - `25`: 25 - `30`: 30 UIFLOW2: > ![set_magnet_odr.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_magnet_odr.png) GNSSModule.set\_gyro\_offsets(_x_, _y_, _z_)[](#GNSSModule.set_gyro_offsets "Link to this definition") Set the manual gyro calibrations offsets value. Parameters: * **x** – gyro calibrations offsets value of X-axis * **y** – gyro calibrations offsets value of Y-axis * **z** – gyro calibrations offsets value of Z-axis UIFLOW2: > ![set_gyro_offsets.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_gyro_offsets.png) GNSSModule.get\_gyroscope()[](#GNSSModule.get_gyroscope "Link to this definition") Get the tuple of x, y, and z values of the gyroscope and gyroscope vector in rad/sec. Return (tuple): gyroscope tuple (float, float, float) UIFLOW2: > ![get_gyroscope.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_gyroscope.png) GNSSModule.get\_accelerometer()[](#GNSSModule.get_accelerometer "Link to this definition") Get the tuple of x, y, and z values of the accelerometer and acceleration vector in gravity units (9.81m/s^2). Return (tuple): accelerometer tuple (float, float, float) UIFLOW2: > ![get_accelerometer.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_accelerometer.png) GNSSModule.get\_magnetometer()[](#GNSSModule.get_magnetometer "Link to this definition") Get the tuple of x, y, and z values of the magnetometer and magnetometer vector in uT. Return (tuple): magnetometer tuple (float, float, float) UIFLOW2: > ![get_magnetometer.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_magnetometer.png) GNSSModule.get\_compass()[](#GNSSModule.get_compass "Link to this definition") Get the compass heading value is in range of 0º ~ 360º. Return (float): range is 0 to 360 degree UIFLOW2: > ![get_compass.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_compass.png) GNSSModule.get\_attitude()[](#GNSSModule.get_attitude "Link to this definition") Get the attitude angles as yaw, pitch, and roll in degrees. Return (tuple): tuple of yaw, pitch, and roll (float, float, float) UIFLOW2: > ![get_attitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_attitude.png) GNSSModule.get\_temperature()[](#GNSSModule.get_temperature "Link to this definition") Get the temperature value in degrees celsius from the BMP280 sensor. Return (float): range is -40 ~ +85 °C. UIFLOW2: > ![get_temperature.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_temperature.png) GNSSModule.get\_pressure()[](#GNSSModule.get_pressure "Link to this definition") Get the pressure value in pascals from the BMP280 sensor. Return (float): range is 300 ~ 1100 hPa. UIFLOW2: > ![get_pressure.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_pressure.png) GNSSModule.set\_time\_zone(_value_)[](#GNSSModule.set_time_zone "Link to this definition") set timezone function. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – timezone value UIFLOW2: > ![set_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/set_time_zone.png) GNSSModule.get\_time\_zone()[](#GNSSModule.get_time_zone "Link to this definition") get timezone function. Return (int): timezone value UIFLOW2: > ![get_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_time_zone.png) GNSSModule.get\_satellite\_num()[](#GNSSModule.get_satellite_num "Link to this definition") get satellite numbers. Return (str): satellite numbers value. UIFLOW2: > ![get_satellite_num.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_satellite_num.png) GNSSModule.get\_altitude()[](#GNSSModule.get_altitude "Link to this definition") get altitude. Return (str): altitude unit is meter. UIFLOW2: > ![get_altitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_altitude.png) GNSSModule.get\_time()[](#GNSSModule.get_time "Link to this definition") get time. Return (str): time(hh:mm:ss) UIFLOW2: > ![get_time.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_time.png) GNSSModule.get\_date()[](#GNSSModule.get_date "Link to this definition") get date. Return (str): date(dd/mm/yy) UIFLOW2: > ![get_date.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_date.png) GNSSModule.get\_latitude()[](#GNSSModule.get_latitude "Link to this definition") get latitude. Return (str): latitude, using degrees minutes format (ddmm.mmmmmN/S). UIFLOW2: > ![get_latitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_latitude.png) GNSSModule.get\_longitude()[](#GNSSModule.get_longitude "Link to this definition") get longitude. Return (str): longitude, using degrees minutes format (ddmm.mmmmmE/W). UIFLOW2: > ![get_longitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_longitude.png) GNSSModule.get\_latitude\_decimal()[](#GNSSModule.get_latitude_decimal "Link to this definition") get latitude decimal. Return (float): latitude decimal(dd.dddd). UIFLOW2: > ![get_latitude_decimal.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_latitude_decimal.png) GNSSModule.get\_longitude\_decimal()[](#GNSSModule.get_longitude_decimal "Link to this definition") get longitude decimal. Return (float): longitude decimal(dd.dddd). UIFLOW2: > ![get_longitude_decimal.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_longitude_decimal.png) GNSSModule.get\_speed(_type_)[](#GNSSModule.get_speed "Link to this definition") get speed. Return (str): speed. Parameters: **type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – speed type, 0 km/h, 1 knot/h Options: - `km/h`: 0 - `knot/h`: 1 UIFLOW2: > ![get_speed.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_speed.png) GNSSModule.get\_course()[](#GNSSModule.get_course "Link to this definition") get course. Return (str): course unit is °. UIFLOW2: > ![get_course.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/get_course.png) GNSSModule.is\_locate\_valid()[](#GNSSModule.is_locate_valid "Link to this definition") get locate status. Return (bool): locate status, true is locate, false is not locate. UIFLOW2: > ![is_locate_valid.png](https://static-cdn.m5stack.com/mpy_docs/module/gnss/is_locate_valid.png) --- # MiniJoyC Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * MiniJoyC Hat * [View page source](../_sources/hats/mini_joy.rst.txt) * * * MiniJoyC Hat[](#minijoyc-hat "Link to this heading") ====================================================== The following products are supported: > [![MiniJoyCHat](https://static-cdn.m5stack.com/resource/docs/products/hat/MiniJoyC/img-5f9e97ba-2ad4-482a-8ed0-5c5551514558.webp)](https://docs.m5stack.com/en/hat/MiniJoyC) 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 hat import MiniJoyHat > 10 > 11 > 12circle0 \= None > 13circle1 \= None > 14label0 \= None > 15label1 \= None > 16label2 \= None > 17label3 \= None > 18i2c0 \= None > 19hat\_minijoyc\_0 \= None > 20 > 21 > 22x \= None > 23value \= None > 24in\_min \= None > 25in\_max \= None > 26out\_min \= None > 27out\_range \= None > 28y \= None > 29last\_x \= None > 30last\_y \= None > 31 > 32 > 33\# Describe this function... > 34def map\_to\_range(value, in\_min, in\_max, out\_min, out\_range): > 35 global \\ > 36 x, \\ > 37 y, \\ > 38 last\_x, \\ > 39 last\_y, \\ > 40 circle0, \\ > 41 circle1, \\ > 42 label0, \\ > 43 label1, \\ > 44 label2, \\ > 45 label3, \\ > 46 i2c0, \\ > 47 hat\_minijoyc\_0 > 48 return int((value \- in\_min) \* out\_range / (in\_max \- in\_min) + out\_min) > 49 > 50 > 51def setup(): > 52 global \\ > 53 circle0, \\ > 54 circle1, \\ > 55 label0, \\ > 56 label1, \\ > 57 label2, \\ > 58 label3, \\ > 59 i2c0, \\ > 60 hat\_minijoyc\_0, \\ > 61 x, \\ > 62 out\_range, \\ > 63 out\_min, \\ > 64 y, \\ > 65 value, \\ > 66 in\_min, \\ > 67 in\_max, \\ > 68 last\_x, \\ > 69 last\_y > 70 > 71 M5.begin() > 72 circle0 \= Widgets.Circle(67, 120, 50, 0xFFFFFF, 0x000000) > 73 circle1 \= Widgets.Circle(67, 120, 4, 0xFFFFFF, 0xFFFFFF) > 74 label0 \= Widgets.Label("X:", 6, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 75 label1 \= Widgets.Label("Y:", 6, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 76 label2 \= Widgets.Label("0", 25, 185, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 77 label3 \= Widgets.Label("0", 21, 212, 1.0, 0x74F707, 0x222222, Widgets.FONTS.DejaVu18) > 78 > 79 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 80 hat\_minijoyc\_0 \= MiniJoyHat(i2c0, 0x54) > 81 hat\_minijoyc\_0.swap\_y(True) > 82 last\_x \= 67 > 83 last\_y \= 120 > 84 > 85 > 86def loop(): > 87 global \\ > 88 circle0, \\ > 89 circle1, \\ > 90 label0, \\ > 91 label1, \\ > 92 label2, \\ > 93 label3, \\ > 94 i2c0, \\ > 95 hat\_minijoyc\_0, \\ > 96 x, \\ > 97 out\_range, \\ > 98 out\_min, \\ > 99 y, \\ > 100 value, \\ > 101 in\_min, \\ > 102 in\_max, \\ > 103 last\_x, \\ > 104 last\_y > 105 M5.update() > 106 x \= last\_x + map\_to\_range(hat\_minijoyc\_0.get\_x(), \-128, 127, \-43, 86) > 107 y \= last\_y + map\_to\_range(hat\_minijoyc\_0.get\_y(), \-128, 127, \-43, 86) > 108 circle1.setCursor(x\=x, y\=y) > 109 if hat\_minijoyc\_0.get\_button\_status(): > 110 circle1.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 111 else: > 112 circle1.setColor(color\=0xFFFFFF, fill\_c\=0x6600CC) > 113 label2.setText(str(hat\_minijoyc\_0.get\_x())) > 114 label3.setText(str(hat\_minijoyc\_0.get\_y())) > 115 > 116 > 117if \_\_name\_\_ \== "\_\_main\_\_": > 118 try: > 119 setup() > 120 while True: > 121 loop() > 122 except (Exception, KeyboardInterrupt) as e: > 123 try: > 124 from utility import print\_error\_msg > 125 > 126 print\_error\_msg(e) > 127 except ImportError: > 128 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/example.png) [stickc\_plus2\_mini\_joy\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/mini_joy/stickc_plus2_mini_joy_example.m5f2) class MiniJoyHat[](#class-minijoyhat "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ MiniJoyHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x38_)[](#MiniJoyHat "Link to this definition") Create a new instance of the MiniJoyHat class. Parameters: * **i2c** – I2C bus * **address** – I2C address UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- MiniJoyHat.get\_x\_raw() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniJoyHat.get_x_raw "Link to this definition") Get the raw x-axis value. Returns: x-axis value UIFLOW2: > ![get_x_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_x_raw.png) MiniJoyHat.get\_y\_raw() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniJoyHat.get_y_raw "Link to this definition") Get the raw y-axis value. Returns: y-axis value UIFLOW2: > ![get_y_raw.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_y_raw.png) MiniJoyHat.get\_x() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniJoyHat.get_x "Link to this definition") Get the x-axis value. Returns: x-axis value UIFLOW2: > ![get_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_x.png) MiniJoyHat.get\_y() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#MiniJoyHat.get_y "Link to this definition") Get the y-axis value. Returns: y-axis value UIFLOW2: > ![get_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_y.png) MiniJoyHat.swap\_x(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniJoyHat.swap_x "Link to this definition") Swap x-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_x.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/swap_x.png) MiniJoyHat.swap\_y(_swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniJoyHat.swap_y "Link to this definition") Swap y-axis direction Parameters: **swap** – True or False UIFLOW2: > ![swap_y.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/swap_y.png) MiniJoyHat.get\_button\_status() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#MiniJoyHat.get_button_status "Link to this definition") Get the button status. Returns: True or False UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_button_status.png) MiniJoyHat.get\_firmware\_version() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#MiniJoyHat.get_firmware_version "Link to this definition") Get the firmware version. Returns: firmware version UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/get_firmware_version.png) MiniJoyHat.set\_i2c\_address(_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#MiniJoyHat.set_i2c_address "Link to this definition") Set the I2C address. Parameters: **address** – 0x01 ~ 0x7F UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/hat/minijoyc/set_i2c_address.png) --- # NCIR Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * NCIR Hat * [View page source](../_sources/hats/ncir.rst.txt) * * * NCIR Hat[](#ncir-hat "Link to this heading") ============================================== The following products are supported: > [![NCIRHAT](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-ncir/hat-ncir_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat-ncir) 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 hat import NCIRHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_ncir\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, hat\_ncir\_0 > 19 > 20 M5.begin() > 21 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 24 hat\_ncir\_0 \= NCIRHat(i2c0) > 25 > 26 > 27def loop(): > 28 global label0, i2c0, hat\_ncir\_0 > 29 M5.update() > 30 label0.setText(str(hat\_ncir\_0.get\_object\_temperature())) > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/ncir/example.png) [stickc\_plus2\_ncir\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/ncir/stickc_plus2_ncir_example.m5f2) class NCIRHat[](#class-ncirhat "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ NCIRHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x5A_)[](#NCIRHat "Link to this definition") Create a NCIRHat object. Parameters: * **i2c** – I2C object * **address** – the I2C address of the device. Default is 0x5A. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/ncir/init.png) NCIRHat class inherits NCIRUnit class, See [unit.NCIRUnit.Methods](../units/ncir.html#unit-ncirunit-methods) for more details. --- # GPS Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GPS Module * [View page source](../_sources/module/gps.rst.txt) * * * GPS Module[](#gps-module "Link to this heading") ================================================== COM.GPS is a satellite positioning module in the M5Stack stacking module series. It is developed based on the NEO-M8N module. Support the following products: > | | | > | --- | --- | > | [![GPSModule](https://static-cdn.m5stack.com/resource/docs/products/module/gps/gps_01.webp)](https://docs.m5stack.com/en/module/gps) | [![COM.GPSModule](https://static-cdn.m5stack.com/resource/docs/products/module/comx_gps/comx_gps_01.webp)](https://docs.m5stack.com/en/module/comx_gps) | Micropython Example: > 1import os, sys, io > 2import M5 > 3from M5 import \* > 4from module import GPSModule > 5 > 6 > 7GPST \= None > 8label0 \= None > 9label1 \= None > 10label2 \= None > 11label3 \= None > 12label4 \= None > 13label5 \= None > 14label6 \= None > 15label7 \= None > 16label8 \= None > 17label9 \= None > 18label10 \= None > 19label11 \= None > 20com\_gps\_0 \= None > 21 > 22 > 23def setup(): > 24 global \\ > 25 GPST, \\ > 26 label0, \\ > 27 label1, \\ > 28 label2, \\ > 29 label3, \\ > 30 label4, \\ > 31 label5, \\ > 32 label6, \\ > 33 label7, \\ > 34 label8, \\ > 35 label9, \\ > 36 label10, \\ > 37 label11, \\ > 38 com\_gps\_0 > 39 > 40 M5.begin() > 41 Widgets.fillScreen(0x222222) > 42 GPST \= Widgets.Title( > 43 " GPS Module Demo", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 44 ) > 45 label0 \= Widgets.Label( > 46 "Locate status:", 10, 27, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 47 ) > 48 label1 \= Widgets.Label( > 49 "Satellite nums:", 2, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 50 ) > 51 label2 \= Widgets.Label("Longitude:", 40, 105, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 52 label3 \= Widgets.Label("Latitude:", 56, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 53 label4 \= Widgets.Label("Date:", 85, 131, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 54 label5 \= Widgets.Label("Time:", 83, 159, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 55 label6 \= Widgets.Label("label6", 150, 28, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 56 label7 \= Widgets.Label("label7", 150, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 57 label8 \= Widgets.Label("label8", 150, 79, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 58 label9 \= Widgets.Label("label9", 150, 107, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 59 label10 \= Widgets.Label("label10", 150, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 60 label11 \= Widgets.Label("label11", 150, 160, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 61 > 62 com\_gps\_0 \= GPSModule(2, 13, 14) > 63 com\_gps\_0.set\_time\_zone(8) > 64 > 65 > 66def loop(): > 67 global \\ > 68 GPST, \\ > 69 label0, \\ > 70 label1, \\ > 71 label2, \\ > 72 label3, \\ > 73 label4, \\ > 74 label5, \\ > 75 label6, \\ > 76 label7, \\ > 77 label8, \\ > 78 label9, \\ > 79 label10, \\ > 80 label11, \\ > 81 com\_gps\_0 > 82 M5.update() > 83 if com\_gps\_0.is\_locate\_valid(): > 84 label6.setText(str("OK")) > 85 else: > 86 label6.setText(str("False")) > 87 label7.setText(str(com\_gps\_0.get\_satellite\_num())) > 88 label8.setText(str(com\_gps\_0.get\_latitude())) > 89 label9.setText(str(com\_gps\_0.get\_longitude())) > 90 label10.setText(str(com\_gps\_0.get\_date())) > 91 label11.setText(str(com\_gps\_0.get\_time())) > 92 > 93 > 94if \_\_name\_\_ \== "\_\_main\_\_": > 95 try: > 96 setup() > 97 while True: > 98 loop() > 99 except (Exception, KeyboardInterrupt) as e: > 100 try: > 101 from utility import print\_error\_msg > 102 > 103 print\_error\_msg(e) > 104 except ImportError: > 105 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/example.png) [gps\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/gps/gps_core2_example.m5f2) class GPSModule[](#class-gpsmodule "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ GPSModule(_id_, _rx_, _tx_)[](#GPSModule "Link to this definition") initialize Function. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART controllers id, the range is 0 to 2. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART rx pin. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART tx pin. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- GPSModule.set\_time\_zone(_value_)[](#GPSModule.set_time_zone "Link to this definition") set timezone function. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – timezone value UIFLOW2: > ![set_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/set_time_zone.png) GPSModule.get\_time\_zone()[](#GPSModule.get_time_zone "Link to this definition") get timezone function. Return (int): timezone value UIFLOW2: > ![get_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_time_zone.png) GPSModule.get\_satellite\_num()[](#GPSModule.get_satellite_num "Link to this definition") get satellite numbers. Return (str): satellite numbers value. UIFLOW2: > ![get_satellite_num.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_satellite_num.png) GPSModule.get\_altitude()[](#GPSModule.get_altitude "Link to this definition") get altitude. Return (str): altitude unit is meter. UIFLOW2: > ![get_altitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_altitude.png) GPSModule.get\_time()[](#GPSModule.get_time "Link to this definition") get time. Return (str): time(hh:mm:ss) UIFLOW2: > ![get_time.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_time.png) GPSModule.get\_date()[](#GPSModule.get_date "Link to this definition") get date. Return (str): date(dd/mm/yy) UIFLOW2: > ![get_date.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_date.png) GPSModule.get\_latitude()[](#GPSModule.get_latitude "Link to this definition") get latitude. Return (str): latitude, using degrees minutes format (ddmm.mmmmmN/S). UIFLOW2: > ![get_latitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_latitude.png) GPSModule.get\_longitude()[](#GPSModule.get_longitude "Link to this definition") get longitude. Return (str): longitude, using degrees minutes format (ddmm.mmmmmE/W). UIFLOW2: > ![get_longitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_longitude.png) GPSModule.get\_latitude\_decimal()[](#GPSModule.get_latitude_decimal "Link to this definition") get latitude decimal. Return (float): latitude decimal(dd.dddd). UIFLOW2: > ![get_latitude_decimal.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_latitude_decimal.png) GPSModule.get\_longitude\_decimal()[](#GPSModule.get_longitude_decimal "Link to this definition") get longitude decimal. Return (float): longitude decimal(dd.dddd). UIFLOW2: > ![get_longitude_decimal.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_longitude_decimal.png) GPSModule.get\_speed(_type_)[](#GPSModule.get_speed "Link to this definition") get speed. Return (str): speed. Parameters: **type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – speed type, 0 km/h, 1 knot/h Options: - `km/h`: 0 - `knot/h`: 1 UIFLOW2: > ![get_speed.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_speed.png) GPSModule.get\_course()[](#GPSModule.get_course "Link to this definition") get course. Return (str): course unit is °. UIFLOW2: > ![get_course.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/get_course.png) GPSModule.is\_locate\_valid()[](#GPSModule.is_locate_valid "Link to this definition") get locate status. Return (bool): locate status, true is locate, false is not locate. UIFLOW2: > ![is_locate_valid.png](https://static-cdn.m5stack.com/mpy_docs/module/gps/is_locate_valid.png) --- # Atomic TFCard Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic TFCard Base * [View page source](../_sources/base/tfcard.rst.txt) * * * Atomic TFCard Base[](#atomic-tfcard-base "Link to this heading") ================================================================== This is the driver library for the Atomic TFCard Base, which is used to mount TFCard. Support the following products: > | | | > | --- | --- | > | [![Atom TFCard](https://static-cdn.m5stack.com/resource/docs/products/atom/atomictf/atomictf_01.webp)](https://docs.m5stack.com/en/atom/atomictf) | [![Atomic TFCard Base](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20TF-Card%20Reader/img-f481a189-c8a3-4b21-8bde-24a6a8b4131d.webp)](https://docs.m5stack.com/en/atom/Atomic%20TF-Card%20Reader) | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### TFCard mount[](#tfcard-mount "Link to this heading") Open the [atoms3r\_tfcard\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/tfcard/atoms3r_tfcard_example.m5f2) project in UiFlow2. This example demonstrates how to read/create a directory using Atomic TFCard Base. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/tfcard/example.png) Example output: > Files in the /sd directory. MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### TFCard mount[](#id1 "Link to this heading") This example demonstrates how to read/create a directory using Atomic TFCard Base. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import AtomicTFCardBase > 9import time > 10 > 11 > 12title0 \= None > 13base\_tfcard \= None > 14 > 15 > 16def setup(): > 17 global title0, base\_tfcard > 18 > 19 M5.begin() > 20 title0 \= Widgets.Title("TFCard e.g.", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 21 > 22 base\_tfcard \= AtomicTFCardBase(slot\=3, width\=1, sck\=7, miso\=8, mosi\=6, freq\=1000000) > 23 os.chdir("/sd") > 24 print((str("Current dir:") + str((os.getcwd())))) > 25 print((str("list /sd/dir: ") + str((os.listdir("/sd/"))))) > 26 if not ("sdcard\_test" in os.listdir("/sd/")): \# noqa: E713 > 27 print("Try create 'sdcard\_test' directory in /sd/") > 28 os.mkdir("/sd/sdcard\_test") > 29 print((str("'sdcard\_test' is directory?:") + str((os.stat("/sd/sdcard\_test")\[0\] \== 0x4000)))) > 30 print((str("'sdcard\_test' is file?:") + str((os.stat("/sd/sdcard\_test")\[0\] \== 0x8000)))) > 31 print("Delay 1s to delete 'sdcard\_test' directory") > 32 time.sleep(1) > 33 os.rmdir("/sd/sdcard\_test") > 34 if not ("sdcard\_test" in os.listdir("/sd/")): \# noqa: E713 > 35 print("Directory 'sdcard\_test' deleted successfully") > 36 > 37 > 38def loop(): > 39 global title0, base\_tfcard > 40 M5.update() > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Example output: > Files in the /sd directory. **API**[](#api "Link to this heading") ---------------------------------------- ### function AtomicTFCardBase[](#function-atomictfcardbase "Link to this heading") AtomicTFCardBase(_slot\=1_, _width\=1_, _cd\=None_, _wp\=None_, _sck\=None_, _miso\=None_, _mosi\=None_, _cs\=None_, _freq\=20000000_)[](#AtomicTFCardBase "Link to this definition") This function is only used to initialize and mount the SD card to the /sd directory, and to try to unmount the existing SD card before mounting it. Other file operations (such as reading/writing files, creating directories, etc.) need to be performed by the os module. Parameters: * **slot** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Which of the available interfaces to use. The default value is 1. * **width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The bus width for the SD/MMC interface. The default value is 1. * **cd** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The card-detect pin to use. The default value is None. * **wp** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The write-protect pin to use. The default value is None. * **sck** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SPI clock pin to use. The default value is None. * **miso** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SPI miso pin to use. The default value is None. * **mosi** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SPI mosi pin to use. The default value is None. * **cs** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SPI chip select pin to use. The default value is None. * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The SD/MMC interface frequency in Hz. The default value is 20000000. Returns: None UiFlow2 Code Block: > ![init.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/tfcard/init.png) MicroPython Code Block: > from base import AtomicTFCardBase > base\_tfcard \= AtomicTFCardBase(slot\=3, width\=1, sck\=7, miso\=8, mosi\=6, freq\=20000000) See [`os`](https://docs.micropython.org/en/v1.22.0/library/os.html#module-os "(in MicroPython vv1.22.0)") – basic “operating system” for more details. --- # GPS V2.0 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GPS V2.0 Module * [View page source](../_sources/module/gpsv2.rst.txt) * * * GPS V2.0 Module[](#gps-v2-0-module "Link to this heading") ============================================================ Module GPS v2.0 is a high-performance GNSS global positioning module, integrated with the high-performance AT6668 chip to provide precise and reliable satellite positioning services. This module supports multi-frequency, multi-mode GNSS signal reception and is compatible with various satellite navigation systems, including GPS, BD2, BD3, GLONASS, GALILEO, and QZSS, enabling high-precision, multi-system joint positioning or single-system independent positioning, and offering excellent anti-jamming capabilities. In weak signal areas, it can quickly acquire higher precision positioning information. The module comes equipped with an external SMA antenna, and also features a dip switch to allow users to flexibly switch TX/RX communication pins, with PPS signal output for precise timing adjustments. It supports multi-stack usage, offering more customization and flexibility, making it suitable for high-precision positioning applications such as in-vehicle navigation, IoT positioning devices, remote monitoring, smart cities, and home and industrial automation. Support the following products: > [![GPSV2Module](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/module/Module%20GPS%20v2.0/4.webp)](https://docs.m5stack.com/en/module/Module%20GPS%20v2.0) 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 module import GPSV2Module > 9import time > 10 > 11 > 12label0 \= None > 13title0 \= None > 14label1 \= None > 15label2 \= None > 16label3 \= None > 17label4 \= None > 18label5 \= None > 19label6 \= None > 20module\_gpsv2\_0 \= None > 21 > 22 > 23power\_on\_time \= None > 24 > 25 > 26def setup(): > 27 global \\ > 28 label0, \\ > 29 title0, \\ > 30 label1, \\ > 31 label2, \\ > 32 label3, \\ > 33 label4, \\ > 34 label5, \\ > 35 label6, \\ > 36 module\_gpsv2\_0, \\ > 37 power\_on\_time > 38 > 39 M5.begin() > 40 Widgets.fillScreen(0x222222) > 41 label0 \= Widgets.Label("Power On:", 1, 33, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 42 title0 \= Widgets.Title( > 43 "GPSV2Module Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 44 ) > 45 label1 \= Widgets.Label( > 46 "Satellite Num:", 1, 66, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 47 ) > 48 label2 \= Widgets.Label("Timestamp:", 1, 202, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 49 label3 \= Widgets.Label("GPS Data:", \-6, 526, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 50 label4 \= Widgets.Label("Latitude:", 1, 104, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 51 label5 \= Widgets.Label("Longitude:", 1, 140, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 52 label6 \= Widgets.Label("Altitude:", 1, 170, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 53 > 54 module\_gpsv2\_0 \= GPSV2Module(2, 13, 14, 25) > 55 power\_on\_time \= time.time() > 56 module\_gpsv2\_0.set\_work\_mode(7) > 57 > 58 > 59def loop(): > 60 global \\ > 61 label0, \\ > 62 title0, \\ > 63 label1, \\ > 64 label2, \\ > 65 label3, \\ > 66 label4, \\ > 67 label5, \\ > 68 label6, \\ > 69 module\_gpsv2\_0, \\ > 70 power\_on\_time > 71 M5.update() > 72 label0.setText(str((str("Power On:") + str(((time.time()) \- power\_on\_time))))) > 73 label1.setText(str((str("Satellite Num:") + str((module\_gpsv2\_0.get\_satellite\_num()))))) > 74 label2.setText(str((str("Timestamp:") + str((module\_gpsv2\_0.get\_timestamp()))))) > 75 label4.setText(str((str("Latitude:") + str((module\_gpsv2\_0.get\_latitude()))))) > 76 label5.setText(str((str("Longitude:") + str((module\_gpsv2\_0.get\_longitude()))))) > 77 label6.setText(str((str("Altitude:") + str((module\_gpsv2\_0.get\_altitude()))))) > 78 time.sleep(1) > 79 > 80 > 81if \_\_name\_\_ \== "\_\_main\_\_": > 82 try: > 83 setup() > 84 while True: > 85 loop() > 86 except (Exception, KeyboardInterrupt) as e: > 87 try: > 88 from utility import print\_error\_msg > 89 > 90 print\_error\_msg(e) > 91 except ImportError: > 92 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/example.png) [gpsv2\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/gpsv2/gpsv2_core2_example.m5f2) class GPSV2Module[](#class-gpsv2module "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ GPSV2Module(_id_, _rx_, _tx_)[](#GPSV2Module "Link to this definition") Initialize the GPSV2Module with a specific UART id and port for communication. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART ID for communication with the GPS module. It can be 0, 1, or 2. * **rx** – The RX pin of the UART. * **tx** – The TX pin of the UART. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- GPSV2Module.set\_work\_mode(_mode_)[](#GPSV2Module.set_work_mode "Link to this definition") Set the working mode of the GPS module. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The mode to set, defined by the GPS module. UIFLOW2: > ![set_work_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/set_work_mode.png) GPSV2Module.get\_work\_mode()[](#GPSV2Module.get_work_mode "Link to this definition") Get the current working mode of the GPS module. Returns: The current working mode of the GPS module. UIFLOW2: > ![get_work_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_work_mode.png) GPSV2Module.get\_antenna\_state()[](#GPSV2Module.get_antenna_state "Link to this definition") Get the state of the antenna. Returns: The antenna state. UIFLOW2: > ![get_antenna_state.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_antenna_state.png) GPSV2Module.get\_gps\_time()[](#GPSV2Module.get_gps_time "Link to this definition") Get the current GPS time. Returns: The GPS time as a list of strings \[hour, minute, second\]. UIFLOW2: > ![get_gps_time.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_gps_time.png) GPSV2Module.get\_gps\_date()[](#GPSV2Module.get_gps_date "Link to this definition") Get the current GPS date. Returns: The GPS date as a list of strings \[day, month, year\]. UIFLOW2: > ![get_gps_date.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_gps_date.png) GPSV2Module.get\_gps\_date\_time()[](#GPSV2Module.get_gps_date_time "Link to this definition") Get the current GPS date and time combined. Returns: The GPS date and time as a list of strings \[year, month, day, hour, minute, second\]. UIFLOW2: > ![get_gps_date_time.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_gps_date_time.png) GPSV2Module.get\_timestamp()[](#GPSV2Module.get_timestamp "Link to this definition") Get the timestamp of the current GPS time. Returns: The timestamp representing the current GPS time. UIFLOW2: > ![get_timestamp.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_timestamp.png) GPSV2Module.get\_latitude()[](#GPSV2Module.get_latitude "Link to this definition") Get the current latitude. Returns: The current latitude in string format. UIFLOW2: > ![get_latitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_latitude.png) GPSV2Module.get\_longitude()[](#GPSV2Module.get_longitude "Link to this definition") Get the current longitude. Returns: The current longitude in string format. UIFLOW2: > ![get_longitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_longitude.png) GPSV2Module.get\_altitude()[](#GPSV2Module.get_altitude "Link to this definition") Get the current altitude. Returns: The current altitude in string format. UIFLOW2: > ![get_altitude.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_altitude.png) GPSV2Module.get\_satellite\_num()[](#GPSV2Module.get_satellite_num "Link to this definition") Get the number of satellites used for positioning. Returns: The number of satellites. UIFLOW2: > ![get_satellite_num.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_satellite_num.png) GPSV2Module.get\_pos\_quality()[](#GPSV2Module.get_pos_quality "Link to this definition") Get the quality of the GPS position. Returns: The position quality indicator. UIFLOW2: > ![get_pos_quality.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_pos_quality.png) GPSV2Module.get\_corse\_over\_ground()[](#GPSV2Module.get_corse_over_ground "Link to this definition") Get the course over ground (COG). Returns: The course over ground in degrees. UIFLOW2: > ![get_corse_over_ground.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_corse_over_ground.png) GPSV2Module.get\_speed\_over\_ground()[](#GPSV2Module.get_speed_over_ground "Link to this definition") Get the speed over ground (SOG). Returns: The speed over ground in knots. UIFLOW2: > ![get_speed_over_ground.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_speed_over_ground.png) GPSV2Module.set\_time\_zone(_value_)[](#GPSV2Module.set_time_zone "Link to this definition") Set the time zone offset for the GPS time. Parameters: **value** – The time zone offset value to set. UIFLOW2: > ![set_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/set_time_zone.png) GPSV2Module.get\_time\_zone()[](#GPSV2Module.get_time_zone "Link to this definition") Get the current time zone offset. Returns: The current time zone offset. UIFLOW2: > ![get_time_zone.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/get_time_zone.png) GPSV2Module.deinit()[](#GPSV2Module.deinit "Link to this definition") Deinitialize the GPS unit, stopping any running tasks and releasing resources. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/module/gps_v2/deinit.png) GPSV2Module.\_add\_checksum(_message_)[](#GPSV2Module._add_checksum "Link to this definition") Add checksum to the message for communication with the GPS module. Parameters: **message** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The message to which the checksum will be added. Returns: The message with added checksum. GPSV2Module.\_decode\_gga(_data_)[](#GPSV2Module._decode_gga "Link to this definition") Decode the GGA sentence to extract GPS quality, number of satellites, and altitude. Parameters: **data** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The GGA sentence to decode. GPSV2Module.\_decode\_rmc(_data_)[](#GPSV2Module._decode_rmc "Link to this definition") Decode the RMC sentence to extract GPS time, latitude, longitude, speed, course, and date. Parameters: **data** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The RMC sentence to decode. GPSV2Module.\_decode\_txt(_data_)[](#GPSV2Module._decode_txt "Link to this definition") Decode the TXT sentence to extract antenna state. Parameters: **data** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The TXT sentence to decode. GPSV2Module.\_monitor()[](#GPSV2Module._monitor "Link to this definition") Monitor the GPS data and decode incoming sentences. --- # NeoFlash Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * NeoFlash Hat * [View page source](../_sources/hats/neoflash.rst.txt) * * * NeoFlash Hat[](#neoflash-hat "Link to this heading") ====================================================== NeoFlash HAT is specifically designed for M5StickC, it is an RGB LED matrix. Space on PCB board is 58x23.5mm and total include 126 RGB LEDs. Every single RGB LED is programmable, which allows you setting the colors and brightness, plus on the 7\*18 matrix layout, you will have a nice experience on either display digital numbers or colorful light effect. Support the following products: > [![NeoFlashHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-neoflash/hat-neoflash_01.webp)](https://docs.m5stack.com/en/hat/hat-neoflash) Micropython Example: import os, sys, io import M5 from M5 import \* from hardware import \* from hat import NeoFlashHat neoflash \= NeoFlashHat((26, 0)) neoflash.set\_pixel(0, 0, 0xFF0000) neoflash.set\_pixel(1, 0, 0x00FF00) UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/hat/neoflash/example.svg) class NeoFlashHat[](#class-neoflashhat "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ NeoFlashHat(_port: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _)[](#NeoFlashHat "Link to this definition") Initialize the NeoFlashHat. Parameters: **port** ([_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – The port to which the NeoFlashHat is connected. port\[0\]: LEDs pin. UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/hat/neoflash/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- NeoFlashHat.set\_pixel(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#NeoFlashHat.set_pixel "Link to this definition") Set the color of the pixel. Parameters: * **x** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The x coordinate of the pixel. * **y** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The y coordinate of the pixel. * **color** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The color of the pixel. UIFLOW2: > ![set_pixel.svg](https://static-cdn.m5stack.com/mpy_docs/hat/neoflash/set_pixel.svg) NeoFlashHat.set\_pixels(_data: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#NeoFlashHat.set_pixels "Link to this definition") Set the color of the pixels. Parameters: **data** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") ) – The list of the pixel position and color, \[x, y, color\]. UIFLOW2: > ![set_pixels.svg](https://static-cdn.m5stack.com/mpy_docs/hat/neoflash/set_pixels.svg) Constants[](#constants "Link to this heading") ------------------------------------------------ NeoFlashHat.WIDTH[](#NeoFlashHat.WIDTH "Link to this definition") The width of the NeoFlashHat. NeoFlashHat.HEIGHT[](#NeoFlashHat.HEIGHT "Link to this definition") The height of the NeoFlashHat. --- # PIR Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * PIR Hat * [View page source](../_sources/hats/pir.rst.txt) * * * PIR Hat[](#pir-hat "Link to this heading") ============================================ Support the following products: > [![PIR](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-pir/hat-pir_01.webp)](https://docs.m5stack.com/en/hat/hat-pir) 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 hat import PIRHat > 9 > 10 > 11label0 \= None > 12hat\_pir\_0 \= None > 13 > 14 > 15def hat\_pir\_0\_active\_event(pir): > 16 global label0, hat\_pir\_0 > 17 label0.setText(str(hat\_pir\_0.get\_status())) > 18 > 19 > 20def setup(): > 21 global label0, hat\_pir\_0 > 22 > 23 M5.begin() > 24 label0 \= Widgets.Label("label0", 9, 15, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 > 26 hat\_pir\_0 \= PIRHat((26, 0)) > 27 hat\_pir\_0.set\_callback(hat\_pir\_0\_active\_event, hat\_pir\_0.IRQ\_ACTIVE) > 28 hat\_pir\_0.enable\_irq() > 29 > 30 > 31def loop(): > 32 global label0, hat\_pir\_0 > 33 M5.update() > 34 > 35 > 36if \_\_name\_\_ \== "\_\_main\_\_": > 37 try: > 38 setup() > 39 while True: > 40 loop() > 41 except (Exception, KeyboardInterrupt) as e: > 42 try: > 43 from utility import print\_error\_msg > 44 > 45 print\_error\_msg(e) > 46 except ImportError: > 47 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/example.png) [stickc\_plus2\_pir\_hat\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/pir/stickc_plus2_pir_hat_example.m5f2) class PIRHat[](#class-pirhat "Link to this heading") ------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ PIRHat(_port_)[](#PIRHat "Link to this definition") Create a PIRHat object. The parameters are: * `port` GPIO pin. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- PIRHat.get\_status()[](#PIRHat.get_status "Link to this definition") Get detection status. UIFLOW2: > ![get_status.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/get_status.png) PIRHat.enable\_irq()[](#PIRHat.enable_irq "Link to this definition") Enable Human detection function. > UIFLOW2: > > > ![enable_irq.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/enable_irq.png) PIRHat.disable\_irq()[](#PIRHat.disable_irq "Link to this definition") Disable Human detection function. UIFLOW2: > ![disable_irq.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/disable_irq.png) PIRHat.set\_callback()[](#PIRHat.set_callback "Link to this definition") Polling method, placed in the loop function, constantly check. UIFLOW2: > ![set_callback.png](https://static-cdn.m5stack.com/mpy_docs/hat/pir/set_callback.png) --- # GRBL Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GRBL Module * [View page source](../_sources/module/grbl.rst.txt) * * * GRBL Module[](#grbl-module "Link to this heading") ==================================================== GRBL 13.2 is a three-axis stepper motor driver module in the M5Stack stacking module series. It uses an ATmega328P-AU controller with three sets of DRV8825PWPR stepper motor driver chip control ways, which can drive three bipolar steppers at the same time. Support the following products: [![GRBLModule](https://static-cdn.m5stack.com/resource/docs/products/module/grbl13.2/grbl13.2_01.webp)](https://docs.m5stack.com/en/module/grbl13.2) 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 module import GRBLModule > 9 > 10 > 11grbl\_0 \= None > 12 > 13 > 14def setup(): > 15 global grbl\_0 > 16 > 17 M5.begin() > 18 Widgets.fillScreen(0x222222) > 19 > 20 grbl\_0 \= GRBLModule(address\=0x70) > 21 print(grbl\_0.get\_message()) > 22 print(grbl\_0.get\_status()) > 23 print(grbl\_0.get\_idle\_state()) > 24 print(grbl\_0.get\_lock\_state()) > 25 grbl\_0.set\_mode(GRBLModule.MODE\_ABSOLUTE) > 26 grbl\_0.unlock() > 27 grbl\_0.turn(5, 5, 10, 5) > 28 grbl\_0.wait\_idle() > 29 grbl\_0.lock() > 30 > 31 > 32def loop(): > 33 global grbl\_0 > 34 M5.update() > 35 > 36 > 37if \_\_name\_\_ \== "\_\_main\_\_": > 38 try: > 39 setup() > 40 while True: > 41 loop() > 42 except (Exception, KeyboardInterrupt) as e: > 43 try: > 44 from utility import print\_error\_msg > 45 > 46 print\_error\_msg(e) > 47 except ImportError: > 48 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/example.png) [grbl\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/grbl/grbl_example.m5f2) class GRBLModule[](#class-grblmodule "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ GRBLModule(_address_)[](#GRBLModule "Link to this definition") Initialize the GRBLModule. Parameters: **address** (_hex_) – The I2C address of the device. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- GRBLModule.g\_code(_command_)[](#GRBLModule.g_code "Link to this definition") Send the G-code command. Parameters: **command** – The G-code command. UIFLOW2: > ![g_code.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/g_code.png) GRBLModule.get\_code\_time(_code_)[](#GRBLModule.get_code_time "Link to this definition") Get the time of the code. Return (int): The estimated time of the command. Parameters: **code** – The G-code command UIFLOW2: > ![get_code_time.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/get_code_time.png) GRBLModule.turn(_x_, _y_, _z_, _speed_)[](#GRBLModule.turn "Link to this definition") Turn the motor to a specific position. Parameters: * **x** – The position of the X motor, 1.6=360°. * **y** – The position of the Y motor, 1.6=360°. * **z** – The position of the Z motor, 1.6=360°. * **speed** – The speed of the motor. UIFLOW2: > ![turn.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/turn.png) GRBLModule.set\_mode(_mode_)[](#GRBLModule.set_mode "Link to this definition") Set the mode of the motor. Parameters: **mode** – The mode of the motor. Options: - `Absolute`: GRBLModule.MODE\_ABSOLUTE - `Relative`: GRBLModule.MODE\_RELATIVE UIFLOW2: > ![set_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/set_mode.png) GRBLModule.init(_x\_step_, _y\_step_, _z\_step_, _acc_)[](#GRBLModule.init "Link to this definition") Initialize the motor. Parameters: * **x\_step** – The step of the X motor. * **y\_step** – The step of the Y motor. * **z\_step** – The step of the Z motor. * **acc** – The acceleration of the motor. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/init.png) GRBLModule.flush()[](#GRBLModule.flush "Link to this definition") Flush the buffer. UIFLOW2: > ![flush.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/flush.png) GRBLModule.get\_message()[](#GRBLModule.get_message "Link to this definition") Get the message. Return (str): The message string. UIFLOW2: > ![get_message.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/get_message.png) GRBLModule.get\_status()[](#GRBLModule.get_status "Link to this definition") Get the status. Return (str): The status string. UIFLOW2: > ![get_status.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/get_status.png) GRBLModule.get\_idle\_state()[](#GRBLModule.get_idle_state "Link to this definition") Get the idle state. Return (bool): The idle state. UIFLOW2: > ![get_idle_state.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/get_idle_state.png) GRBLModule.get\_lock\_state()[](#GRBLModule.get_lock_state "Link to this definition") Get the lock state. Return (bool): The lock state. UIFLOW2: > ![get_lock_state.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/get_lock_state.png) GRBLModule.wait\_idle()[](#GRBLModule.wait_idle "Link to this definition") Wait until the motor is idle. UIFLOW2: > ![wait_idle.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/wait_idle.png) GRBLModule.unlock\_alarm\_state()[](#GRBLModule.unlock_alarm_state "Link to this definition") Unlock the alarm state. UIFLOW2: > ![unlock_alarm_state.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/unlock_alarm_state.png) GRBLModule.lock()[](#GRBLModule.lock "Link to this definition") Lock the motor. UIFLOW2: > ![lock.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/lock.png) GRBLModule.unlock()[](#GRBLModule.unlock "Link to this definition") Unlock the motor. UIFLOW2: > ![unlock.png](https://static-cdn.m5stack.com/mpy_docs/module/grbl/unlock.png) Constants[](#constants "Link to this heading") ------------------------------------------------ > GRBLModule.MODE\_ABSOLUTE[](#GRBLModule.MODE_ABSOLUTE "Link to this definition") > > GRBLModule.MODE\_RELATIVE[](#GRBLModule.MODE_RELATIVE "Link to this definition") > > Motor mode --- # GoPlus2Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * GoPlus2Module * [View page source](../_sources/module/goplus2.rst.txt) * * * GoPlus2Module[](#goplus2module "Link to this heading") ======================================================== Support the following products: [![GoPlus2Module](https://static-cdn.m5stack.com/resource/docs/products/module/goplus2/goplus2_01.webp)](https://docs.m5stack.com/en/module/goplus2) 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 module import GoPlus2Module > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15goplus20 \= None > 16 > 17 > 18def setup(): > 19 global title0, label0, label1, goplus20 > 20 > 21 M5.begin() > 22 Widgets.fillScreen(0x222222) > 23 title0 \= Widgets.Title("GoPlus2 Module Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 24 label0 \= Widgets.Label("Motor Speed:", 2, 72, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 label1 \= Widgets.Label("Servo Angle:", 2, 116, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 > 27 goplus20 \= GoPlus2Module(0x38) > 28 goplus20.set\_digital\_output(1, 1) > 29 goplus20.set\_digital\_output(2, 1) > 30 goplus20.set\_digital\_output(3, 1) > 31 > 32 > 33def loop(): > 34 global title0, label0, label1, goplus20 > 35 M5.update() > 36 label0.setText(str((str("Motor Speed:") + str("180")))) > 37 label1.setText(str((str("Servo Angle:") + str("-127")))) > 38 goplus20.set\_servo\_angle(1, 180) > 39 goplus20.set\_servo\_angle(2, 180) > 40 goplus20.set\_servo\_angle(3, 180) > 41 goplus20.set\_servo\_angle(4, 180) > 42 goplus20.set\_motor\_speed(1, \-127) > 43 goplus20.set\_motor\_speed(2, \-127) > 44 time.sleep(4) > 45 label0.setText(str((str("Motor Speed:") + str("-180")))) > 46 label1.setText(str((str("Servo Angle:") + str("127")))) > 47 goplus20.set\_servo\_angle(1, 0) > 48 goplus20.set\_servo\_angle(2, 0) > 49 goplus20.set\_servo\_angle(3, 0) > 50 goplus20.set\_servo\_angle(4, 127) > 51 goplus20.set\_motor\_speed(1, 127) > 52 time.sleep(4) > 53 > 54 > 55if \_\_name\_\_ \== "\_\_main\_\_": > 56 try: > 57 setup() > 58 while True: > 59 loop() > 60 except (Exception, KeyboardInterrupt) as e: > 61 try: > 62 from utility import print\_error\_msg > 63 > 64 print\_error\_msg(e) > 65 except ImportError: > 66 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/example.png) [goplus2\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/goplus2/goplus2_core2_example.m5f2) class GoPlus2Module[](#class-goplus2module "Link to this heading") -------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ GoPlus2Module(_address_)[](#GoPlus2Module "Link to this definition") Initialize the GoPlus2Module. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – The I2C address of the GoPlus2 module (default is 0x38). UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- GoPlus2Module.set\_servo\_angle(_servo\_num_, _angle_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#GoPlus2Module.set_servo_angle "Link to this definition") Set the angle of the specified servo. Parameters: * **servo\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the servo (1 to 4). * **angle** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The angle to set the servo to (0 to 180 degrees). UIFLOW2: > ![set_servo_angle.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/set_servo_angle.png) GoPlus2Module.set\_servo\_pulse\_width(_servo\_num_, _pulse\_width_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#GoPlus2Module.set_servo_pulse_width "Link to this definition") Set the pulse width for the specified servo. Parameters: * **servo\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the servo (1 to 4). * **pulse\_width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The pulse width to set (in microseconds). UIFLOW2: > ![set_servo_pulse_width.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/set_servo_pulse_width.png) GoPlus2Module.set\_motor\_speed(_motor\_num_, _speed_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#GoPlus2Module.set_motor_speed "Link to this definition") Set the speed of the specified motor. Parameters: * **motor\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the motor (1 or 2). * **speed** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The speed to set (negative for reverse). UIFLOW2: > ![set_motor_speed.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/set_motor_speed.png) GoPlus2Module.set\_digital\_output(_pin\_num_, _value_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#GoPlus2Module.set_digital_output "Link to this definition") Set the digital output for the specified pin. Parameters: * **pin\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the pin (1 to 3). * **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value to set (0 or 1). UIFLOW2: > ![set_digital_output.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/set_digital_output.png) GoPlus2Module.get\_digital\_input(_pin\_num_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#GoPlus2Module.get_digital_input "Link to this definition") Get the digital input value of the specified pin. Parameters: **pin\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the pin (1 to 3). UIFLOW2: > ![get_digital_input.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/get_digital_input.png) GoPlus2Module.get\_analog\_input(_pin\_num_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#GoPlus2Module.get_analog_input "Link to this definition") Get the analog input value of the specified pin. Parameters: **pin\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of the pin (1 to 3). UIFLOW2: > ![get_analog_input.png](https://static-cdn.m5stack.com/mpy_docs/module/goplus2/get_analog_input.png) --- # Servos8 Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Servos8 Hat * [View page source](../_sources/hats/servo8.rst.txt) * * * Servos8 Hat[](#servos8-hat "Link to this heading") ==================================================== 8Servos HAT v1.1 is an 8-channel servo driver module that works with the M5StickC/C Plus series. Adopt STM32F030F4 as main controller to drive servos with PWM (Pulse Width Modulation) signal. I2C communication. Embedded power management circuit to control servo ON/OFF with programming. With the rechargeable 16340 lithium battery (with the capacity of 700mAh),It also supports 18350 lithium batteries, it can support Maximum 1.3A load. Applied for robotic and DIY projects. Support the following products: > [![Servo8](https://static-cdn.m5stack.com/resource/docs/products/hat/hat_8servos_1.1/hat_8servos_1.1_01.webp)](https://docs.m5stack.com/en/hat/hat_8servos_1.1) Micropython Example: import os, sys, io import M5 from M5 import \* from hardware import \* from hat import Servos8Hat i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) servo \= Servos8Hat(i2c0, 0x36) servo.power\_on() for i in range(1, 9): servo.write\_servo\_angle(i, 90) servo.power\_off() class Servos8Hat[](#class-servos8hat "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ Servos8Hat(_i2c: I2C_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \= 0x36_)[](#Servos8Hat "Link to this definition") Initialize the Servos8Hat. * `i2c`: I2C port to use. * `address`: I2C address of the servo8. UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- Servos8Hat.write\_servo\_angle(_ch_, _angle_)[](#Servos8Hat.write_servo_angle "Link to this definition") Set the angle of the servo. * `ch`: The channel (1 to 8) of the servo. * `angle`: The angle (0 to 180) of the servo. UIFLOW2: > ![write_servo_angle.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/write_servo_angle.svg) Servos8Hat.read\_servo\_angle(_ch_)[](#Servos8Hat.read_servo_angle "Link to this definition") Read the angle of the servo. * `ch`: The channel (1 to 8) of the servo. UIFLOW2: > ![read_servo_angle.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/read_servo_angle.svg) Servos8Hat.write\_servo\_pulse(_ch_, _pulse_)[](#Servos8Hat.write_servo_pulse "Link to this definition") Set the pulse of the servo. * `ch`: The channel (1 to 8) of the servo. * `pulse`: The pulse (500 to 2500) of the servo. UIFLOW2: > ![write_servo_pulse.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/write_servo_pulse.svg) Servos8Hat.read\_servo\_pulse(_ch_)[](#Servos8Hat.read_servo_pulse "Link to this definition") Read the pulse of the servo. * `ch`: The channel (1 to 8) of the servo. UIFLOW2: > ![read_servo_pulse.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/read_servo_pulse.svg) Servos8Hat.power\_ctrl(_state_)[](#Servos8Hat.power_ctrl "Link to this definition") Control the power of the servo. * `state`: The state of the power, 0 for OFF and 1 for ON. UIFLOW2: > ![power_ctrl.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/power_ctrl.svg) Servos8Hat.power\_on()[](#Servos8Hat.power_on "Link to this definition") Turn on the power of the servo. UIFLOW2: > ![power_on.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/power_on.svg) Servos8Hat.power\_off()[](#Servos8Hat.power_off "Link to this definition") Turn off the power of the servo. UIFLOW2: > ![power_off.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/power_off.svg) Servos8Hat.get\_power\_state()[](#Servos8Hat.get_power_state "Link to this definition") Get the state of the power of the servo. UIFLOW2: > ![get_power_state.svg](https://static-cdn.m5stack.com/mpy_docs/hat/8servos_v11/get_power_state.svg) --- # Speaker Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Speaker Hat * [View page source](../_sources/hats/speaker.rst.txt) * * * Speaker Hat[](#speaker-hat "Link to this heading") ==================================================== The following products are supported: > [![Speaker Hat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-spk/hat-spk_01.webp)](https://docs.m5stack.com/en/hat/hat-spk) Below is the detailed support for Speaker on the host: | Controller | Speaker Hat | | --- | --- | | CoreInk | ✅ | | StickC | ✅ | | StickC PLUS | ✅ | | StickC PLUS2 | ✅ | 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 hat import SpeakerHat > 9 > 10 > 11hat\_spk\_0 \= None > 12 > 13 > 14def setup(): > 15 global hat\_spk\_0 > 16 > 17 M5.begin() > 18 hat\_spk\_0 \= SpeakerHat((26, 0)) > 19 hat\_spk\_0.setVolumePercentage(1) > 20 hat\_spk\_0.tone(2000, 100) > 21 hat\_spk\_0.playWavFile("/flash/res/audio/poweron\_2\_5s.wav") > 22 > 23 > 24def loop(): > 25 global hat\_spk\_0 > 26 M5.update() > 27 > 28 > 29if \_\_name\_\_ \== "\_\_main\_\_": > 30 try: > 31 setup() > 32 while True: > 33 loop() > 34 except (Exception, KeyboardInterrupt) as e: > 35 try: > 36 from utility import print\_error\_msg > 37 > 38 print\_error\_msg(e) > 39 except ImportError: > 40 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/speaker/example.png) [stickc\_plus2\_speaker\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/speaker/stickc_plus2_speaker_example.m5f2) [`poweron_2_5s.wav`](../_downloads/ce98f404409f010a7283ed9919415a4a/poweron_2_5s.wav) class SpeakerHat[](#class-speakerhat "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ SpeakerHat(_\*args_, _\*\*kwargs_)[](#SpeakerHat "Link to this definition") Create an SpeakerHat object. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/speaker/init.png) SpeakerHat class inherits M5.Speaker class, See [hardware.Speaker.Methods](../hardware/speaker.html#hardware-speaker-methods) for more details. --- # HMI Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * HMI Module * [View page source](../_sources/module/hmi.rst.txt) * * * HMI Module[](#hmi-module "Link to this heading") ================================================== Support the following products: [![HMI Module](https://static-cdn.m5stack.com/resource/docs/products/module/HMI%20Module/img-4c227abf-0a4c-4e3a-b711-b81a35899aaf.webp)](https://docs.m5stack.com/en/module/HMI%20Module) Micropython Example: import os, sys, io import M5 from M5 import \* from module import HMIModule import time title0 \= None label0 \= None label1 \= None label2 \= None label3 \= None label4 \= None label5 \= None label6 \= None hmi\_0 \= None led\_a\_state \= None led\_b\_state \= None btn\_a\_state \= None btn\_b\_state \= None def setup(): global title0, label0, label1, label2, label3, label4, label5, label6, hmi\_0, led\_a\_state, led\_b\_state, btn\_a\_state, btn\_b\_state M5.begin() Widgets.fillScreen(0x222222) title0 \= Widgets.Title("HMI Core2 Test", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu18) label0 \= Widgets.Label("Btn enc:", 0, 81, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label1 \= Widgets.Label("Btn A:", 0, 129, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label2 \= Widgets.Label("Btn B:", 0, 176, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label3 \= Widgets.Label("Rotary:", 0, 37, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label4 \= Widgets.Label("LED A:", 173, 106, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label5 \= Widgets.Label("LED B:", 173, 164, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label6 \= Widgets.Label("Rotary Inc:", 173, 41, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) hmi\_0 \= HMIModule(address\=0x41) hmi\_0.set\_rotary\_value(0) def loop(): global title0, label0, label1, label2, label3, label4, label5, label6, hmi\_0, led\_a\_state, led\_b\_state, btn\_a\_state, btn\_b\_state M5.update() led\_a\_state \= hmi\_0.get\_led\_state(1) led\_b\_state \= hmi\_0.get\_led\_state(2) btn\_a\_state \= hmi\_0.get\_button\_status(2) btn\_b\_state \= hmi\_0.get\_button\_status(3) label0.setText(str((str('Rotary:') + str((hmi\_0.get\_button\_status(1)))))) label1.setText(str((str('Btn A:') + str(btn\_a\_state)))) label2.setText(str((str('Btn B:') + str(btn\_b\_state)))) label4.setText(str((str('LED A:') + str(led\_a\_state)))) label5.setText(str((str('LED B:') + str(led\_b\_state)))) label3.setText(str((str('Enc:') + str((hmi\_0.get\_rotary\_value()))))) if hmi\_0.get\_button\_status(1): label6.setText(str((str('Rotary Inc:') + str((hmi\_0.get\_rotary\_increments()))))) elif btn\_a\_state: led\_a\_state \= not led\_a\_state hmi\_0.set\_led\_state(1, led\_a\_state) elif btn\_b\_state: led\_b\_state \= not led\_b\_state hmi\_0.set\_led\_state(2, led\_b\_state) hmi\_0.reset\_rotary\_value() time.sleep\_ms(200) if \_\_name\_\_ \== '\_\_main\_\_': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print\_error\_msg print\_error\_msg(e) except ImportError: print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/example.png) [hmi\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/hmi/hmi_core2_example.m5f2) class HMIModule[](#class-hmimodule "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ HMIModule(_address_)[](#HMIModule "Link to this definition") Init I2C Module HMI I2C Address. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the HMIModule. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- HMIModule.get\_rotary\_value() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_rotary_value "Link to this definition") Get the current value of the rotary. UIFLOW2: > ![get_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_encoder_value.png) HMIModule.set\_rotary\_value(_value_)[](#HMIModule.set_rotary_value "Link to this definition") Set the rotary value. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – rotary value(-2147483648-2147483647). UIFLOW2: > ![set_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/set_encoder_value.png) HMIModule.reset\_rotary\_value()[](#HMIModule.reset_rotary_value "Link to this definition") Reset the rotary value. UIFLOW2: > ![reset_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/reset_encoder.png) HMIModule.get\_rotary\_increments() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_rotary_increments "Link to this definition") Get the increment value of the rotary. UIFLOW2: > ![get_rotary_increments.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_increment_value.png) HMIModule.get\_button\_status(_btn\_num_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_button_status "Link to this definition") Get the state of a specific button. Parameters: **btn\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – : Button number (1 to 3). UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_button_state.png) HMIModule.get\_led\_state(_led\_num_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_led_state "Link to this definition") Get the state of a specific LED. Parameters: **led\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – : LED number (1 to 2). UIFLOW2: > ![get_led_state.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_led_state.png) HMIModule.set\_led\_state(_led\_num_, _state_)[](#HMIModule.set_led_state "Link to this definition") Set the state of a specific LED. Parameters: * **led\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – : LED number (1 to 2). * **state** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – : The state to set for the LED. UIFLOW2: > ![set_led_state.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/set_led_state.png) HMIModule.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_firmware_version "Link to this definition") Get the firmware version of the HMI module. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_firmware_version.png) HMIModule.get\_i2c\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#HMIModule.get_i2c_address "Link to this definition") Get the current I2C address of the HMI module. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/get_i2c_address.png) HMIModule.set\_i2c\_address(_addr_)[](#HMIModule.set_i2c_address "Link to this definition") Set a new I2C address for the HMI module. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – : The new I2C address to set. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/hmi/set_i2c_address.png) --- # Servo Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Servo Hat * [View page source](../_sources/hats/servo.rst.txt) * * * Servo Hat[](#servo-hat "Link to this heading") ================================================ SERVO HAT as the name suggests, is a servo motor module with the new and upgraded “ES9251II” digital servo,This comes with 145°±10° range of motion and can be controlled by PWM signals. The signal pin of the hat is connected to G26 on M5StickC. Support the following products: > [![ServoHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-servo/hat-servo_01.webp)](https://docs.m5stack.com/en/hat/hat-servo) Micropython Example: import os, sys, io import M5 from M5 import \* from hardware import \* from hat import ServoHat servo \= ServoHat((26, 0)) servo.set\_duty(100) servo.set\_percent(50) UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/hat/servo/example.svg) class ServoHat[](#class-servohat "Link to this heading") ---------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ServoHat(_port: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _)[](#ServoHat "Link to this definition") Initialize the Servo. Parameters: **port** ([_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – The port to which the Servo is connected. port\[0\]: servo pin UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/hat/servo/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- ServoHat.set\_duty(_duty: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ServoHat.set_duty "Link to this definition") Set the duty cycle. Parameters: **duty** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The duty cycle. from 26 to 127. UIFLOW2: > ![set_duty.svg](https://static-cdn.m5stack.com/mpy_docs/hat/servo/set_duty.svg) ServoHat.set\_percent(_percent: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ServoHat.set_percent "Link to this definition") Set the clamping percentage. Parameters: **percent** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The clamping percentage. from 0 to 100. UIFLOW2: > ![set_percent.svg](https://static-cdn.m5stack.com/mpy_docs/hat/servo/set_percent.svg) ServoHat.deinit()[](#ServoHat.deinit "Link to this definition") Deinitialize the Servo. UIFLOW2: > ![deinit.svg](https://static-cdn.m5stack.com/mpy_docs/hat/servo/deinit.svg) --- # Lora Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Lora Module * [View page source](../_sources/module/lora.rst.txt) * * * Lora Module[](#lora-module "Link to this heading") ==================================================== The LoRa433\_V1.1 Module is part of the M5Stack stackable module series. It is a LoRa communication module that operates at a 433MHz frequency and utilizes the Ra-02 module (SX1278 chip) solution. Support the following products: [![LoraModule](https://static-cdn.m5stack.com/resource/docs/products/module/Module-LoRa433_V1.1/img-dac09b0a-7367-4ed9-9374-b604f646ec3b.webp)](https://docs.m5stack.com/en/module/Module-LoRa433_V1.1) Micropython Example: import os, sys, io import M5 from M5 import \* from module import LoraModule lora \= LoraModule(pin\_irq\=35, pin\_rst\=13) \# basic lora \= LoraModule(pin\_irq\=35, pin\_rst\=25) \# core2 lora \= LoraModule(pin\_irq\=10, pin\_rst\=5) \# cores3 lora.send("Hello, LoRa!") print(lora.recv()) def callback(received\_data): global lora print(received\_data) lora.start\_recv() lora.set\_irq\_callback(callback) lora.start\_recv() UIFLOW2 Example: > ![example_tx.svg](https://static-cdn.m5stack.com/mpy_docs/module/lora433/example_tx.svg) > > ![example_rx.svg](https://static-cdn.m5stack.com/mpy_docs/module/lora433/example_rx.svg) [cores3\_lora433\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora433/cores3_lora433_rx_example.m5f2) [cores3\_lora433\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora433/cores3_lora433_tx_example.m5f2) [cores3\_lora868\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora433/cores3_lora868_rx_example.m5f2) [cores3\_lora868\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora433/cores3_lora868_tx_example.m5f2) class LoraModule[](#class-loramodule "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ LoraModule(_pin\_cs_, _pin\_irq_, _pin\_rst_, _freq\_band_, _sf_, _bw_, _coding\_rate_, _preamble\_len_, _output\_power_)[](#LoraModule "Link to this definition") Initialize the LoRa module. Parameters: * **pin\_cs** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Chip select pin * **pin\_irq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Interrupt pin * **pin\_rst** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Reset pin * **freq\_band** – LoRa RF frequency in kHz. * **sf** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Spreading factor, Higher spreading factors allow reception of weaker signals but have slower data rate. * **bw** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Bandwidth value in kHz. Must be exactly one of BANDWIDTHS * **coding\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Forward Error Correction (FEC) coding rate is expressed as a ratio, `4/N`. * **preamble\_len** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Length of the preamble sequence, in units of symbols. * **output\_power** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Output power in dBm. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- LoraModule.send(_packet_, _tx\_at\_ms_)[](#LoraModule.send "Link to this definition") Send a data packet. Return (int): The return value is the timestamp when transmission completed, as a`time.ticks\_ms()` result. It will be more accurate if the modem was initialized to use interrupts. Parameters: * **packet** – The data packet to send. * **tx\_at\_ms** – Time to transmit the packet in milliseconds. For precise timing of sent packets, there is an optional `tx\_at\_ms` argument which is a timestamp (as a `time.ticks\_ms()` value). If set, the packet will be sent as close as possible to this timestamp and the function will block until that time arrives UIFLOW2: > ![send.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/send.png) LoraModule.recv(_timeout\_ms_, _rx\_length_, _rx\_packet_)[](#LoraModule.recv "Link to this definition") Receive a data packet. Return (RxPacket): Returns None on timeout, or an `RxPacket` instance with the packet on success. Parameters: * **timeout\_ms** – Optional, sets a receive timeout in milliseconds. If None (default value), then the function will block indefinitely until a packet is received. * **rx\_length** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Necessary to set if `implicit\_header` is set to `True` (see above). This is the length of the packet to receive. Ignored in the default LoRa explicit header mode, where the received radio header includes the length. * **rx\_packet** ([_RxPacket_](lora_sx1262.html#lora.RxPacket "lora.RxPacket") ) – Optional, this can be an `RxPacket` object previously received from the modem. If the newly received packet has the same length, this object is reused and returned to save an allocation. If the newly received packet has a different length, a new `RxPacket` object is allocated and returned instead. UIFLOW2: > ![recv.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/recv.png) LoraModule.start\_recv()[](#LoraModule.start_recv "Link to this definition") Start receiving data once, trigger an interrupt when data is received. UIFLOW2: > ![start_recv.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/start_recv.png) LoraModule.set\_irq\_callback(_callback_)[](#LoraModule.set_irq_callback "Link to this definition") Set the IRQ callback function. Parameters: **callback** – The callback function. The function should accept one argument, which is the received data. UIFLOW2: > ![set_irq_callback.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/set_irq_callback.png) LoraModule.standby()[](#LoraModule.standby "Link to this definition") Set the modem to standby mode. UIFLOW2: > ![standby.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/standby.png) LoraModule.sleep()[](#LoraModule.sleep "Link to this definition") Set the modem to sleep mode. UIFLOW2: > ![sleep.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/sleep.png) LoraModule.irq\_triggered()[](#LoraModule.irq_triggered "Link to this definition") Check if the IRQ has been triggered. UIFLOW2: > ![irq_triggered.png](https://static-cdn.m5stack.com/mpy_docs/module/lora433/irq_triggered.png) Constants[](#constants "Link to this heading") ------------------------------------------------ LoraModule.LORA\_433[](#LoraModule.LORA_433 "Link to this definition") LoraModule.LORA\_868[](#LoraModule.LORA_868 "Link to this definition") Select the LoRa frequency band. LoraModule.BANDWIDTHS[](#LoraModule.BANDWIDTHS "Link to this definition") Valid bandwidth --- # LLM Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * LLM Module * [View page source](../_sources/module/llm.rst.txt) * * * LLM Module[](#llm-module "Link to this heading") ================================================== Micropython Example: from module import LlmModule def on\_keyword\_detected(): print("\[Keyword\] detected") def on\_asr\_data\_input(data: str, finish: bool, index: int): print(f"\[ASR data\] {data}") def on\_llm\_data\_input(data: str, finish: bool, index: int): print(f"\[LLM data\] {data}") module\_llm \= LlmModule() module\_llm.begin\_voice\_assistant() module\_llm.set\_voice\_assistant\_on\_keyword\_detected\_callback(on\_keyword\_detected) module\_llm.set\_voice\_assistant\_on\_asr\_data\_input\_callback(on\_asr\_data\_input) module\_llm.set\_voice\_assistant\_on\_llm\_data\_input\_callback(on\_llm\_data\_input) while True: module\_llm.update() UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/example.png) [llm\_voice\_assistant.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/llm/llm_voice_assistant.m5f2) class LlmModule[](#class-llmmodule "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ LlmModule[](#LlmModule "Link to this definition") Initialize LlmModule and set up UART communication based on board type. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- LlmModule.update() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#LlmModule.update "Link to this definition") Update ModuleLLM, receive response message. UIFLOW2: > ![update.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/update.png) LlmModule.check\_connection() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#LlmModule.check_connection "Link to this definition") Check if the module connection is working properly. Returns: True if module connection is OK, False otherwise. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UIFLOW2: > ![check_connection.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/check_connection.png) LlmModule.get\_response\_msg\_list() → [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") [](#LlmModule.get_response_msg_list "Link to this definition") Get the list of module’s response messages. Returns: List of response messages as dictionaries. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") UIFLOW2: > ![get_response_msg_list.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_response_msg_list.png) LlmModule.clear\_response\_msg\_list() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#LlmModule.clear_response_msg_list "Link to this definition") Clear the module’s response message list. UIFLOW2: > ![clear_response_msg_list.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/clear_response_msg_list.png) LlmModule.sys\_ping() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#LlmModule.sys_ping "Link to this definition") Send a ping to the system and get the response code. UIFLOW2: > ![sys_ping.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/sys_ping.png) LlmModule.sys\_reset(_wait\_reset\_finish\=True_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#LlmModule.sys_reset "Link to this definition") Reset the system. Parameters: **wait\_reset\_finish** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to wait for reset completion. Returns: Result of the reset command. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UIFLOW2: > ![sys_reset.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/sys_reset.png) LlmModule.sys\_reboot() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#LlmModule.sys_reboot "Link to this definition") Reboot the system. Returns: Result of the reboot command. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UIFLOW2: > ![sys_reboot.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/sys_reboot.png) LlmModule.llm\_setup(_prompt\=''_, _model\='qwen2.5-0.5b'_, _response\_format\='llm.utf-8.stream'_, _input\='llm.utf-8.stream'_, _enoutput\=True_, _enkws\=True_, _max\_token\_len\=127_, _request\_id\='llm\_setup'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.llm_setup "Link to this definition") Set up the LLM module. Parameters: * **prompt** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The prompt text. * **model** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The model name. * **response\_format** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The response format. * **input** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The input format. * **enoutput** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable output. * **enkws** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable keyword spotting. * **max\_token\_len** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Maximum token length. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the setup command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![llm_setup.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/llm_setup.png) LlmModule.llm\_inference(_work\_id_, _input\_data_, _request\_id\='llm\_inference'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.llm_inference "Link to this definition") Perform inference with the LLM module. Parameters: * **work\_id** – The work ID. * **input\_data** – The input data. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the inference command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![llm_inference.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/llm_inference.png) LlmModule.audio\_setup(_capcard\=0_, _capdevice\=0_, _cap\_volume\=0.5_, _playcard\=0_, _playdevice\=1_, _play\_volume\=0.15_, _request\_id\='audio\_setup'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.audio_setup "Link to this definition") Set up the audio module. Parameters: * **capcard** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Capture card index. * **capdevice** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Capture device index. * **cap\_volume** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Capture volume. * **playcard** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Playback card index. * **playdevice** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Playback device index. * **play\_volume** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Playback volume. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the setup command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![audio_setup.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/audio_setup.png) LlmModule.tts\_setup(_model\='single\_speaker\_english\_fast'_, _response\_format\='tts.base64.wav'_, _input\='tts.utf-8.stream'_, _enoutput\=True_, _enkws\=True_, _request\_id\='tts\_setup'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.tts_setup "Link to this definition") Set up the TTS module. Parameters: * **model** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – TTS model name. * **response\_format** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The response format. * **input** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The input format. * **enoutput** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable output. * **enkws** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable keyword spotting. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the setup command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![tts_setup.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/tts_setup.png) LlmModule.kws\_setup(_kws\='HELLO'_, _model\='sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01'_, _response\_format\='kws.bool'_, _input\='sys.pcm'_, _enoutput\=True_, _request\_id\='kws\_setup'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.kws_setup "Link to this definition") Set up the KWS module. Parameters: * **kws** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Keyword to detect. * **model** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – KWS model name. * **response\_format** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The response format. * **input** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The input format. * **enoutput** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable output. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the setup command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![kws_setup.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/kws_setup.png) LlmModule.asr\_setup(_model\='sherpa-ncnn-streaming-zipformer-20M-2023-02-17'_, _response\_format\='asr.utf-8.stream'_, _input\='sys.pcm'_, _enoutput\=True_, _enkws\=True_, _rule1\=2.4_, _rule2\=1.2_, _rule3\=30.0_, _request\_id\='asr\_setup'_) → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.asr_setup "Link to this definition") Set up the ASR module. Parameters: * **model** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – ASR model name. * **response\_format** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The response format. * **input** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The input format. * **enoutput** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable output. * **enkws** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Enable keyword spotting. * **rule1** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Rule 1 value. * **rule2** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Rule 2 value. * **rule3** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – Rule 3 value. * **request\_id** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Request ID. Returns: Result of the setup command. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![asr_setup.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/asr_setup.png) LlmModule.get\_latest\_llm\_work\_id() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.get_latest_llm_work_id "Link to this definition") Get latest LLM module work id. Returns: Latest LLM module work id. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![get_latest_llm_work_id.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_llm_work_id.png) LlmModule.get\_latest\_audio\_work\_id() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.get_latest_audio_work_id "Link to this definition") Get latest Audio module work id. Returns: Latest Audio module work id. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![get_latest_audio_work_id.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_audio_work_id.png) LlmModule.get\_latest\_tts\_work\_id() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.get_latest_tts_work_id "Link to this definition") Get latest TTS module work id. Returns: Latest TTS module work id. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![get_latest_tts_work_id.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_tts_work_id.png) LlmModule.get\_latest\_kws\_work\_id() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.get_latest_kws_work_id "Link to this definition") Get latest KWS module work id. Returns: Latest KWS module work id. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![get_latest_kws_work_id.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_kws_work_id.png) LlmModule.get\_latest\_asr\_work\_id() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#LlmModule.get_latest_asr_work_id "Link to this definition") Get latest ASR module work id. Returns: Latest ASR module work id. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UIFLOW2: > ![get_latest_asr_work_id.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_asr_work_id.png) LlmModule.get\_latest\_error\_code() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#LlmModule.get_latest_error_code "Link to this definition") Get latest ModuleLLM response error code. Returns: Latest ModuleLLM response error code. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UIFLOW2: > ![get_latest_error_code.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/get_latest_error_code.png) LlmModule.begin\_voice\_assistant(_wake\_up\_keyword\='HELLO'_, _prompt\=''_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#LlmModule.begin_voice_assistant "Link to this definition") Begin the voice assistant. Parameters: * **wake\_up\_keyword** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The wake-up keyword. * **prompt** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The assistant prompt. Returns: True if the voice assistant began successfully, False otherwise. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UIFLOW2: > ![begin_voice_assistant.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/begin_voice_assistant.png) LlmModule.set\_voice\_assistant\_on\_keyword\_detected\_callback(_on\_keyword\_detected_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#LlmModule.set_voice_assistant_on_keyword_detected_callback "Link to this definition") Set the callback for when the wake-up keyword is detected. Parameters: **on\_keyword\_detected** – Callback function to be executed on keyword detection. UIFLOW2: > ![set_voice_assistant_on_keyword_detected_callback.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/set_voice_assistant_on_keyword_detected_callback.png) LlmModule.set\_voice\_assistant\_on\_asr\_data\_input\_callback(_on\_asr\_data\_input_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#LlmModule.set_voice_assistant_on_asr_data_input_callback "Link to this definition") Set the callback for when ASR data is input. Parameters: **on\_asr\_data\_input** – Callback function to handle ASR data input. UIFLOW2: > ![set_voice_assistant_on_asr_data_input_callback.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/set_voice_assistant_on_asr_data_input_callback.png) LlmModule.set\_voice\_assistant\_on\_llm\_data\_input\_callback(_on\_llm\_data\_input_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#LlmModule.set_voice_assistant_on_llm_data_input_callback "Link to this definition") Set the callback for when LLM data is input. Parameters: **on\_llm\_data\_input** – Callback function to handle LLM data input. UIFLOW2: > ![set_voice_assistant_on_llm_data_input_callback.png](https://static-cdn.m5stack.com/mpy_docs/module/llm/set_voice_assistant_on_llm_data_input_callback.png) --- # Speaker2 Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Speaker2 Hat * [View page source](../_sources/hats/speaker2.rst.txt) * * * Speaker2 Hat[](#speaker2-hat "Link to this heading") ====================================================== This is the driver library of Speaker2 Hat, which is provides a set of methods to control the speaker. Support the following products: > [![Speaker2](https://static-cdn.m5stack.com/resource/docs/products/hat/Hat-SPK2/img-20b44754-2357-4fcd-be78-77f1107f89ec.webp)](https://docs.m5stack.com/en/hat/Hat-SPK2) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### play audio[](#play-audio "Link to this heading") Open the [speaker2\_stickcplus2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/speaker2/speaker2_stickcplus2_example.m5f2) project in UiFlow2. This example demonstrates how to play audio. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/speaker2/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### play audio[](#id1 "Link to this heading") This example demonstrates how to play audio. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from hat import Speaker2Hat > 9 > 10 > 11title1 \= None > 12label0 \= None > 13label1 \= None > 14hat\_spk2\_0 \= None > 15 > 16 > 17def setup(): > 18 global title1, label0, label1, hat\_spk2\_0 > 19 > 20 Widgets.setRotation(3) > 21 M5.begin() > 22 title1 \= Widgets.Title("SPK2 StickcPlus2 e.g.", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 23 label0 \= Widgets.Label( > 24 "Press BtnA to Beep", 1, 39, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 25 ) > 26 label1 \= Widgets.Label( > 27 "Press BtnB to play wav", 1, 74, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 28 ) > 29 > 30 hat\_spk2\_0 \= Speaker2Hat((26, 0)) > 31 hat\_spk2\_0.setVolumePercentage(1) > 32 > 33 > 34def loop(): > 35 global title1, label0, label1, hat\_spk2\_0 > 36 M5.update() > 37 if BtnA.wasPressed(): > 38 hat\_spk2\_0.tone(2000, 100) > 39 if BtnB.wasPressed(): > 40 hat\_spk2\_0.playWavFile("/flash/res/audio/poweron\_2\_5s.wav") > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Speaker2[](#speaker2 "Link to this heading") _class_ hat.speaker2.Speaker2Hat(_\*args_, _\*\*kwargs_)[](#hat.speaker2.Speaker2Hat "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Speaker2 class inherits Speaker class, See [hardware.Speaker.Methods](../hardware/speaker.html#hardware-speaker-methods) for more details. --- # LoRa868 v1.2 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * LoRa868 v1.2 Module * [View page source](../_sources/module/lora_sx1262.rst.txt) * * * LoRa868 v1.2 Module[](#lora868-v1-2-module "Link to this heading") ==================================================================== The LoRa868 v1.2 Module is part of the M5Stack stackable module series. It is a LoRa communication module that operates at a 900MHz frequency and utilizes the SX1262 chip solution. Support the following products: > [![LoRa868Module v1.2](https://static-cdn.m5stack.com/resource/docs/products/module/Module-LoRa868_V1.2/img-dac09b0a-7367-4ed9-9374-b604f646ec3b.webp)](https://docs.m5stack.com/en/module/Module-LoRa868_V1.2) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ Note Before using the following examples, please check the DIP switches on the module to ensure that the pins used in the example match the DIP switch positions. For specific configurations, please refer to the product manual page. The SPI configuration has been implemented internally, so users do not need to worry about it. ### Sender[](#sender "Link to this heading") Open the [cores3\_lora\_sx1262\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora_sx1262/cores3_lora_sx1262_tx_example.m5f2) project in UiFlow2. This example sends data every second. UiFlow2 Code Block: > ![cores3_lora_sx1262_tx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/tx_example.png) Example output: > None ### Receiver[](#receiver "Link to this heading") Open the [cores3\_lora\_sx1262\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lora_sx1262/cores3_lora_sx1262_rx_example.m5f2) project in UiFlow2. This example receives and displays data. UiFlow2 Code Block: > ![cores3_lora_sx1262_rx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/rx_example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- Note Before using the following examples, please check the DIP switches on the module to ensure that the pins used in the example match the DIP switch positions. For specific configurations, please refer to the product manual page. The SPI configuration has been implemented internally, so users do not need to worry about it. ### Sender[](#id1 "Link to this heading") This example sends data every second. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LoRaSx1262Module > 9import time > 10 > 11 > 12title0 \= None > 13label\_t \= None > 14label\_time \= None > 15label\_tx \= None > 16label\_ts \= None > 17lora868v12\_0 \= None > 18 > 19 > 20count \= None > 21last\_time \= None > 22timestamp \= None > 23 > 24 > 25def setup(): > 26 global \\ > 27 title0, \\ > 28 label\_t, \\ > 29 label\_time, \\ > 30 label\_tx, \\ > 31 label\_ts, \\ > 32 lora868v12\_0, \\ > 33 count, \\ > 34 last\_time, \\ > 35 timestamp > 36 > 37 M5.begin() > 38 Widgets.fillScreen(0x222222) > 39 title0 \= Widgets.Title("LoRa Module Tx", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 40 label\_t \= Widgets.Label("Send:", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 41 label\_time \= Widgets.Label("1", 118, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 42 label\_tx \= Widgets.Label("hello", 65, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 43 label\_ts \= Widgets.Label("timestamp:", 5, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 44 > 45 lora868v12\_0 \= LoRaSx1262Module(5, 1, 10, 2, 868000, "250", 8, 8, 12, 0x12, 10) > 46 count \= 0 > 47 last\_time \= time.ticks\_ms() > 48 > 49 > 50def loop(): > 51 global \\ > 52 title0, \\ > 53 label\_t, \\ > 54 label\_time, \\ > 55 label\_tx, \\ > 56 label\_ts, \\ > 57 lora868v12\_0, \\ > 58 count, \\ > 59 last\_time, \\ > 60 timestamp > 61 M5.update() > 62 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \>= 1000: > 63 last\_time \= time.ticks\_ms() > 64 count \= count + 1 > 65 timestamp \= lora868v12\_0.send((str("hello M5 ") + str(count)), None) > 66 label\_tx.setText(str((str("hello M5 ") + str(count)))) > 67 label\_time.setText(str(last\_time)) > 68 > 69 > 70if \_\_name\_\_ \== "\_\_main\_\_": > 71 try: > 72 setup() > 73 while True: > 74 loop() > 75 except (Exception, KeyboardInterrupt) as e: > 76 try: > 77 from utility import print\_error\_msg > 78 > 79 print\_error\_msg(e) > 80 except ImportError: > 81 print("please update to latest firmware") Example output: > None ### Receiver[](#id2 "Link to this heading") This example receives and displays data. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LoRaSx1262Module > 9import time > 10 > 11 > 12title0 \= None > 13label\_r \= None > 14label\_rx \= None > 15label\_t \= None > 16label\_time \= None > 17label\_rssi \= None > 18label\_snr \= None > 19label\_rssi\_v \= None > 20label\_snr\_v \= None > 21lora868v12\_0 \= None > 22 > 23 > 24lora868v12\_data \= None > 25rssi \= None > 26snr \= None > 27last\_time \= None > 28 > 29 > 30def lora868v12\_0\_receive\_event(received\_data): > 31 global \\ > 32 title0, \\ > 33 label\_r, \\ > 34 label\_rx, \\ > 35 label\_t, \\ > 36 label\_time, \\ > 37 label\_rssi, \\ > 38 label\_snr, \\ > 39 label\_rssi\_v, \\ > 40 label\_snr\_v, \\ > 41 lora868v12\_0, \\ > 42 lora868v12\_data, \\ > 43 rssi, \\ > 44 snr, \\ > 45 last\_time > 46 lora868v12\_data \= received\_data > 47 label\_rx.setText(str(lora868v12\_data.decode())) > 48 rssi \= lora868v12\_data.rssi > 49 snr \= lora868v12\_data.snr > 50 label\_rssi\_v.setText(str(rssi)) > 51 label\_snr\_v.setText(str(snr)) > 52 > 53 > 54def setup(): > 55 global \\ > 56 title0, \\ > 57 label\_r, \\ > 58 label\_rx, \\ > 59 label\_t, \\ > 60 label\_time, \\ > 61 label\_rssi, \\ > 62 label\_snr, \\ > 63 label\_rssi\_v, \\ > 64 label\_snr\_v, \\ > 65 lora868v12\_0, \\ > 66 lora868v12\_data, \\ > 67 rssi, \\ > 68 snr, \\ > 69 last\_time > 70 > 71 M5.begin() > 72 Widgets.fillScreen(0x222222) > 73 title0 \= Widgets.Title("LoRa Module Rx", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 74 label\_r \= Widgets.Label("Recv:", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 75 label\_rx \= Widgets.Label(" ", 65, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 76 label\_t \= Widgets.Label("timestamp:", 5, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 77 label\_time \= Widgets.Label("1", 118, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 78 label\_rssi \= Widgets.Label("RSSI: ", 5, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 79 label\_snr \= Widgets.Label("SNR: ", 5, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 80 label\_rssi\_v \= Widgets.Label(" ", 65, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 81 label\_snr\_v \= Widgets.Label(" ", 65, 108, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 82 > 83 lora868v12\_0 \= LoRaSx1262Module(5, 1, 10, 2, 868000, "250", 8, 8, 12, 0x12, 10) > 84 lora868v12\_0.set\_irq\_callback(lora868v12\_0\_receive\_event) > 85 lora868v12\_0.start\_recv() > 86 last\_time \= time.ticks\_ms() > 87 > 88 > 89def loop(): > 90 global \\ > 91 title0, \\ > 92 label\_r, \\ > 93 label\_rx, \\ > 94 label\_t, \\ > 95 label\_time, \\ > 96 label\_rssi, \\ > 97 label\_snr, \\ > 98 label\_rssi\_v, \\ > 99 label\_snr\_v, \\ > 100 lora868v12\_0, \\ > 101 lora868v12\_data, \\ > 102 rssi, \\ > 103 snr, \\ > 104 last\_time > 105 M5.update() > 106 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \>= 1000: > 107 last\_time \= time.ticks\_ms() > 108 label\_time.setText(str(last\_time)) > 109 > 110 > 111if \_\_name\_\_ \== "\_\_main\_\_": > 112 try: > 113 setup() > 114 while True: > 115 loop() > 116 except (Exception, KeyboardInterrupt) as e: > 117 try: > 118 from utility import print\_error\_msg > 119 > 120 print\_error\_msg(e) > 121 except ImportError: > 122 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### class LoRaSx1262Module[](#class-lorasx1262module "Link to this heading") _class_ module.lora\_sx1262.LoRaSx1262Module(_pin\_rst\=5_, _pin\_cs\=1_, _pin\_irq\=10_, _pin\_busy\=2_, _freq\_khz\=868000_, _bw\='250'_, _sf\=8_, _coding\_rate\=8_, _reamble\_len\=12_, _syncword\=0x12_, _output\_power\=10_)[](#module.lora_sx1262.LoRaSx1262Module "Link to this definition") Create an LoRaSx1262Module object. Parameters: * **timer\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The Timer ID. Range: 0~3. Default is 0. * **pin\_rst** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (RST) Reset pin number. * **pin\_cs** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (NSS) Chip select pin number. * **pin\_irq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (IRQ) Interrupt pin number. * **pin\_busy** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (BUSY) Busy pin number. * **freq\_khz** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – LoRa RF frequency in KHz, with a range of 850000 KHz to 930000 KHz. * **bw** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Bandwidth, options include: * `"7.8"`: 7.8 KHz * `"10.4"`: 10.4 KHz * `"15.6"`: 15.6 KHz * `"20.8"`: 20.8 KHz * `"31.25"`: 31.25 KHz * `"41.7"`: 41.7 KHz * `"62.5"`: 62.5 KHz * `"125"`: 125 KHz * `"250"`: 250 KHz * `"500"`: 500 KHz * **sf** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Spreading factor, range from 7 to 12. Higher spreading factors allow reception of weaker signals but with slower data rates. * **coding\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Forward Error Correction (FEC) coding rate expressed as 4/N, with a range from 5 to 8. * **preamble\_len** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Length of the preamble sequence in symbols, range from 0 to 255. * **syncword** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Sync word to mark the start of the data frame, default is 0x12. * **output\_power** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Output power in dBm, range from -9 to 22. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/init.png) MicroPython Code Block: > from module import LoRaSx1262Module > > lora868v12\_0 \= LoRaSx1262Module(5, 1, 10, 2, 868000, '250', 8, 8, 12, 0x12, 10) set\_irq\_callback(_callback_)[](#module.lora_sx1262.LoRaSx1262Module.set_irq_callback "Link to this definition") Set the interrupt callback function to be executed on IRQ. Parameters: **callback** – The callback function to be invoked when the interrupt is triggered. The callback should not take any arguments and should return nothing. Call start\_recv() to begin receiving data. UiFlow2 Code Block: > ![set_irq_callback.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/set_irq_callback.png) MicroPython Code Block: > lora868v12\_0.set\_irq\_callback() start\_recv()[](#module.lora_sx1262.LoRaSx1262Module.start_recv "Link to this definition") Start receive data. This method initiates the process to begin receiving data. UiFlow2 Code Block: > ![start_recv.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/start_recv.png) MicroPython Code Block: > lora868v12\_0.start\_recv() recv(_self_, _timeout\_ms_, _rx\_length_, _rx\_packet_)[](#module.lora_sx1262.LoRaSx1262Module.recv "Link to this definition") Receive data. Parameters: * **timeout\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Timeout in milliseconds (optional). Default is None. * **rx\_length** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Length of the data to be read. Default is 0xFF. * **rx\_packet** ([_RxPacket_](#lora.RxPacket "lora.RxPacket") ) – An instance of RxPacket (optional) to reuse. Returns: Received packet instance Return type: [RxPacket](#lora.RxPacket "lora.RxPacket") Attempt to receive a LoRa packet. Returns None if timeout occurs, or returns the received packet instance. UiFlow2 Code Block: > ![recv.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/recv.png) MicroPython Code Block: > data \= lora868v12\_0.recv() send(_buf_, _tx\_at\_ms\=None_)[](#module.lora_sx1262.LoRaSx1262Module.send "Link to this definition") Send data. Parameters: * **packet** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _|_ [_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_ [_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _|_ [_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_ [_bytearray_](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.13)") ) – The data to be sent. * **tx\_at\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The timestamp in milliseconds when to send the data (optional). Default is None. Returns: Returns a timestamp (result of time.ticks\_ms()) indicating when the data packet was sent. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") Send a data packet and return the timestamp after the packet is sent. UiFlow2 Code Block: > ![send.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/send.png) MicroPython Code Block: > lora868v12\_0.send() standby()[](#module.lora_sx1262.LoRaSx1262Module.standby "Link to this definition") Set module to standby mode. Puts the LoRa module into standby mode, consuming less power. UiFlow2 Code Block: > ![standby.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/standby.png) MicroPython Code Block: > lora868v12\_0.standby() sleep()[](#module.lora_sx1262.LoRaSx1262Module.sleep "Link to this definition") Put the module to sleep mode. Reduces the power consumption by putting the module into deep sleep mode. UiFlow2 Code Block: > ![sleep.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/sleep.png) MicroPython Code Block: > lora868v12\_0.sleep() irq\_triggered()[](#module.lora_sx1262.LoRaSx1262Module.irq_triggered "Link to this definition") Check IRQ trigger. Returns: Returns True if an interrupt service routine (ISR) has been triggered since the last send or receive started. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![irq_triggered.png](https://static-cdn.m5stack.com/mpy_docs/module/lora868_v12/irq_triggered.png) MicroPython Code Block: > lora868v12\_0.irq\_triggered() ### class RxPacket[](#class-rxpacket "Link to this heading") _class_ lora.RxPacket[](#lora.RxPacket "Link to this definition") Create an RxPacket object. decode()[](#lora.RxPacket.decode "Link to this definition") Decode the received data. ticks\_ms()[](#lora.RxPacket.ticks_ms "Link to this definition") Timestamp of when the data was received. rssi()[](#lora.RxPacket.rssi "Link to this definition") Received signal strength (units: dBm). snr()[](#lora.RxPacket.snr "Link to this definition") Signal-to-noise ratio (units: dB \* 4). valid\_crc()[](#lora.RxPacket.valid_crc "Link to this definition") CRC validity check. --- # Thermal Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Thermal Hat * [View page source](../_sources/hats/thermal.rst.txt) * * * Thermal Hat[](#thermal-hat "Link to this heading") ==================================================== The following products are supported: > [![ThermalHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-thermal/hat-thermal_01.webp)](https://docs.m5stack.com/en/hat/hat-thermal) 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 hat import ThermalHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_thermal\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, hat\_thermal\_0 > 19 > 20 M5.begin() > 21 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 24 hat\_thermal\_0 \= ThermalHat(i2c0, 0x33) > 25 > 26 > 27def loop(): > 28 global label0, i2c0, hat\_thermal\_0 > 29 M5.update() > 30 hat\_thermal\_0.update\_temperature\_buffer() > 31 label0.setText(str(hat\_thermal\_0.get\_max\_temperature)) > 32 > 33 > 34if \_\_name\_\_ \== "\_\_main\_\_": > 35 try: > 36 setup() > 37 while True: > 38 loop() > 39 except (Exception, KeyboardInterrupt) as e: > 40 try: > 41 from utility import print\_error\_msg > 42 > 43 print\_error\_msg(e) > 44 except ImportError: > 45 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/thermal/example.png) [stickc\_plus2\_thermal\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/thermal/stickc_plus2_thermal_example.m5f2) class ThermalHat[](#class-thermalhat "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ThermalHat(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x33_)[](#ThermalHat "Link to this definition") Create a ThermalHat object. Parameters: * **i2c** – I2C object * **address** – the I2C address of the device. Default is 0x33. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/thermal/init.png) ThermalHat class inherits ThermalUnit class, See [unit.ThermaltUnit.Methods](../units/thermal.html#unit-thermaltunit-methods) for more details. --- # LoRaWAN868 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * LoRaWAN868 Module * [View page source](../_sources/module/lorawan868.rst.txt) * * * LoRaWAN868 Module[](#lorawan868-module "Link to this heading") ================================================================ COM.LoRaWAN is a LoRaWAN communication module in the M5Stack stackable module series, supporting node-to-node or LoRaWAN communication. Support the following products: [![LoRaWAN868Module](https://static-cdn.m5stack.com/resource/docs/products/module/comx_lorawan/comx_lorawan_01.webp)](https://docs.m5stack.com/en/module/comx_lorawan) Micropython TX Example: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LoRaWAN868Module > 9import time > 10 > 11 > 12lorawan868\_0 \= None > 13 > 14 > 15def setup(): > 16 global lorawan868\_0 > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 > 21 lorawan868\_0 \= LoRaWAN868Module(1, (17, 16)) > 22 lorawan868\_0.wake\_up() > 23 lorawan868\_0.set\_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) > 24 lorawan868\_0.set\_auto\_low\_power(False) > 25 print(lorawan868\_0.query\_chip\_id()) > 26 print(lorawan868\_0.query\_lorawan\_mode()) > 27 print(lorawan868\_0.any()) > 28 lorawan868\_0.set\_mode(LoRaWAN868Module.MODE\_LORA) > 29 > 30 > 31def loop(): > 32 global lorawan868\_0 > 33 M5.update() > 34 lorawan868\_0.send\_hex("Hello Lora!") > 35 time.sleep(1) > 36 > 37 > 38if \_\_name\_\_ \== "\_\_main\_\_": > 39 try: > 40 setup() > 41 while True: > 42 loop() > 43 except (Exception, KeyboardInterrupt) as e: > 44 try: > 45 from utility import print\_error\_msg > 46 > 47 print\_error\_msg(e) > 48 except ImportError: > 49 print("please update to latest firmware") Micropython RX Example: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LoRaWAN868Module > 9 > 10 > 11lorawan868\_0 \= None > 12 > 13 > 14def setup(): > 15 global lorawan868\_0 > 16 > 17 M5.begin() > 18 Widgets.fillScreen(0x222222) > 19 > 20 lorawan868\_0 \= LoRaWAN868Module(1, (17, 16)) > 21 lorawan868\_0.wake\_up() > 22 lorawan868\_0.set\_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) > 23 lorawan868\_0.set\_auto\_low\_power(False) > 24 print(lorawan868\_0.query\_chip\_id()) > 25 print(lorawan868\_0.query\_lorawan\_mode()) > 26 print(lorawan868\_0.any()) > 27 lorawan868\_0.set\_mode(LoRaWAN868Module.MODE\_LORA) > 28 lorawan868\_0.enable\_rx(0) > 29 > 30 > 31def loop(): > 32 global lorawan868\_0 > 33 M5.update() > 34 if lorawan868\_0.any(): > 35 print(lorawan868\_0.receive\_data()) > 36 lorawan868\_0.enable\_rx(0) > 37 > 38 > 39if \_\_name\_\_ \== "\_\_main\_\_": > 40 try: > 41 setup() > 42 while True: > 43 loop() > 44 except (Exception, KeyboardInterrupt) as e: > 45 try: > 46 from utility import print\_error\_msg > 47 > 48 print\_error\_msg(e) > 49 except ImportError: > 50 print("please update to latest firmware") UIFLOW2 TX Example: > ![tx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/tx_example.png) UIFLOW2 RX Example: > ![rx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/rx_example.png) [lorawan868\_example\_tx.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lorawan868/lorawan868_example_tx.m5f2) [lorawan868\_example\_rx.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lorawan868/lorawan868_example_rx.m5f2) class LoRaWAN868Module[](#class-lorawan868module "Link to this heading") -------------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ LoRaWAN868Module(_id_, _port_, _band_)[](#LoRaWAN868Module "Link to this definition") Initialize the LoRaWANModule. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART ID to use for communication. * **port** – The UART port to use for communication, specified as a tuple of (rx, tx) pins. * **band** – The frequency to use for LoRa communication UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- LoRaWAN868Module.set\_mode(_mode_)[](#LoRaWAN868Module.set_mode "Link to this definition") Set the mode of the LoRaWAN module. Parameters: **mode** – The mode to set. UIFLOW2: > ![set_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_mode.png) LoRaWAN868Module.set\_parameters(_freq_, _power_, _sf_, _bw_, _cr_, _preamble_, _crc_, _iq\_inv_, _save_)[](#LoRaWAN868Module.set_parameters "Link to this definition") Set the parameters of the LoRaWAN module. Parameters: * **freq** – Set LoRa listening/sending frequency in Hz. * **power** – LoRa signal output power in dBm; * **sf** – Spreading factor, from 5~12 * **bw** – Bandwidth 0 – 125K, 1 – 250K, 2 – 500K; * **cr** – 1 – 4/5, 2 – 4/6, 3 – 4/7, 4 – 4/8; * **preamble** – Preamble Length from 8~65535 bit; * **crc** – 0 – disable CRC check, 1 – enable CRC check; * **iq\_inv** – 0 – not inverted, 1 – inverted; * **save** – Save parameters to FLASH, 0 – not save, 1 – save. UIFLOW2: > ![set_parameters.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_parameters.png) LoRaWAN868Module.wake\_up()[](#LoRaWAN868Module.wake_up "Link to this definition") Wake up the device through a serial port interrupt. After resetting, the device is in sleep state. In theory, sending any data through the serial port can trigger the interrupt and wake up the device. UIFLOW2: > ![wake_up.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/wake_up.png) LoRaWAN868Module.sleep()[](#LoRaWAN868Module.sleep "Link to this definition") Put the device into low-power mode. UIFLOW2: > ![sleep.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/sleep.png) LoRaWAN868Module.reset()[](#LoRaWAN868Module.reset "Link to this definition") Reset the device. UIFLOW2: > ![reset.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/reset.png) LoRaWAN868Module.restore\_factory\_settings()[](#LoRaWAN868Module.restore_factory_settings "Link to this definition") Restore the device to factory settings. The parameters will reset and the device will enter sleep mode after response ends. UIFLOW2: > ![restore_factory_settings.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/restore_factory_settings.png) LoRaWAN868Module.set\_copyright(_enable_)[](#LoRaWAN868Module.set_copyright "Link to this definition") Enable or disable copyright information print when boot loader mode begins. Default is enable. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set True to enable, False to disable. UIFLOW2: > ![set_copyright.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_copyright.png) LoRaWAN868Module.set\_auto\_low\_power(_enable_)[](#LoRaWAN868Module.set_auto_low_power "Link to this definition") Enable or disable automatic low-power mode. Default is enable. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set True to enable, False to disable. UIFLOW2: > ![set_auto_low_power.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_auto_low_power.png) LoRaWAN868Module.query\_chip\_id()[](#LoRaWAN868Module.query_chip_id "Link to this definition") Query the unique ID of the chip, which can be used to query the corresponding serial number. UIFLOW2: > ![query_chip_id.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/query_chip_id.png) LoRaWAN868Module.enable\_rx(_timeout_)[](#LoRaWAN868Module.enable_rx "Link to this definition") Enable the LoRaWAN module to receive data. Parameters: **timeout** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The timeout for the receive operation. UIFLOW2: > ![enable_rx.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/enable_rx.png) LoRaWAN868Module.set\_deveui(_deveui_)[](#LoRaWAN868Module.set_deveui "Link to this definition") Set or query the DevEui. DevEui must be 16 hex characters (0-9, A-F). Parameters: **deveui** – The DevEui to set. If None, query the current DevEui. UIFLOW2: > ![set_deveui.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_deveui.png) LoRaWAN868Module.set\_appeui(_appeui_)[](#LoRaWAN868Module.set_appeui "Link to this definition") Set or query the AppEui. AppEui must be 16 hex characters (0-9, A-F). Parameters: **appeui** – The AppEui to set. If None, query the current AppEui. UIFLOW2: > ![set_appeui.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_appeui.png) LoRaWAN868Module.set\_appkey(_appkey_)[](#LoRaWAN868Module.set_appkey "Link to this definition") Set or query the AppKey. AppKey must be 32 hex characters (0-9, A-F). Parameters: **appkey** – The AppKey to set. If None, query the current AppKey. UIFLOW2: > ![set_appkey.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_appkey.png) LoRaWAN868Module.set\_nwkskey(_nwkskey_)[](#LoRaWAN868Module.set_nwkskey "Link to this definition") Set or query the NwkSKey. NwkSKey must be 32 hex characters (0-9, A-F). Parameters: **nwkskey** – The NwkSKey to set. If None, query the current NwkSKey. UIFLOW2: > ![set_nwkskey.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_nwkskey.png) LoRaWAN868Module.set\_appskey(_appskey_)[](#LoRaWAN868Module.set_appskey "Link to this definition") Set or query the AppSKey. AppSKey must be 32 hex characters (0-9, A-F). Parameters: **appskey** – The AppSKey to set. If None, query the current AppSKey. UIFLOW2: > ![set_appskey.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_appskey.png) LoRaWAN868Module.set\_devaddr(_devaddr_)[](#LoRaWAN868Module.set_devaddr "Link to this definition") Set or query the DevAddr. DevAddr must be 8 hex characters (0-9, A-F). Parameters: **devaddr** – The DevAddr to set. If None, query the current DevAddr. UIFLOW2: > ![set_devaddr.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_devaddr.png) LoRaWAN868Module.set\_otaa\_mode(_enable_)[](#LoRaWAN868Module.set_otaa_mode "Link to this definition") Set or query the OTAA mode. 1 for OTAA mode, 0 for ABP mode. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set True for OTAA mode, False for ABP mode. UIFLOW2: > ![set_otaa_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_otaa_mode.png) LoRaWAN868Module.set\_adr(_enable_)[](#LoRaWAN868Module.set_adr "Link to this definition") Enable or disable the ADR (Adaptive Data Rate) function. Default is enabled. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set True to enable ADR, False to disable. UIFLOW2: > ![set_adr.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_adr.png) LoRaWAN868Module.set\_channel\_mask(_mask_)[](#LoRaWAN868Module.set_channel_mask "Link to this definition") Set or query the LoRaWAN working channel mask. Parameters: **mask** – The channel mask in hexadecimal format, e.g., 0000000000000000000000FF for channels 0~7. UIFLOW2: > ![set_channel_mask.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_channel_mask.png) LoRaWAN868Module.join\_network()[](#LoRaWAN868Module.join_network "Link to this definition") Join the network using OTAA (Over-The-Air Activation). This command triggers the join process. UIFLOW2: > ![join_network.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/join_network.png) LoRaWAN868Module.set\_duty\_cycle(_cycle_)[](#LoRaWAN868Module.set_duty_cycle "Link to this definition") Set or query the communication cycle in milliseconds. For example, 60000 means communication every 60 seconds. Parameters: **cycle** – The communication cycle in milliseconds. UIFLOW2: > ![set_duty_cycle.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_duty_cycle.png) LoRaWAN868Module.set\_class\_mode(_mode_)[](#LoRaWAN868Module.set_class_mode "Link to this definition") Set or query the device's communication mode. Only Class A or Class C are valid. Parameters: **mode** – Set "A" for Class A or "C" for Class C. UIFLOW2: > ![set_class_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_class_mode.png) LoRaWAN868Module.set\_ack(_enable_)[](#LoRaWAN868Module.set_ack "Link to this definition") Enable or disable the ACK receipt function. If enabled, the device waits for acknowledgment from the gateway. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set True to enable ACK, False to disable. UIFLOW2: > ![set_ack.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_ack.png) LoRaWAN868Module.set\_app\_port(_port_)[](#LoRaWAN868Module.set_app_port "Link to this definition") Set or query the application port (fport) for upstream data. Valid range is 0~255. Parameters: **port** – The application port to set. UIFLOW2: > ![set_app_port.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_app_port.png) LoRaWAN868Module.set\_retransmission\_count(_count_)[](#LoRaWAN868Module.set_retransmission_count "Link to this definition") Set or query the number of retransmissions if communication fails. The valid range is 3~8. Parameters: **count** – The number of retransmissions to set. If None, query the current setting. UIFLOW2: > ![set_retransmission_count.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/set_retransmission_count.png) LoRaWAN868Module.send\_hex(_hex\_data_)[](#LoRaWAN868Module.send_hex "Link to this definition") Send hex data in LoRaWAN or LoRa mode. Hex characters must be in pairs (e.g., "AABB"). Parameters: **hex\_data** – The hex data to send, up to 64 bytes. UIFLOW2: > ![send_hex.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/send_hex.png) LoRaWAN868Module.send\_string(_string\_data_)[](#LoRaWAN868Module.send_string "Link to this definition") Send string data in LoRaWAN or LoRa mode. The string must consist of ASCII characters. Parameters: **string\_data** – The string data to send, up to 64 bytes. UIFLOW2: > ![send_string.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/send_string.png) LoRaWAN868Module.query\_lorawan\_mode()[](#LoRaWAN868Module.query_lorawan_mode "Link to this definition") Query if the device is in LoRaWAN or normal LoRa mode. UIFLOW2: > ![query_lorawan_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/query_lorawan_mode.png) LoRaWAN868Module.save\_parameters\_to\_flash()[](#LoRaWAN868Module.save_parameters_to_flash "Link to this definition") Save the current LoRa parameters to FLASH memory. UIFLOW2: > ![save_parameters_to_flash.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/save_parameters_to_flash.png) LoRaWAN868Module.at\_cmd(_cmd_, _data_)[](#LoRaWAN868Module.at_cmd "Link to this definition") Send an AT command to the LoRaWAN module. Parameters: * **cmd** – The AT command to send. * **data** – The data to send with the AT command. UIFLOW2: > ![at_cmd.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/at_cmd.png) LoRaWAN868Module.at\_query(_cmd_)[](#LoRaWAN868Module.at_query "Link to this definition") Query the current settings of the LoRaWAN module. Parameters: **cmd** – The AT command to query. UIFLOW2: > ![at_query.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/at_query.png) LoRaWAN868Module.at\_receive()[](#LoRaWAN868Module.at_receive "Link to this definition") Receive a response from the LoRaWAN module. UIFLOW2: > ![at_receive.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/at_receive.png) LoRaWAN868Module.flush()[](#LoRaWAN868Module.flush "Link to this definition") Clear the UART buffer. UIFLOW2: > ![flush.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/flush.png) LoRaWAN868Module.any()[](#LoRaWAN868Module.any "Link to this definition") Check if there is any data in the UART buffer. UIFLOW2: > ![any.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/any.png) LoRaWAN868Module.receive\_data()[](#LoRaWAN868Module.receive_data "Link to this definition") Receive data from the LoRaWAN module. UIFLOW2: > ![receive_data.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lorawan868/receive_data.png) Constants[](#constants "Link to this heading") ------------------------------------------------ > LoRaWAN868Module.BAND\_470[](#LoRaWAN868Module.BAND_470 "Link to this definition") > > LoRaWAN868Module.BAND\_868[](#LoRaWAN868Module.BAND_868 "Link to this definition") > > LoRaWAN868Module.BAND\_915[](#LoRaWAN868Module.BAND_915 "Link to this definition") > > LoRa band frequency > > LoRaWAN868Module.MODE\_LORA[](#LoRaWAN868Module.MODE_LORA "Link to this definition") > > LoRaWAN868Module.MODE\_LORAWAN[](#LoRaWAN868Module.MODE_LORAWAN "Link to this definition") > > LoRa Mode --- # ToF Hat — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * ToF Hat * [View page source](../_sources/hats/tof.rst.txt) * * * ToF Hat[](#tof-hat "Link to this heading") ============================================ The following products are supported: > [![ToFHat](https://static-cdn.m5stack.com/resource/docs/products/hat/hat-tof/hat-tof_01.webp)](https://docs.m5stack.com/zh_CN/hat/hat-tof) 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 hat import ToFHat > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14hat\_tof\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, hat\_tof\_0 > 19 > 20 M5.begin() > 21 label0 \= Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 i2c0 \= I2C(0, scl\=Pin(26), sda\=Pin(0), freq\=100000) > 24 hat\_tof\_0 \= ToFHat(i2c0) > 25 > 26 > 27def loop(): > 28 global label0, i2c0, hat\_tof\_0 > 29 M5.update() > 30 label0.setText(str((str((hat\_tof\_0.get\_range())) + str("mm")))) > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/tof/example.png) [stickc\_plus2\_tof\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/tof/stickc_plus2_tof_example.m5f2) class ToFHat[](#class-tofhat "Link to this heading") ------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ToFHat(_i2c: I2C_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x29_, _io\_timeout\_ms: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#ToFHat "Link to this definition") Creates an instance of the ToFHat class. Parameters: * **i2c** – the I2C object. * **address** – the I2C address of the device. Default is 0x23. * **io\_timeout\_ms** – the timeout of I2C communication. Default is 0ms. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/tof/init.png) ToFHat class inherits ToFUnit class, See [unit.ToFUnit.Methods](../units/tof.html#unit-tofunit-methods) for more details. --- # NB-IoT Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * NB-IoT Module * [View page source](../_sources/module/nbiot.rst.txt) * * * NB-IoT Module[](#nb-iot-module "Link to this heading") ======================================================== The following products are supported: > [![NB-IoT Module](https://static-cdn.m5stack.com/resource/docs/products/module/comx_nb-iot/comx_nb-iot_01.webp)](https://docs.m5stack.com/en/module/comx_nb-iot) class NBIOTModule[](#class-nbiotmodule "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ NBIOTModule(_id: Literal\[0, 1, 2\]_, _tx: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _rx: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#NBIOTModule "Link to this definition") Create a NBIOTModule object Parameters: * **id** – UART ID. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART TX pin. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART RX pin. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/nbiot/init.png) See [unit.NBIOTUnit.Methods](../units/nbiot.html#unit-nbiotunit-methods) for more details. --- # COMX LTE Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * COMX LTE Module * [View page source](../_sources/module/lte.rst.txt) * * * COMX LTE Module[](#comx-lte-module "Link to this heading") ============================================================ LTEModule Class provides a set of methods to control the LTE module. Through the chat script of AT commands, the module is set to PPP mode and then the data is sent to the Internet through the serial port. Support the following products: > [![COMX LTE](https://static-cdn.m5stack.com/resource/docs/products/module/comx_lte/comx_lte_01.webp)](https://docs.m5stack.com/en/module/comx_lte) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### HTTP GET over LTE[](#http-get-over-lte "Link to this heading") Open the [core2\_lte\_http\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lte/core2_lte_http_example.m5f2) project in UiFlow2. This example demonstrates how to use PPP dial-up on the LTE module and then use the requests2 library to send an HTTP GET request. UiFlow2 Code Block: > ![example_http.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/example_http.png) Example output: > None ### Chat script[](#chat-script "Link to this heading") Open the [core2\_lte\_chat\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/lte/core2_lte_chat_example.m5f2) project in UiFlow2. Set the LTE module to PPP mode through a custom AT command chat script. UiFlow2 Code Block: > ![example_chat.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/example_chat.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### HTTP GET over LTE[](#id1 "Link to this heading") This example demonstrates how to use PPP dial-up on the LTE module and then use the requests2 library to send an HTTP GET request. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LTEModule > 9import requests2 > 10 > 11 > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16label4 \= None > 17label5 \= None > 18label6 \= None > 19label7 \= None > 20label8 \= None > 21label9 \= None > 22label10 \= None > 23title0 \= None > 24comlte\_0 \= None > 25http\_req \= None > 26 > 27 > 28def setup(): > 29 global \\ > 30 label0, \\ > 31 label1, \\ > 32 label2, \\ > 33 label3, \\ > 34 label4, \\ > 35 label5, \\ > 36 label6, \\ > 37 label7, \\ > 38 label8, \\ > 39 label9, \\ > 40 label10, \\ > 41 title0, \\ > 42 comlte\_0, \\ > 43 http\_req > 44 > 45 M5.begin() > 46 Widgets.fillScreen(0x222222) > 47 label0 \= Widgets.Label("Connecting", 16, 47, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 48 label1 \= Widgets.Label("IPv4:", 16, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 49 label2 \= Widgets.Label("Netmask:", 16, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 50 label3 \= Widgets.Label("Gateway:", 16, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 51 label4 \= Widgets.Label("DNS:", 16, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 52 label5 \= Widgets.Label("HTTP Code:", 16, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 53 label6 \= Widgets.Label("label6", 80, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 54 label7 \= Widgets.Label("label7", 120, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 55 label8 \= Widgets.Label("label8", 120, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 56 label9 \= Widgets.Label("label9", 80, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 57 label10 \= Widgets.Label("label10", 140, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 58 title0 \= Widgets.Title("COM.LTE Sample Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 59 > 60 comlte\_0 \= LTEModule(2, 14, 13, verbose\=True) > 61 comlte\_0.chat2("IP", "CMNET") > 62 comlte\_0.active(True) > 63 comlte\_0.connect(authmode\=comlte\_0.AUTH\_NONE, username\="", password\="") > 64 while not (comlte\_0.isconnected()): > 65 pass > 66 label0.setText(str("Connected")) > 67 label6.setText(str(comlte\_0.ifconfig()\[0\])) > 68 label7.setText(str(comlte\_0.ifconfig()\[1\])) > 69 label8.setText(str(comlte\_0.ifconfig()\[2\])) > 70 label9.setText(str(comlte\_0.ifconfig()\[3\])) > 71 http\_req \= requests2.get( > 72 "https://httpbin.org/get", headers\={"Content-Type": "application/json"} > 73 ) > 74 label10.setText(str(http\_req.status\_code)) > 75 http\_req.close() > 76 > 77 > 78def loop(): > 79 global \\ > 80 label0, \\ > 81 label1, \\ > 82 label2, \\ > 83 label3, \\ > 84 label4, \\ > 85 label5, \\ > 86 label6, \\ > 87 label7, \\ > 88 label8, \\ > 89 label9, \\ > 90 label10, \\ > 91 title0, \\ > 92 comlte\_0, \\ > 93 http\_req > 94 M5.update() > 95 > 96 > 97if \_\_name\_\_ \== "\_\_main\_\_": > 98 try: > 99 setup() > 100 while True: > 101 loop() > 102 except (Exception, KeyboardInterrupt) as e: > 103 try: > 104 comlte\_0.deinit() > 105 from utility import print\_error\_msg > 106 > 107 print\_error\_msg(e) > 108 except ImportError: > 109 print("please update to latest firmware") Example output: > None ### Chat script[](#id2 "Link to this heading") Set the LTE module to PPP mode through a custom AT command chat script. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import LTEModule > 9import requests2 > 10 > 11 > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16label4 \= None > 17label5 \= None > 18label6 \= None > 19label7 \= None > 20label8 \= None > 21label9 \= None > 22label10 \= None > 23title0 \= None > 24comlte\_0 \= None > 25http\_req \= None > 26 > 27 > 28def setup(): > 29 global \\ > 30 label0, \\ > 31 label1, \\ > 32 label2, \\ > 33 label3, \\ > 34 label4, \\ > 35 label5, \\ > 36 label6, \\ > 37 label7, \\ > 38 label8, \\ > 39 label9, \\ > 40 label10, \\ > 41 title0, \\ > 42 comlte\_0, \\ > 43 http\_req > 44 > 45 M5.begin() > 46 Widgets.fillScreen(0x222222) > 47 label0 \= Widgets.Label("Connecting", 16, 47, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 48 label1 \= Widgets.Label("IPv4:", 16, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 49 label2 \= Widgets.Label("Netmask:", 16, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 50 label3 \= Widgets.Label("Gateway:", 16, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 51 label4 \= Widgets.Label("DNS:", 16, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 52 label5 \= Widgets.Label("HTTP Code:", 16, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 53 label6 \= Widgets.Label("label6", 80, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 54 label7 \= Widgets.Label("label7", 120, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 55 label8 \= Widgets.Label("label8", 120, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 56 label9 \= Widgets.Label("label9", 80, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 57 label10 \= Widgets.Label("label10", 140, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 58 title0 \= Widgets.Title("COM.LTE Sample Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 59 > 60 comlte\_0 \= LTEModule(2, 14, 13, verbose\=True) > 61 comlte\_0.chat( > 62 \[\ > 63 \["ABORT", "BUSY"\],\ > 64 \["ABORT", "NO ANSWER"\],\ > 65 \["ABORT", "NO CARRIER"\],\ > 66 \["ABORT", "NO DIALTONE"\],\ > 67 \["ABORT", "\\\\nRINGING\\\\r\\\\n\\\\r\\\\nRINGING\\\\r"\],\ > 68 \["SAY", "modem init: press -C to disconnect\\\\n"\],\ > 69 \["", "+++ATH"\],\ > 70 \["SAY", "Before Connecting\\\\n"\],\ > 71 \["OK", 'AT+CGDCONT=1,"IP","CMNET"'\],\ > 72 \["SAY", "\\\\n + defining PDP context\\\\n"\],\ > 73 \["", "ATD\*99#"\],\ > 74 \["SAY", "Number Dialled\\\\n"\],\ > 75 \["SAY", "\\\\n + attaching"\],\ > 76 \["SAY", "\\\\n + requesting data connection"\],\ > 77 \["CONNECT", "\\\\d\\\\c"\],\ > 78 \["SAY", "\\\\n + connected"\],\ > 79 \] > 80 ) > 81 comlte\_0.active(True) > 82 comlte\_0.connect(authmode\=comlte\_0.AUTH\_NONE, username\="", password\="") > 83 while not (comlte\_0.isconnected()): > 84 pass > 85 label0.setText(str("Connected")) > 86 label6.setText(str(comlte\_0.ifconfig()\[0\])) > 87 label7.setText(str(comlte\_0.ifconfig()\[1\])) > 88 label8.setText(str(comlte\_0.ifconfig()\[2\])) > 89 label9.setText(str(comlte\_0.ifconfig()\[3\])) > 90 http\_req \= requests2.get( > 91 "https://httpbin.org/get", headers\={"Content-Type": "application/json"} > 92 ) > 93 label10.setText(str(http\_req.status\_code)) > 94 http\_req.close() > 95 > 96 > 97def loop(): > 98 global \\ > 99 label0, \\ > 100 label1, \\ > 101 label2, \\ > 102 label3, \\ > 103 label4, \\ > 104 label5, \\ > 105 label6, \\ > 106 label7, \\ > 107 label8, \\ > 108 label9, \\ > 109 label10, \\ > 110 title0, \\ > 111 comlte\_0, \\ > 112 http\_req > 113 M5.update() > 114 > 115 > 116if \_\_name\_\_ \== "\_\_main\_\_": > 117 try: > 118 setup() > 119 while True: > 120 loop() > 121 except (Exception, KeyboardInterrupt) as e: > 122 try: > 123 comlte\_0.deinit() > 124 from utility import print\_error\_msg > 125 > 126 print\_error\_msg(e) > 127 except ImportError: > 128 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### LTEModule[](#ltemodule "Link to this heading") _class_ module.lte.LTEModule(_id_, _tx_, _rx_, _verbose\=False_)[](#module.lte.LTEModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") LTE module class. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART ID connected to the LTE module. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Connect to the UART TX pin of the LTE module. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Connect to the UART RX pin of the LTE module. * **verbose** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to print verbose information. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/init.png) MicroPython Code Block: > from module import LTEModule > > comlte\_0 \= LTEModule(2, 14, 13, verbose\=True) active(\[_is\_active_\])[](#module.lte.LTEModule.active "Link to this definition") Activate (“up”) or deactivate (“down”) the network interface, if a boolean argument is passed. Otherwise, query current state if no argument is provided. Parameters: **is\_active** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – If True, the LTE module is enabled, if False, the LTE module is disabled. Returns: Returns the activation status of the LTE module. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![active.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/active.png) MicroPython Code Block: > comlte\_0.active(True) > comlte\_0.active(False) > comlte\_0.active() connect(_authmode\=AUTH\_NONE_, _username\=''_, _password\=''_)[](#module.lte.LTEModule.connect "Link to this definition") Initiate a PPP connection with the given parameters. Parameters: * **authmode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Authentication Mode, either LTEModule.AUTH\_NONE, LTEModule.AUTH\_PAP, or LTEModule.AUTH\_CHAP. * **username** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – An optional user name to use with the authentication mode. * **password** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – An optional password to use with the authentication mode. Returns: None UiFlow2 Code Block: > ![connect.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/connect.png) MicroPython Code Block: > comlte\_0.connect(authmode\=AUTH\_NONE, username\="", password\="") > comlte\_0.connect() isconnected()[](#module.lte.LTEModule.isconnected "Link to this definition") Returns True if the PPP link is connected and up. Returns False otherwise. Returns: True if the PPP link is connected and up, False otherwise. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![isconnected.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/isconnected.png) MicroPython Code Block: > comlte\_0.isconnected() ifconfig()[](#module.lte.LTEModule.ifconfig "Link to this definition") Get IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. This method returns a 4-tuple with the above information. Returns: A 4-tuple with IP address, subnet mask, gateway and DNS server. UiFlow2 Code Block: > ![get_localip.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/get_localip.png) > > ![get_subnet.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/get_subnet.png) > > ![get_gateway.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/get_gateway.png) > > ![get_dns.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/get_dns.png) MicroPython Code Block: > comlte\_0.ifconfig() > comlte\_0.ifconfig()\[0\] \# IP address > comlte\_0.ifconfig()\[1\] \# network > comlte\_0.ifconfig()\[2\] \# gateway > comlte\_0.ifconfig()\[3\] \# DNS server chat(_script_)[](#module.lte.LTEModule.chat "Link to this definition") Chat with the LTE module. Parameters: **script** ([_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – A tuple of commands to chat with the LTE module. Each command is a tuple of two elements: the first element is the expect value, and the second element is the command. For example, ((“OK”, “AT”). Return type: None UiFlow2 Code Block: > ![chat.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/chat.png) MicroPython Code Block: > comlte\_0.chat((("OK", "AT"), ("OK", "AT+CGDCONT=1,"IP","CMNET""), ("OK", "ATD\*99#"))) chat2(_pdp\_type_, _apn_)[](#module.lte.LTEModule.chat2 "Link to this definition") Chat with the LTE module to establish a PPP connection. Parameters: * **pdp\_type** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – PDP type. For example, “IP”, “PPP”, “IPV4V6”, “IPV6”. * **apn** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Access Point Name. For example, “CMNET”. Return type: None UiFlow2 Code Block: > ![chat2.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/chat2.png) MicroPython Code Block: > comlte\_0.chat2("IP", "CMNET") deinit()[](#module.lte.LTEModule.deinit "Link to this definition") Deinitialize the LTE module. UiFlow2 Code Block: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/module/com_lte/deinit.png) MicroPython Code Block: > comlte\_0.deinit() Return type: None --- # ODrive Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * ODrive Module * [View page source](../_sources/module/odrive.rst.txt) * * * ODrive Module[](#odrive-module "Link to this heading") ======================================================== ODrive is a high-performance servo motor drive module launched by M5Stack, based on the open source motion control solution ODrive. Support the following products: [![ODriveModule](https://static-cdn.m5stack.com/resource/docs/products/module/odrive/odrive_01.webp)](https://docs.m5stack.com/en/module/odrive) Micropython Example: import os, sys, io import M5 from M5 import \* from module import ODriveModule drive \= ODriveModule(port\=(13,5)) drive.get\_vbus\_voltage() drive.set\_velocity(10) drive.set\_current(5) drive.set\_control\_mode(ODriveModule.CONTROL\_MODE\_POSITION\_CONTROL) drive.set\_position(1000) UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/example.png) [core\_odrive\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/odrive/core_odrive_example.m5f2) class ODriveModule[](#class-odrivemodule "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ODriveModule(_id_, _port_)[](#ODriveModule "Link to this definition") Initialize the ODriveModule. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) * **port** UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ODriveModule.set\_position(_position_, _velocity\_feedforward_, _current\_feedforward_)[](#ODriveModule.set_position "Link to this definition") Set the target position with optional feedforward values. Parameters: * **position** – The target position in counts or radians, depending on the configuration. * **velocity\_feedforward** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The feedforward velocity in counts/s or radians/s to assist the controller. * **current\_feedforward** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The feedforward current in amperes to assist the controller. UIFLOW2: > ![set_position.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_position.png) ODriveModule.set\_velocity(_velocity_, _current\_feedforward_)[](#ODriveModule.set_velocity "Link to this definition") Set the target velocity with optional current feedforward. Parameters: * **velocity** – The target velocity in counts/s or radians/s. * **current\_feedforward** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The feedforward current in amperes to assist the controller. UIFLOW2: > ![set_velocity.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_velocity.png) ODriveModule.set\_current(_current_)[](#ODriveModule.set_current "Link to this definition") Set the target current. Parameters: **current** – The target current in amperes for torque control. UIFLOW2: > ![set_current.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_current.png) ODriveModule.set\_gain(_pos\_gain_, _vel\_gain_, _vel\_integrator\_gain_)[](#ODriveModule.set_gain "Link to this definition") Parameters: * **pos\_gain** * **vel\_gain** * **vel\_integrator\_gain** UIFLOW2: > ![set_gain.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_gain.png) ODriveModule.set\_control\_mode(_mode_)[](#ODriveModule.set_control_mode "Link to this definition") Set the control mode of the controller. Parameters: **mode** – The control mode. UIFLOW2: > ![set_control_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_control_mode.png) ODriveModule.set\_control\_input\_pos(_pos_)[](#ODriveModule.set_control_input_pos "Link to this definition") Set the control input position for the controller. Parameters: **pos** – The desired input position in counts or radians for position control. UIFLOW2: > ![set_control_input_pos.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_control_input_pos.png) ODriveModule.trapezoidal\_move(_position_)[](#ODriveModule.trapezoidal_move "Link to this definition") Perform a trapezoidal move to the given position. Parameters: **position** – The target position in counts or radians to move to using a trapezoidal velocity profile. UIFLOW2: > ![trapezoidal_move.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/trapezoidal_move.png) ODriveModule.run\_state(_requested\_state_, _timeout_)[](#ODriveModule.run_state "Link to this definition") Run the axis to the requested state within a timeout period. Parameters: * **requested\_state** – The desired axis state to transition to, using the AXIS\_STATE\_\* constants. * **timeout** – Timeout in milliseconds to wait for the axis to reach the requested state. UIFLOW2: > ![run_state.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/run_state.png) ODriveModule.get\_velocity()[](#ODriveModule.get_velocity "Link to this definition") Get the estimated velocity of the motor. Return (float): The estimated velocity in counts/s or radians/s. UIFLOW2: > ![get_velocity.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_velocity.png) ODriveModule.get\_vbus\_voltage()[](#ODriveModule.get_vbus_voltage "Link to this definition") Get the measured bus voltage. Return (float): The bus voltage in volts. UIFLOW2: > ![get_vbus_voltage.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_vbus_voltage.png) ODriveModule.get\_phase\_current()[](#ODriveModule.get_phase_current "Link to this definition") Get the measured phase current of the motor. Return (float): The phase current in amperes. UIFLOW2: > ![get_phase_current.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_phase_current.png) ODriveModule.get\_bus\_current()[](#ODriveModule.get_bus_current "Link to this definition") Get the bus current drawn by the motor. Return (float): The bus current in amperes. UIFLOW2: > ![get_bus_current.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_bus_current.png) ODriveModule.get\_encoder\_shadow\_count()[](#ODriveModule.get_encoder_shadow_count "Link to this definition") Get the encoder's shadow count, which is an internal counter. Return (int): The shadow count as an integer value. UIFLOW2: > ![get_encoder_shadow_count.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_encoder_shadow_count.png) ODriveModule.get\_encoder\_pos\_estimate()[](#ODriveModule.get_encoder_pos_estimate "Link to this definition") Get the estimated position from the encoder. Return (float): The estimated position in counts or radians. UIFLOW2: > ![get_encoder_pos_estimate.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_encoder_pos_estimate.png) ODriveModule.get\_motor\_temp()[](#ODriveModule.get_motor_temp "Link to this definition") Get the temperature of the motor thermistor. Return (float): The motor temperature in degrees Celsius. UIFLOW2: > ![get_motor_temp.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/get_motor_temp.png) ODriveModule.erase\_config()[](#ODriveModule.erase_config "Link to this definition") Erase the current configuration settings. UIFLOW2: > ![erase_config.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/erase_config.png) ODriveModule.save\_config()[](#ODriveModule.save_config "Link to this definition") Save the current configuration to non-volatile memory. UIFLOW2: > ![save_config.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/save_config.png) ODriveModule.reboot()[](#ODriveModule.reboot "Link to this definition") Reboot the ODrive device. UIFLOW2: > ![reboot.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/reboot.png) ODriveModule.set\_default\_config()[](#ODriveModule.set_default_config "Link to this definition") Set the default configuration parameters. UIFLOW2: > ![set_default_config.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/set_default_config.png) ODriveModule.check\_error()[](#ODriveModule.check_error "Link to this definition") Check for any errors in the system components. UIFLOW2: > ![check_error.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/check_error.png) ODriveModule.read\_flush()[](#ODriveModule.read_flush "Link to this definition") Flush the UART read buffer to clear any residual data. UIFLOW2: > ![read_flush.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_flush.png) ODriveModule.read\_string()[](#ODriveModule.read_string "Link to this definition") Read a string terminated by a newline character from the device. Return (str): The string read from the device, excluding the newline character. UIFLOW2: > ![read_string.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_string.png) ODriveModule.read\_float()[](#ODriveModule.read_float "Link to this definition") Read a floating-point value from the device. Return (float): The float value read from the device; returns 0.0 if parsing fails. UIFLOW2: > ![read_float.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_float.png) ODriveModule.read\_int()[](#ODriveModule.read_int "Link to this definition") Read an integer value from the device. Return (int): The integer value read from the device; returns 0 if parsing fails. UIFLOW2: > ![read_int.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_int.png) ODriveModule.write\_to\_device(_data_)[](#ODriveModule.write_to_device "Link to this definition") Write a command string to the device via UART. Parameters: **data** – The command string to send to the device, ending with a newline character. UIFLOW2: > ![write_to_device.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/write_to_device.png) ODriveModule.write\_config(_config_, _value_)[](#ODriveModule.write_config "Link to this definition") Write a configuration parameter to the device. Parameters: * **config** – The configuration key as a string, e.g., 'axis0.controller.config.pos\_gain'. * **value** – The value to set for the configuration parameter; can be a float or integer. UIFLOW2: > ![write_config.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/write_config.png) ODriveModule.read\_config\_int(_config_)[](#ODriveModule.read_config_int "Link to this definition") Read an integer configuration parameter from the device. Return (int): The integer value of the specified configuration parameter; returns 0 if parsing fails. Parameters: **config** – The configuration key as a string, e.g., 'axis0.encoder.error'. UIFLOW2: > ![read_config_int.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_config_int.png) ODriveModule.read\_config\_float(_config_)[](#ODriveModule.read_config_float "Link to this definition") Read a floating-point configuration parameter from the device. Return (float): The float value of the specified configuration parameter; returns 0.0 if parsing fails. Parameters: **config** – The configuration key as a string, e.g., 'axis0.motor\_thermistor.temperature'. UIFLOW2: > ![read_config_float.png](https://static-cdn.m5stack.com/mpy_docs/module/odrive/read_config_float.png) Constants[](#constants "Link to this heading") ------------------------------------------------ ODriveModule.AXIS\_STATE\_UNDEFINED[](#ODriveModule.AXIS_STATE_UNDEFINED "Link to this definition") ODriveModule.AXIS\_STATE\_IDLE[](#ODriveModule.AXIS_STATE_IDLE "Link to this definition") ODriveModule.AXIS\_STATE\_STARTUP\_SEQUENCE[](#ODriveModule.AXIS_STATE_STARTUP_SEQUENCE "Link to this definition") ODriveModule.AXIS\_STATE\_FULL\_CALIBRATION\_SEQUENCE[](#ODriveModule.AXIS_STATE_FULL_CALIBRATION_SEQUENCE "Link to this definition") ODriveModule.AXIS\_STATE\_MOTOR\_CALIBRATION[](#ODriveModule.AXIS_STATE_MOTOR_CALIBRATION "Link to this definition") ODriveModule.AXIS\_STATE\_SENSORLESS\_CONTROL[](#ODriveModule.AXIS_STATE_SENSORLESS_CONTROL "Link to this definition") ODriveModule.AXIS\_STATE\_ENCODER\_INDEX\_SEARCH[](#ODriveModule.AXIS_STATE_ENCODER_INDEX_SEARCH "Link to this definition") ODriveModule.AXIS\_STATE\_ENCODER\_OFFSET\_CALIBRATION[](#ODriveModule.AXIS_STATE_ENCODER_OFFSET_CALIBRATION "Link to this definition") ODriveModule.AXIS\_STATE\_CLOSED\_LOOP\_CONTROL[](#ODriveModule.AXIS_STATE_CLOSED_LOOP_CONTROL "Link to this definition") Axis states ODriveModule.CONTROL\_MODE\_VOLTAGE\_CONTROL[](#ODriveModule.CONTROL_MODE_VOLTAGE_CONTROL "Link to this definition") ODriveModule.CONTROL\_MODE\_TORQUE\_CONTROL[](#ODriveModule.CONTROL_MODE_TORQUE_CONTROL "Link to this definition") ODriveModule.CONTROL\_MODE\_VELOCITY\_CONTROL[](#ODriveModule.CONTROL_MODE_VELOCITY_CONTROL "Link to this definition") ODriveModule.CONTROL\_MODE\_POSITION\_CONTROL[](#ODriveModule.CONTROL_MODE_POSITION_CONTROL "Link to this definition") Control modes --- # Unknown HAT === .. toctree:: :maxdepth: 1 adc.rst cardkb.rst dac.rst dac2.rst dlight.rst env.rst finger.rst heart.rst joyc.rst joystick.rst mini\_encoder.rst mini\_joy.rst ncir.rst neoflash.rst pir.rst servo.rst servo8.rst speaker.rst speaker2.rst thermal.rst tof.rst vibrator.rst --- # PLUS Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * PLUS Module * [View page source](../_sources/module/plus.rst.txt) * * * PLUS Module[](#plus-module "Link to this heading") ==================================================== Support the following products: [![PLUS Module](https://static-cdn.m5stack.com/resource/docs/products/module/plus/plus_01.webp)](https://docs.m5stack.com/en/module/plus) Micropython Example: import os, sys, io import M5 from M5 import \* from module import PLUSModule title0 \= None label2 \= None label0 \= None label1 \= None plus\_0 \= None btn\_state \= None last\_btn\_state \= None def setup(): global title0, label2, label0, label1, plus\_0, btn\_state, last\_btn\_state M5.begin() Widgets.fillScreen(0x222222) title0 \= Widgets.Title("PLUS Core2 Test", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu18) label2 \= Widgets.Label("Btn rotray:", 1, 166, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label0 \= Widgets.Label("Rotary:", 1, 60, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) label1 \= Widgets.Label("Rotary Inc:", 1, 111, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18) plus\_0 \= PLUSModule(address\=0x62) plus\_0.set\_rotary\_value(0) def loop(): global title0, label2, label0, label1, plus\_0, btn\_state, last\_btn\_state M5.update() btn\_state \= plus\_0.get\_button\_status() label0.setText(str((str('Rotary:') + str((plus\_0.get\_rotary\_value()))))) label2.setText(str((str('Btn rotray:') + str(btn\_state)))) if btn\_state and btn\_state != last\_btn\_state: label1.setText(str((str('Rotary Inc:') + str((plus\_0.get\_rotary\_increments()))))) last\_btn\_state \= btn\_state if \_\_name\_\_ \== '\_\_main\_\_': try: setup() while True: loop() except (Exception, KeyboardInterrupt) as e: try: from utility import print\_error\_msg print\_error\_msg(e) except ImportError: print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/example.png) [plus\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/plus/plus_core2_example.m5f2) class PLUSModule[](#class-plusmodule "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ PLUSModule(_address_)[](#PLUSModule "Link to this definition") Init I2C Module PLUS I2C Address. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the PLUSModule. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- PLUSModule.get\_rotary\_value() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PLUSModule.get_rotary_value "Link to this definition") Get the current value of the rotary. Returns: The value of the rotary relative to the zero point. UIFLOW2: > ![get_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/get_encoder_value.png) PLUSModule.set\_rotary\_value(_value_)[](#PLUSModule.set_rotary_value "Link to this definition") Set the rotary value. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – rotary value. UIFLOW2: > ![set_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/set_encoder_value.png) PLUSModule.reset\_rotary\_value()[](#PLUSModule.reset_rotary_value "Link to this definition") Reset the rotary value. UIFLOW2: > ![reset_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/reset_encoder.png) PLUSModule.get\_rotary\_increments() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PLUSModule.get_rotary_increments "Link to this definition") Get the increments of the rotary value since the last call of this function. Returns: The increment value of the rotary. UIFLOW2: > ![get_rotary_increments.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/get_rotary_increments.png) PLUSModule.get\_button\_status() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PLUSModule.get_button_status "Link to this definition") Get the state of a specific button. UIFLOW2: > ![get_button_status.png](https://static-cdn.m5stack.com/mpy_docs/module/plus/get_button_state.png) --- # Vibrator HAT — UIFlow2 Programming Guide master documentation * [](../index.html) * [HAT](index.html) * Vibrator HAT * [View page source](../_sources/hats/vibrator.rst.txt) * * * Vibrator HAT[](#vibrator-hat "Link to this heading") ====================================================== Support the following products: > [![Vibrator](https://static-cdn.m5stack.com/resource/docs/products/hat/HAT-Vibrator/img-97e3aea6-fe57-4a5b-b83b-7c96086f3d3e.webp)](https://docs.m5stack.com/zh_CN/hat/HAT-Vibrator) 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 hat import VibratorHat > 9from hardware import \* > 10 > 11 > 12title0 \= None > 13freq\_label \= None > 14duty\_label \= None > 15label0 \= None > 16label1 \= None > 17label2 \= None > 18line0 \= None > 19line1 \= None > 20line2 \= None > 21hat\_vibrator\_0 \= None > 22 > 23 > 24import math > 25 > 26width \= None > 27duty\_w \= None > 28duty \= None > 29freq \= None > 30 > 31 > 32\# Describe this function... > 33def draw\_pwm(): > 34 global \\ > 35 width, \\ > 36 duty\_w, \\ > 37 duty, \\ > 38 freq, \\ > 39 title0, \\ > 40 freq\_label, \\ > 41 duty\_label, \\ > 42 label0, \\ > 43 label1, \\ > 44 label2, \\ > 45 line0, \\ > 46 line1, \\ > 47 line2, \\ > 48 hat\_vibrator\_0 > 49 if duty \== 0: > 50 width \= 55 \- (freq \- 10) > 51 print(width) > 52 line0.setPoints(x0\=(67 \- width), y0\=160, x1\=67, y1\=160) > 53 line2.setPoints(x0\=67, y0\=160, x1\=67, y1\=160) > 54 line1.setPoints(x0\=67, y0\=160, x1\=(67 + width), y1\=160) > 55 else: > 56 width \= 55 \- (freq \- 10) > 57 duty\_w \= math.ceil((width + width) \* (duty / 100)) > 58 line0.setPoints(x0\=12, y0\=130, x1\=(12 + duty\_w), y1\=130) > 59 line2.setPoints(x0\=(12 + duty\_w), y0\=130, x1\=(12 + duty\_w), y1\=160) > 60 line1.setPoints( > 61 x0\=(12 + duty\_w), y0\=160, x1\=((12 + duty\_w) + ((width + width) \- duty\_w)), y1\=160 > 62 ) > 63 > 64 > 65def setup(): > 66 global \\ > 67 title0, \\ > 68 freq\_label, \\ > 69 duty\_label, \\ > 70 label0, \\ > 71 label1, \\ > 72 label2, \\ > 73 line0, \\ > 74 line1, \\ > 75 line2, \\ > 76 hat\_vibrator\_0, \\ > 77 width, \\ > 78 duty\_w, \\ > 79 duty, \\ > 80 freq > 81 > 82 M5.begin() > 83 Widgets.fillScreen(0xFFFFFF) > 84 title0 \= Widgets.Title("VIBRATOR", 18, 0xFFFFFF, 0xF5A41D, Widgets.FONTS.DejaVu18) > 85 freq\_label \= Widgets.Label("Freq: 00", 2, 32, 1.0, 0xF5A41D, 0xFFFFFF, Widgets.FONTS.DejaVu18) > 86 duty\_label \= Widgets.Label("Duty: 00", 2, 64, 1.0, 0xF5A41D, 0xFFFFFF, Widgets.FONTS.DejaVu18) > 87 label0 \= Widgets.Label( > 88 "Long Press Turn OFF", 18, 192, 1.0, 0xF5A41D, 0xFFFFFF, Widgets.FONTS.DejaVu9 > 89 ) > 90 label1 \= Widgets.Label("Duty", 84, 100, 1.0, 0xF5A41D, 0xFFFFFF, Widgets.FONTS.DejaVu18) > 91 label2 \= Widgets.Label("Freq", 47, 213, 1.0, 0xF5A41D, 0xFFFFFF, Widgets.FONTS.DejaVu18) > 92 line0 \= Widgets.Line(12, 130, 67, 130, 0xF5A41D) > 93 line1 \= Widgets.Line(67, 160, 122, 160, 0xF5A41D) > 94 line2 \= Widgets.Line(67, 130, 67, 160, 0xF5A41D) > 95 > 96 hat\_vibrator\_0 \= VibratorHat(port\=(26, 0)) > 97 freq \= 10 > 98 duty \= 0 > 99 freq\_label.setText(str((str("Freq: ") + str(freq)))) > 100 duty\_label.setText(str((str("Duty: ") + str(duty)))) > 101 draw\_pwm() > 102 hat\_vibrator\_0.once(freq\=10, duty\=50, duration\=50) > 103 > 104 > 105def loop(): > 106 global \\ > 107 title0, \\ > 108 freq\_label, \\ > 109 duty\_label, \\ > 110 label0, \\ > 111 label1, \\ > 112 label2, \\ > 113 line0, \\ > 114 line1, \\ > 115 line2, \\ > 116 hat\_vibrator\_0, \\ > 117 width, \\ > 118 duty\_w, \\ > 119 duty, \\ > 120 freq > 121 M5.update() > 122 if BtnA.wasClicked(): > 123 freq \= freq + 1 > 124 if freq \> 55: > 125 freq \= 10 > 126 freq\_label.setText(str((str("Freq: ") + str(freq)))) > 127 draw\_pwm() > 128 hat\_vibrator\_0.set\_freq(freq) > 129 if BtnB.wasClicked(): > 130 duty \= duty + 1 > 131 duty \= duty % 100 > 132 duty\_label.setText(str((str("Duty: ") + str(duty)))) > 133 draw\_pwm() > 134 hat\_vibrator\_0.set\_duty(duty) > 135 if BtnA.isHolding(): > 136 duty \= 0 > 137 draw\_pwm() > 138 hat\_vibrator\_0.turn\_off() > 139 > 140 > 141if \_\_name\_\_ \== "\_\_main\_\_": > 142 try: > 143 setup() > 144 while True: > 145 loop() > 146 except (Exception, KeyboardInterrupt) as e: > 147 try: > 148 from utility import print\_error\_msg > 149 > 150 print\_error\_msg(e) > 151 except ImportError: > 152 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/example.png) [stick\_plus2\_vibrator\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hat/vibrator/stick_plus2_vibrator_example.m5f2) class VibratorHAT[](#class-vibratorhat "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ VibratorHAT[](#VibratorHAT "Link to this definition") Create an VibratorHAT object. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- VibratorHAT.once(_freq\=10_, _duty\=50_, _duration\=50_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#VibratorHAT.once "Link to this definition") Play the haptic effect once on the motor. Parameters: * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The frequency of vibration ranges from 10-55Hz. * **duty** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The duty cycle of vibration ranges from 0-100, representing the corresponding percentage. * **duration** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The duration of the vibration effect, in milliseconds. UIFLOW2: > ![once.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/init.png) VibratorHAT.set\_freq(_freq_)[](#VibratorHAT.set_freq "Link to this definition") Set the vibration frequency. Parameters: **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The frequency of vibration ranges from 10-55Hz. UIFLOW2: > ![set_freq.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/set_freq.png) VibratorHAT.set\_duty(_freq_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#VibratorHAT.set_duty "Link to this definition") Set the vibration duty cycle. Parameters: **duty** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The duty cycle of vibration ranges from 0-100, representing the corresponding percentage. UIFLOW2: > ![set_duty.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/set_duty.png) VibratorHAT.turn\_off() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#VibratorHAT.turn_off "Link to this definition") Turn off the motor. UIFLOW2: > ![turn_off.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/turn_off.png) VibratorHAT.deint() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#VibratorHAT.deint "Link to this definition") Deinitialize the motor. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/hat/vibrator/deinit.png) --- # requests2 — Network Request Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Software](index.html) * `requests2` — Network Request Module * [View page source](../_sources/software/requests2.rst.txt) * * * [`requests2`](#module-requests2 "requests2: Network Request Module") — Network Request Module[](#requests2-network-request-module "Link to this heading") ============================================================================================================================================================ requests2 is based on urequests and supports Streaming Uploads and x-www-form-urlencoded. The main functionality and function of the `requests2` module. 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 \* > 8import requests2 > 9 > 10 > 11label0 \= None > 12http\_req \= None > 13 > 14 > 15def setup(): > 16 global label0, http\_req > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 label0 \= Widgets.Label("label0", 6, 6, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 21 > 22 http\_req \= requests2.get( > 23 "https://httpbin.org/get", headers\={"Content-Type": "application/json"} > 24 ) > 25 label0.setText(str(http\_req.text)) > 26 > 27 > 28def loop(): > 29 global label0, http\_req > 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: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/software/http/example.png) [cores3\_http\_get\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/softwave/http/cores3_http_get_example.m5f2) Function[](#function "Link to this heading") ---------------------------------------------- requests2.request(_method_, _url_, _data\=None_, _json\=None_, _headers\={}_) → Response[](#requests2.requests2.request "Link to this definition") Send a network request, it will block the response data returned to the network, parameters: Parameters: * **method** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – method of establishing a network request. e.g. `HEAD`,\`\`GET\`\`,\`\`POST\`\`,\`\`PUT\`\`,\`\`PATCH\`\`, `DELETE`. * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **data** – (optional), a dictionary, tuple list \[(key, value)\] (will be form coded), byte or class file object sent in the request body. * **json** – (optional), json data sent in the request body. * **headers** ([_dict_](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") ) – (optional), HTTP header dictionary to be sent with the request. requests2.head(_url_, _\*\*kw_) → Response[](#requests2.requests2.head "Link to this definition") Send a `HEAD` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. requests2.get(_url_, _\*\*kw_) → Response[](#requests2.requests2.get "Link to this definition") Send a `GET` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. UIFLOW2: > ![get.png](https://static-cdn.m5stack.com/mpy_docs/software/http/requests.png) requests2.post(_url_, _\*\*kw_) → Response[](#requests2.requests2.post "Link to this definition") Send a `POST` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. UIFLOW2: > ![post.png](https://static-cdn.m5stack.com/mpy_docs/software/http/requests.png) requests2.put(_url_, _\*\*kw_) → Response[](#requests2.requests2.put "Link to this definition") Send a `PUT` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. UIFLOW2: > ![put.png](https://static-cdn.m5stack.com/mpy_docs/software/http/requests.png) requests2.patch(_url_, _\*\*kw_) → Response[](#requests2.requests2.patch "Link to this definition") Send a `PATCH` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. UIFLOW2: > ![patch.png](https://static-cdn.m5stack.com/mpy_docs/software/http/requests.png) requests2.delete(_url_, _\*\*kw_) → Response[](#requests2.requests2.delete "Link to this definition") Send a `DELETE` request, the return type is the response of the request, parameters: Parameters: * **url** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – URL of the network request. * **kw** – request optional parameters. UIFLOW2: > ![delete.png](https://static-cdn.m5stack.com/mpy_docs/software/http/requests.png) class Response[](#class-response "Link to this heading") ---------------------------------------------------------- Methods[](#methods "Link to this heading") -------------------------------------------- Response.headers[](#requests2.Response.headers "Link to this definition") Type: [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") Return the response header. UIFLOW2: > ![headers.png](https://static-cdn.m5stack.com/mpy_docs/software/http/headers.png) Response.status\_code[](#requests2.Response.status_code "Link to this definition") Type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") Return the status code of the response. UIFLOW2: > ![status_code.png](https://static-cdn.m5stack.com/mpy_docs/software/http/status_code.png) Response.close() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#requests2.Response.close "Link to this definition") Close the connection and release resources. UIFLOW2: > ![close.png](https://static-cdn.m5stack.com/mpy_docs/software/http/close.png) _property_ Response.content[](#requests2.Response.content "Link to this definition") Type: [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") Return the content of the response, in bytes. UIFLOW2: > ![content.png](https://static-cdn.m5stack.com/mpy_docs/software/http/content.png) _property_ Response.text[](#requests2.Response.text "Link to this definition") Type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") Return the content of the response, in str. UIFLOW2: > ![text.png](https://static-cdn.m5stack.com/mpy_docs/software/http/text.png) Response.json() → [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") [](#requests2.Response.json "Link to this definition") Return the content of the response, in dict. UIFLOW2: > ![json.png](https://static-cdn.m5stack.com/mpy_docs/software/http/json.png) --- # PM2.5 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * PM2.5 Module * [View page source](../_sources/module/pm25.rst.txt) * * * PM2.5 Module[](#pm2-5-module "Link to this heading") ====================================================== PM2.5 Air Quality Module is an ambient air quality testing Module. This product adopts PMSA003 digital universal particulate matter concentration sensor. It can quickly collect and calculate the number of suspended particles of different particle sizes in the air per unit volume. The other two versions come with the STH30 and SHT20, which can be used to measure ambient temperature and humidity. Support the following products: > | | | | > | --- | --- | --- | > | [![PM25Module](https://static-cdn.m5stack.com/resource/docs/products/module/PM2.5%20AIR%20QUALITY%20KIT%20(Excluding%20Core)/img-3fdafe0e-bb11-4ad5-b6d6-061919cc735b.webp)](https://static-cdn.m5stack.com/resource/docs/products/module/PM2.5%20AIR%20QUALITY%20KIT%20(Excluding%20Core)/img-3fdafe0e-bb11-4ad5-b6d6-061919cc735b.webp) | [![PM25Module-SHT20](https://static-cdn.m5stack.com/resource/docs/products/base/pm2.5/pm2.5_01.webp)](https://static-cdn.m5stack.com/resource/docs/products/base/pm2.5/pm2.5_01.webp) | [![PM25Module-SHT30](https://static-cdn.m5stack.com/resource/docs/products/app/PM2.5%20Air%20Quality%20Kit(SHT30)/img-1e1a8f8e-bea0-4cd1-a82d-274c22ad7e79.webp)](https://docs.m5stack.com/en/app/PM2.5%20Air%20Quality%20Kit(SHT30)) | 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 module import PM25Module > 9import time > 10 > 11 > 12title0 \= None > 13label9 \= None > 14label0 \= None > 15label10 \= None > 16label1 \= None > 17label2 \= None > 18label3 \= None > 19label4 \= None > 20label5 \= None > 21label6 \= None > 22label7 \= None > 23label8 \= None > 24pm25\_0 \= None > 25 > 26 > 27def setup(): > 28 global \\ > 29 title0, \\ > 30 label9, \\ > 31 label0, \\ > 32 label10, \\ > 33 label1, \\ > 34 label2, \\ > 35 label3, \\ > 36 label4, \\ > 37 label5, \\ > 38 label6, \\ > 39 label7, \\ > 40 label8, \\ > 41 pm25\_0 > 42 > 43 M5.begin() > 44 Widgets.fillScreen(0x222222) > 45 title0 \= Widgets.Title("PM2.5 Module Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 46 label9 \= Widgets.Label("Temp:", 191, 26, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 47 label0 \= Widgets.Label("PM1.0 Env:", 1, 26, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 48 label10 \= Widgets.Label("Humi:", 191, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 49 label1 \= Widgets.Label("PM2.5 Env:", 1, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 50 label2 \= Widgets.Label("PM10 Env:", 1, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 51 label3 \= Widgets.Label( > 52 "Particles 0.3um:", 1, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 53 ) > 54 label4 \= Widgets.Label( > 55 "Particles 0.5um:", 1, 124, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 56 ) > 57 label5 \= Widgets.Label( > 58 "Particles 1.0um:", 1, 145, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 59 ) > 60 label6 \= Widgets.Label( > 61 "Particles 2.5um:", 1, 167, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 62 ) > 63 label7 \= Widgets.Label( > 64 "Particles 5um:", 1, 189, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 65 ) > 66 label8 \= Widgets.Label( > 67 "Particles 10um:", 1, 210, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 68 ) > 69 > 70 pm25\_0 \= PM25Module(2) > 71 pm25\_0.set\_module\_mode(0) > 72 pm25\_0.set\_module\_power(True) > 73 print(pm25\_0.get\_module\_power()) > 74 > 75 > 76def loop(): > 77 global \\ > 78 title0, \\ > 79 label9, \\ > 80 label0, \\ > 81 label10, \\ > 82 label1, \\ > 83 label2, \\ > 84 label3, \\ > 85 label4, \\ > 86 label5, \\ > 87 label6, \\ > 88 label7, \\ > 89 label8, \\ > 90 pm25\_0 > 91 M5.update() > 92 pm25\_0.request\_air\_data() > 93 pm25\_0.refresh\_data() > 94 label0.setText(str((str("PM1.0 Env:") + str((pm25\_0.get\_pm\_data(3)))))) > 95 label1.setText(str((str("PM2.5 Env:") + str((pm25\_0.get\_pm\_data(4)))))) > 96 label2.setText(str((str("PM10 Env:") + str((pm25\_0.get\_pm\_data(5)))))) > 97 label3.setText(str((str("Particles 0.3um:") + str((pm25\_0.get\_pm\_data(6)))))) > 98 label4.setText(str((str("Particles 0.5um:") + str((pm25\_0.get\_pm\_data(7)))))) > 99 label5.setText(str((str("Particles 1.0um:") + str((pm25\_0.get\_pm\_data(8)))))) > 100 label6.setText(str((str("Particles 2.5um:") + str((pm25\_0.get\_pm\_data(9)))))) > 101 label7.setText(str((str("Particles 5um:") + str((pm25\_0.get\_pm\_data(10)))))) > 102 label8.setText(str((str("Particles 10um:") + str((pm25\_0.get\_pm\_data(11)))))) > 103 label9.setText(str((str("Temp:") + str((pm25\_0.get\_temperature()))))) > 104 label10.setText(str((str("Humi:") + str((pm25\_0.get\_humidity()))))) > 105 time.sleep\_ms(100) > 106 > 107 > 108if \_\_name\_\_ \== "\_\_main\_\_": > 109 try: > 110 setup() > 111 while True: > 112 loop() > 113 except (Exception, KeyboardInterrupt) as e: > 114 try: > 115 from utility import print\_error\_msg > 116 > 117 print\_error\_msg(e) > 118 except ImportError: > 119 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/example.png) [pm25\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/pm25/pm25_core2_example.m5f2) class PM25Module[](#class-pm25module "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ PM25Module[](#PM25Module "Link to this definition") Init Module PM2.5 with UART. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- PM25Module.set\_module\_power(_state_)[](#PM25Module.set_module_power "Link to this definition") Set the PM25Module power state. Parameters: **state** – Set to True to enable power, False to disable. UIFLOW2: > ![set_module_power.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/set_module_power.png) PM25Module.get\_module\_power() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#PM25Module.get_module_power "Link to this definition") Get the PM25Module power state. Parameters: **state** – Get the module power state. UIFLOW2: > ![get_module_power.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/get_module_power.png) PM25Module.set\_module\_mode(_mode_)[](#PM25Module.set_module_mode "Link to this definition") Set the PM25Module work mode. Parameters: **mode** – Options: * `Active mode`: 1 * `Passive mode`: 0 UIFLOW2: > ![set_module_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/set_module_mode.png) PM25Module.refresh\_data()[](#PM25Module.refresh_data "Link to this definition") Refresh the PM25Module data. Parameters: **mode** – Options: * `Active mode`: 1 * `Passive mode`: 0 UIFLOW2: > ![refresh_data.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/refresh_data.png) PM25Module.request\_air\_data()[](#PM25Module.request_air_data "Link to this definition") Request PM25Module air data. UIFLOW2: > ![request_air_data.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/request_air_data.png) PM25Module.get\_pm\_data(_data\_num_)[](#PM25Module.get_pm_data "Link to this definition") Select the type of particulate matter data to retrieve. Parameters: **data\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The options range from standard PM concentrations to counts of particles of specific sizes in 0.1 liters of air. Options: * `PM1.0 Concentration(Std)`: 0 * `PM2.5 Concentration(Std)`: 1 * `PM10 Concentration(Std)`: 2 * `PM1.0 Concentration(Env)`: 3 * `PM2.5 Concentration(Env)`: 4 * `PM10 Concentration(Env)`: 5 * `Particels more than 0.3um in 0.1 liters of air`: 6 * `Particels more than 0.5um in 0.1 liters of air`: 7 * `Particels more than 1.0um in 0.1 liters of air`: 8 * `Particels more than 2.5um in 0.1 liters of air`: 9 * `Particels more than 5.0um in 0.1 liters of air`: 10 * `Particels more than 10um in 0.1 liters of air`: 11 UIFLOW2: > ![get_pm_data.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/get_pm_data.png) PM25Module.get\_temperature()[](#PM25Module.get_temperature "Link to this definition") Get PM25Module environmental temperature data. UIFLOW2: > ![get_temperature.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/get_temperature.png) PM25Module.get\_humidity()[](#PM25Module.get_humidity "Link to this definition") Get PM25Module environmental humidity data. UIFLOW2: > ![get_humidity.png](https://static-cdn.m5stack.com/mpy_docs/module/pm25/get_humidity.png) --- # time – time related functions — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * `time` – time related functions * [View page source](../_sources/system/time.rst.txt) * * * [`time`](#module-time "time: time related functions") – time related functions[](#module-time "Link to this heading") ======================================================================================================================== The `time` module provides functions for getting the current time and date, measuring time intervals, and for delays. **Time Epoch**: It is January 1, 1970, 00:00:00 (UTC) on all platforms. Epoch year may be determined with `gmtime(0)[0]`. **Maintaining actual calendar date/time**: This requires a Real Time Clock (RTC). On systems with underlying OS (including some RTOS), an RTC may be implicit. Setting and maintaining actual calendar time is responsibility of OS/RTOS and is done outside of MicroPython, it just uses OS API to query date/time. On baremetal ports however system time depends on `machine.RTC()` object. The current calendar time may be set using `machine.RTC().datetime(tuple)` function, and maintained by following means: * By a backup battery (which may be an additional, optional component for a particular board). * Using networked time protocol (requires setup by a port/user). * Set manually by a user on each power-up (many boards then maintain RTC time across hard resets, though some may require setting it again in such case). If actual calendar time is not maintained with a system/MicroPython RTC, functions below which require reference to current absolute time may behave not as expected. 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 \* > 8import time > 9 > 10 > 11label0 \= None > 12label1 \= None > 13label2 \= None > 14label3 \= None > 15 > 16 > 17def setup(): > 18 global label0, label1, label2, label3 > 19 > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 label0 \= Widgets.Label("GMT-0 time:", 2, 20, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 23 label1 \= Widgets.Label("label1", 2, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 24 label2 \= Widgets.Label("GMT-2 time:", 2, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 label3 \= Widgets.Label("label3", 2, 140, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 > 27 time.timezone("GMT0") > 28 label1.setText(str(time.localtime())) > 29 time.timezone("GMT-8") > 30 label3.setText(str(time.localtime())) > 31 > 32 > 33def loop(): > 34 global label0, label1, label2, label3 > 35 M5.update() > 36 > 37 > 38if \_\_name\_\_ \== "\_\_main\_\_": > 39 try: > 40 setup() > 41 while True: > 42 loop() > 43 except (Exception, KeyboardInterrupt) as e: > 44 try: > 45 from utility import print\_error\_msg > 46 > 47 print\_error\_msg(e) > 48 except ImportError: > 49 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/system/time/example.png) [cores3\_time\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/time/cores3_time_example.m5f2) Functions[](#functions "Link to this heading") ------------------------------------------------ time.timezone(\[_tz_\])[](#time.timezone "Link to this definition") When no parameters are passed in, get the current time zone and return the string of the time zone. UIFLOW2: > ![timezone.png](https://static-cdn.m5stack.com/mpy_docs/system/time/timezone.png) Pass in a time zone string to set the time zone. The value of `tz` can be found at this [link](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) . UIFLOW2: > ![timezone1.png](https://static-cdn.m5stack.com/mpy_docs/system/time/timezone1.png) > > ![timezone2.png](https://static-cdn.m5stack.com/mpy_docs/system/time/timezone2.png) time.gmtime(\[_secs_\])[](#time.gmtime "Link to this definition") time.localtime(\[_secs_\])[](#time.localtime "Link to this definition") Convert the time _secs_ expressed in seconds since the Epoch (see above) into an 8-tuple which contains: `(year, month, mday, hour, minute, second, weekday, yearday)` If _secs_ is not provided or None, then the current time from the RTC is used. The gmtime() function returns a date-time tuple in UTC, and localtime() returns a date-time tuple in local time. The format of the entries in the 8-tuple are: * year includes the century (for example 2014). * month is 1-12 * mday is 1-31 * hour is 0-23 * minute is 0-59 * second is 0-59 * weekday is 0-6 for Mon-Sun * yearday is 1-366 UIFLOW2: > ![gmtime.png](https://static-cdn.m5stack.com/mpy_docs/system/time/gmtime.png) > > ![localtime.png](https://static-cdn.m5stack.com/mpy_docs/system/time/localtime.png) time.mktime()[](#time.mktime "Link to this definition") This is inverse function of localtime. It’s argument is a full 8-tuple which expresses a time as per localtime. It returns an integer which is the number of seconds since Jan 1, 2000. UIFLOW2: > ![mktime.png](https://static-cdn.m5stack.com/mpy_docs/system/time/mktime.png) > > ![mktime1.png](https://static-cdn.m5stack.com/mpy_docs/system/time/mktime1.png) time.sleep(_seconds_)[](#time.sleep "Link to this definition") Sleep for the given number of seconds. Some boards may accept _seconds_ as a floating-point number to sleep for a fractional number of seconds. Note that other boards may not accept a floating-point argument, for compatibility with them use sleep\_ms() and sleep\_us() functions. UIFLOW2: > ![sleep.png](https://static-cdn.m5stack.com/mpy_docs/system/time/sleep.png) time.sleep\_ms(_ms_)[](#time.sleep_ms "Link to this definition") Delay for given number of milliseconds, should be positive or 0. This function will delay for at least the given number of milliseconds, but may take longer than that if other processing must take place, for example interrupt handlers or other threads. Passing in 0 for _ms_ will still allow this other processing to occur. Use sleep\_us() for more precise delays. UIFLOW2: > ![sleep_ms.png](https://static-cdn.m5stack.com/mpy_docs/system/time/sleep_ms.png) time.sleep\_us(_us_)[](#time.sleep_us "Link to this definition") Delay for given number of microseconds, should be positive or 0. This function attempts to provide an accurate delay of at least _us_ microseconds, but it may take longer if the system has other higher priority processing to perform. UIFLOW2: > ![sleep_us.png](https://static-cdn.m5stack.com/mpy_docs/system/time/sleep_us.png) time.ticks\_ms()[](#time.ticks_ms "Link to this definition") Returns an increasing millisecond counter with an arbitrary reference point, that wraps around after some value. The wrap-around value is not explicitly exposed, but we will refer to it as _TICKS\_MAX_ to simplify discussion. Period of the values is _TICKS\_PERIOD = TICKS\_MAX + 1_. _TICKS\_PERIOD_ is guaranteed to be a power of two, but otherwise may differ from port to port. The same period value is used for all of ticks\_ms(), ticks\_us(), ticks\_cpu() functions (for simplicity). Thus, these functions will return a value in range \[_0_ .. _TICKS\_MAX_\], inclusive, total _TICKS\_PERIOD_ values. Note that only non-negative values are used. For the most part, you should treat values returned by these functions as opaque. The only operations available for them are ticks\_diff() and ticks\_add() functions described below. Note: Performing standard mathematical operations (+, -) or relational operators (<, <=, >, >=) directly on these value will lead to invalid result. Performing mathematical operations and then passing their results as arguments to ticks\_diff() or ticks\_add() will also lead to invalid results from the latter functions. UIFLOW2: > ![ticks_ms.png](https://static-cdn.m5stack.com/mpy_docs/system/time/ticks_ms.png) time.ticks\_us()[](#time.ticks_us "Link to this definition") > Just like ticks\_ms() above, but in microseconds. UIFLOW2: > ![ticks_ms.png](https://static-cdn.m5stack.com/mpy_docs/system/time/ticks_ms.png) time.ticks\_cpu()[](#time.ticks_cpu "Link to this definition") Similar to ticks\_ms() and ticks\_us(), but with the highest possible resolution in the system. This is usually CPU clocks, and that’s why the function is named that way. But it doesn’t have to be a CPU clock, some other timing source available in a system (e.g. high-resolution timer) can be used instead. The exact timing unit (resolution) of this function is not specified on `time` module level, but documentation for a specific port may provide more specific information. This function is intended for very fine benchmarking or very tight real-time loops. Avoid using it in portable code. Availability: Not every port implements this function. UIFLOW2: > ![ticks_cpu.png](https://static-cdn.m5stack.com/mpy_docs/system/time/ticks_cpu.png) time.ticks\_add(_ticks_, _delta_)[](#time.ticks_add "Link to this definition") Offset ticks value by a given number, which can be either positive or negative. Given a _ticks_ value, this function allows to calculate ticks value _delta_ ticks before or after it, following modular-arithmetic definition of tick values (see ticks\_ms() above). _ticks_ parameter must be a direct result of call to ticks\_ms(), ticks\_us(), or ticks\_cpu() functions (or from previous call to ticks\_add()). However, _delta_ can be an arbitrary integer number or numeric expression. ticks\_add() is useful for calculating deadlines for events/tasks. (Note: you must use ticks\_diff() function to work with deadlines.) Examples: \# Find out what ticks value there was 100ms ago print(ticks\_add(time.ticks\_ms(), \-100)) \# Calculate deadline for operation and test for it deadline \= ticks\_add(time.ticks\_ms(), 200) while ticks\_diff(deadline, time.ticks\_ms()) \> 0: do\_a\_little\_of\_something() \# Find out TICKS\_MAX used by this port print(ticks\_add(0, \-1)) UIFLOW2: > ![ticks_add.png](https://static-cdn.m5stack.com/mpy_docs/system/time/ticks_add.png) time.ticks\_diff(_ticks1_, _ticks2_)[](#time.ticks_diff "Link to this definition") Measure ticks difference between values returned from ticks\_ms(), ticks\_us(), or ticks\_cpu() functions, as a signed value which may wrap around. The argument order is the same as for subtraction operator, `ticks_diff(ticks1, ticks2)` has the same meaning as `ticks1 - ticks2`. However, values returned by ticks\_ms(), etc. functions may wrap around, so directly using subtraction on them will produce incorrect result. That is why ticks\_diff() is needed, it implements modular (or more specifically, ring) arithmetics to produce correct result even for wrap-around values (as long as they not too distant inbetween, see below). The function returns **signed** value in the range \[_\-TICKS\_PERIOD/2_ .. _TICKS\_PERIOD/2-1_\] (that’s a typical range definition for two’s-complement signed binary integers). If the result is negative, it means that _ticks1_ occurred earlier in time than _ticks2_. Otherwise, it means that _ticks1_ occurred after _ticks2_. This holds **only** if _ticks1_ and _ticks2_ are apart from each other for no more than _TICKS\_PERIOD/2-1_ ticks. If that does not hold, incorrect result will be returned. Specifically, if two tick values are apart for _TICKS\_PERIOD/2-1_ ticks, that value will be returned by the function. However, if _TICKS\_PERIOD/2_ of real-time ticks has passed between them, the function will return _\-TICKS\_PERIOD/2_ instead, i.e. result value will wrap around to the negative range of possible values. Informal rationale of the constraints above: Suppose you are locked in a room with no means to monitor passing of time except a standard 12-notch clock. Then if you look at dial-plate now, and don’t look again for another 13 hours (e.g., if you fall for a long sleep), then once you finally look again, it may seem to you that only 1 hour has passed. To avoid this mistake, just look at the clock regularly. Your application should do the same. “Too long sleep” metaphor also maps directly to application behaviour: don’t let your application run any single task for too long. Run tasks in steps, and do time-keeping inbetween. ticks\_diff() is designed to accommodate various usage patterns, among them: * Polling with timeout. In this case, the order of events is known, and you will deal only with positive results of ticks\_diff(): \# Wait for GPIO pin to be asserted, but at most 500us start \= time.ticks\_us() while pin.value() \== 0: if time.ticks\_diff(time.ticks\_us(), start) \> 500: raise TimeoutError * Scheduling events. In this case, ticks\_diff() result may be negative if an event is overdue: \# This code snippet is not optimized now \= time.ticks\_ms() scheduled\_time \= task.scheduled\_time() if ticks\_diff(scheduled\_time, now) \> 0: print("Too early, let's nap") sleep\_ms(ticks\_diff(scheduled\_time, now)) task.run() elif ticks\_diff(scheduled\_time, now) \== 0: print("Right at time!") task.run() elif ticks\_diff(scheduled\_time, now) < 0: print("Oops, running late, tell task to run faster!") task.run(run\_faster\=true) Note: Do not pass time() values to ticks\_diff(), you should use normal mathematical operations on them. But note that time() may (and will) also overflow. This is known as [https://en.wikipedia.org/wiki/Year\_2038\_problem](https://en.wikipedia.org/wiki/Year_2038_problem) . UIFLOW2: > ![ticks_diff.png](https://static-cdn.m5stack.com/mpy_docs/system/time/ticks_diff.png) time.time()[](#time.time "Link to this definition") Returns the number of seconds, as an integer, since the Epoch, assuming that underlying RTC is set and maintained as described above. If an RTC is not set, this function returns number of seconds since a port-specific reference point in time (for embedded boards without a battery-backed RTC, usually since power up or reset). If you want to develop portable MicroPython application, you should not rely on this function to provide higher than second precision. If you need higher precision, absolute timestamps, use time\_ns(). If relative times are acceptable then use the ticks\_ms() and ticks\_us() functions. If you need calendar time, gmtime() or localtime() without an argument is a better choice. Difference to CPython In CPython, this function returns number of seconds since Unix epoch, 1970-01-01 00:00 UTC, as a floating-point, usually having microsecond precision. With MicroPython, only Unix port uses the same Epoch, and if floating-point precision allows, returns sub-second precision. Embedded hardware usually doesn’t have floating-point precision to represent both long time ranges and subsecond precision, so they use integer value with second precision. Some embedded hardware also lacks battery-powered RTC, so returns number of seconds since last power-up or from other relative, hardware-specific point(e.g. reset). UIFLOW2: > ![time.png](https://static-cdn.m5stack.com/mpy_docs/system/time/time.png) time.time\_ns()[](#time.time_ns "Link to this definition") Similar to time() but returns nanoseconds since the Epoch, as an integer (usually a big integer, so will allocate on the heap). UIFLOW2: > None --- # class ImagePlus – display remote image — UIFlow2 Programming Guide master documentation * [](../index.html) * [`Widgets` — A basic UI library](index.html) * class ImagePlus – display remote image * [View page source](../_sources/widgets/image+.rst.txt) * * * class ImagePlus – display remote image[](#class-imageplus-display-remote-image "Link to this heading") ======================================================================================================== The ImagePlus class extends the Widgets.Image class to provide additional functionalities for handling images with dynamic updates. 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 image\_plus import ImagePlus > 9 > 10 > 11title0 \= None > 12image\_plus0 \= None > 13 > 14 > 15def setup(): > 16 global title0, image\_plus0 > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 title0 \= Widgets.Title("Image+ CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 21 image\_plus0 \= ImagePlus( > 22 "https://static-cdn.m5stack.com/resource/public/assets/aboutus/m5logo2022.png", > 23 43, > 24 51, > 25 True, > 26 3000, > 27 default\_img\="res/img/default.png", > 28 ) > 29 > 30 image\_plus0.setVisible(True) > 31 image\_plus0.set\_update\_period(5000) > 32 image\_plus0.set\_update\_enable(True) > 33 > 34 > 35def loop(): > 36 global title0, image\_plus0 > 37 M5.update() > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/example.png) [imageplus\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/widgets/image_plus/imageplus_cores3_example.m5f2.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Widgets.ImagePlus(_url_, _x_, _y_, _enable_, _period_, _default\_img\='res/img/default.jpg'_, _parent\=None_)[](#Widgets.ImagePlus "Link to this definition") Create an ImagePlus object. It accepts the following parameters: > * `url` is the URL of the image to be fetched and displayed. > > * `x` is the starting X-axis coordinate where the image will be displayed. > > * `y` is the starting Y-axis coordinate where the image will be displayed. > > * `enable` is a boolean indicating whether periodic updates of the image are enabled. > > * `period` is the update period in milliseconds when enable is True. > > * `default_img` is the path to the default image file to be displayed if the URL fetch fails. Supported formats are BMP, JPG, and PNG. Default is “res/img/default.jpg”. > > * `parent` is the graphical object on which the image will be drawn. If not provided, the default display will be used. > Methods[](#methods "Link to this heading") -------------------------------------------- ImagePlus.set\_update\_enable(_enable: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#Widgets.ImagePlus.set_update_enable "Link to this definition") Enable or disable periodic updates of the image. Accept the following parameters: > * `enable` is a boolean indicating whether updates should be enabled. > UIFLOW2: > ![set_update_enable.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/set_update_enable.png) ImagePlus.set\_update\_period(_period: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.ImagePlus.set_update_period "Link to this definition") Set the update period for fetching and displaying the image. Accept the following parameters: > * `period` is the update period in milliseconds. > UIFLOW2: > ![set_update_period.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/set_update_period.png) ImagePlus.setCursor(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.ImagePlus.setCursor "Link to this definition") Set the position of the ImagePlus object. Accept the following parameters: > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > UIFLOW2: > ![setCursor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/setCursor.png) ImagePlus.setVisible(_visible: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#Widgets.ImagePlus.setVisible "Link to this definition") Set the visibility of the ImagePlus object. Accept the following parameters: > * `visible` is the visibility of the displayed iamge. > UIFLOW2: > ![setVisible.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/setVisible.png) ImagePlus.is\_valid\_image() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Widgets.ImagePlus.is_valid_image "Link to this definition") Check if the fetched image is valid. Returns True if the image is valid, otherwise False. UIFLOW2: > ![is_valid_image.png](https://static-cdn.m5stack.com/mpy_docs/widgets/image_plus/is_valid_image.png) --- # PPS Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * PPS Module * [View page source](../_sources/module/pps.rst.txt) * * * PPS Module[](#pps-module "Link to this heading") ================================================== The PPS class controls a Programmable Power Supply (PPS), capable of providing an output up to 30V and 5A. It allows for precise control over the output voltage and current, with features to read back the actual output values and the module’s status. Support the following products: > [![PPSModule](https://static-cdn.m5stack.com/resource/docs/products/module/Module13.2-PPS/img-20342b36-9573-4baa-8c91-0952802bc631.webp)](https://docs.m5stack.com/en/module/PPS) 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 module import PPSModule > 9import time > 10 > 11 > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16label4 \= None > 17label5 \= None > 18pps\_0 \= None > 19 > 20 > 21def setup(): > 22 global label0, label1, label2, label3, label4, label5, pps\_0 > 23 > 24 M5.begin() > 25 Widgets.fillScreen(0x222222) > 26 label0 \= Widgets.Label( > 27 "Output Voltage:", 20, 40, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 28 ) > 29 label1 \= Widgets.Label( > 30 "Output Current:", 20, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 31 ) > 32 label2 \= Widgets.Label("Mode:", 22, 120, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 33 label3 \= Widgets.Label("label3", 180, 40, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 34 label4 \= Widgets.Label("label4", 180, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 35 label5 \= Widgets.Label("label5", 180, 120, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 36 > 37 pps\_0 \= PPSModule(address\=0x35) > 38 pps\_0.set\_output\_voltage(5.5) > 39 pps\_0.set\_output\_current(1) > 40 pps\_0.enable\_output() > 41 > 42 > 43def loop(): > 44 global label0, label1, label2, label3, label4, label5, pps\_0 > 45 M5.update() > 46 label3.setText(str(pps\_0.read\_output\_voltage())) > 47 label4.setText(str(pps\_0.read\_output\_current())) > 48 label5.setText(str(pps\_0.read\_psu\_running\_mode())) > 49 time.sleep\_ms(100) > 50 > 51 > 52if \_\_name\_\_ \== "\_\_main\_\_": > 53 try: > 54 setup() > 55 while True: > 56 loop() > 57 except (Exception, KeyboardInterrupt) as e: > 58 try: > 59 from utility import print\_error\_msg > 60 > 61 print\_error\_msg(e) > 62 except ImportError: > 63 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/example.png) [cores3\_pps\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/pps/cores3_pps_example.m5f2) class PPSModule[](#class-ppsmodule "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ PPSModule(_addr\=0x35_)[](#PPSModule "Link to this definition") Creates a PPS object to interact with the programmable power supply. * `addr`: I2C address of the PPS device (default is 0x35). Methods[](#methods "Link to this heading") -------------------------------------------- PPSModule.set\_output(_enable: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#PPSModule.set_output "Link to this definition") Enable or disable the PPS output. * `enable`: True to enable, False to disable. UIFLOW2: > ![set_output.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/set_output.png) PPSModule.enable\_output()[](#PPSModule.enable_output "Link to this definition") Enable the PPS output. UIFLOW2: > ![enable_output.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/enable_output.png) PPSModule.disable\_output()[](#PPSModule.disable_output "Link to this definition") Disable the PPS output. UIFLOW2: > ![disable_output.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/disable_output.png) PPSModule.set\_output\_voltage(_voltage: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") _)[](#PPSModule.set_output_voltage "Link to this definition") Set the output voltage of the PPS. * `voltage`: Desired output voltage from 0.0 to 30.0 volts. UIFLOW2: > ![set_output_voltage.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/set_output_voltage.png) PPSModule.set\_output\_current(_current: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") _)[](#PPSModule.set_output_current "Link to this definition") Set the output current of the PPS. * `current`: Desired output current from 0.0A to 5.0A. UIFLOW2: > ![set_output_current.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/set_output_current.png) PPSModule.read\_psu\_running\_mode() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PPSModule.read_psu_running_mode "Link to this definition") Read the PSU running mode. UIFLOW2: > ![read_psu_running_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_psu_running_mode.png) PPSModule.read\_output\_current() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#PPSModule.read_output_current "Link to this definition") Read the current output current. UIFLOW2: > ![read_output_current.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_output_current.png) PPSModule.read\_output\_voltage() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#PPSModule.read_output_voltage "Link to this definition") Read the current output voltage. UIFLOW2: > ![read_output_voltage.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_output_voltage.png) PPSModule.read\_input\_voltage() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#PPSModule.read_input_voltage "Link to this definition") Read the input voltage. UIFLOW2: > ![read_input_voltage.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_input_voltage.png) PPSModule.read\_data\_update\_flag() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PPSModule.read_data_update_flag "Link to this definition") Read the data update flag. UIFLOW2: > ![read_data_update_flag.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_data_update_flag.png) PPSModule.read\_mcu\_temperature() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#PPSModule.read_mcu_temperature "Link to this definition") Read the MCU temperature. UIFLOW2: > ![read_mcu_temperature.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_mcu_temperature.png) PPSModule.read\_module\_id() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PPSModule.read_module_id "Link to this definition") Read the module ID. UIFLOW2: > ![read_module_id.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_module_id.png) PPSModule.read\_uid() → [bytearray](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.13)") [](#PPSModule.read_uid "Link to this definition") Read the unique identifier (UID). UIFLOW2: > ![read_uid.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/read_uid.png) PPSModule.get\_i2c\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#PPSModule.get_i2c_address "Link to this definition") Get the current I2C address of the device. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/get_i2c_address.png) PPSModule.set\_i2c\_address(_new\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#PPSModule.set_i2c_address "Link to this definition") Set a new I2C address for the device. * `new_address`: The new I2C address to set. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/pps/set_i2c_address.png) --- # PwrCAN Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * PwrCAN Module * [View page source](../_sources/module/pwrcan.rst.txt) * * * PwrCAN Module[](#pwrcan-module "Link to this heading") ======================================================== PwrCAN Module 13.2 is a multifunctional module designed for the PwrCAN bus, integrating isolated CAN communication and DC 9-24V power bus. The module also includes Pwr485 (with isolation) bus functionality and can provide isolated 5V power supply to the M5 host. The CAN communication part uses the CA-IS3050G isolated transceiver, and the RS485 part uses the CA-IS3082W isolated transceiver. The GPIOs related to CAN and RS485 communication can be selected through dip switches, and the 120-ohm terminal resistance at the CAN and RS485 outputs can also be selected through dip switches. The module’s power bus supports DC 9-24V wide voltage input, with the DC socket directly connected to the HT3.96 and XT30 power parts. The built-in isolated power module F0505S-2WR3 provides power to the M5 host. This module is suitable for fields such as robot control, protocol conversion, industrial automation, automotive communication systems, intelligent transportation, and building automation. Supported Products: [![PwrCANModule](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/module/Module13.2-PwrCAN/4.webp)](https://docs.m5stack.com/en/module/Module13.2-PwrCAN) 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 module import PwrCANModule > 9from module import PwrCANModuleRS485 > 10from unit import RS485Unit > 11import time > 12 > 13 > 14title0 \= None > 15label3 \= None > 16label0 \= None > 17label1 \= None > 18label2 \= None > 19pwrcan\_0 \= None > 20pwrcan\_1 \= None > 21rs485\_0 \= None > 22 > 23 > 24def setup(): > 25 global title0, label3, label0, label1, label2, pwrcan\_0, pwrcan\_1, rs485\_0 > 26 > 27 M5.begin() > 28 Widgets.fillScreen(0x222222) > 29 title0 \= Widgets.Title( > 30 "PwrCANModule CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 31 ) > 32 label3 \= Widgets.Label("CAN Rec:", 0, 95, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 33 label0 \= Widgets.Label( > 34 "CAN Message State: ", 0, 49, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 35 ) > 36 label1 \= Widgets.Label( > 37 "RS485 Message State: ", 0, 138, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 38 ) > 39 label2 \= Widgets.Label("RS485 Rec:", 0, 179, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 40 > 41 pwrcan\_0 \= PwrCANModule(0, 17, 18, PwrCANModule.NORMAL, baudrate\=1000000) > 42 pwrcan\_1 \= PwrCANModuleRS485(1, baudrate\=115200, bits\=8, parity\=None, stop\=1, tx\=13, rx\=7) > 43 rs485\_0 \= RS485Unit( > 44 2, > 45 port\=(1, 2), > 46 baudrate\=115200, > 47 bits\=8, > 48 parity\=None, > 49 stop\=1, > 50 txbuf\=256, > 51 rxbuf\=256, > 52 timeout\=0, > 53 timeout\_char\=0, > 54 invert\=0, > 55 flow\=0, > 56 ) > 57 > 58 > 59def loop(): > 60 global title0, label3, label0, label1, label2, pwrcan\_0, pwrcan\_1, rs485\_0 > 61 M5.update() > 62 if M5.Touch.getCount(): > 63 pwrcan\_0.send("uiflow2", 0, timeout\=0, rtr\=False, extframe\=False) > 64 label0.setText(str("CAN Message State: Send")) > 65 pwrcan\_1.write("RS485\_uiflow2" + "\\r\\n") > 66 label1.setText(str("RS485 Message State: Send")) > 67 time.sleep(1) > 68 else: > 69 label0.setText(str("CAN Message State: Not Send")) > 70 label1.setText(str("RS485 Message State: Not Send")) > 71 if pwrcan\_0.any(0): > 72 label3.setText(str((str("CAN Rec:") + str((pwrcan\_0.recv(0, timeout\=5000)))))) > 73 if rs485\_0.any(): > 74 label2.setText(str((str("RS485 Rec:") + str((rs485\_0.read()))))) > 75 > 76 > 77if \_\_name\_\_ \== "\_\_main\_\_": > 78 try: > 79 setup() > 80 while True: > 81 loop() > 82 except (Exception, KeyboardInterrupt) as e: > 83 try: > 84 from utility import print\_error\_msg > 85 > 86 print\_error\_msg(e) > 87 except ImportError: > 88 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/example.png) [pwrcan\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/pwrcan/pwrcan_cores3_example.m5f2) class PwrCANModule[](#class-pwrcanmodule "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ PwrCANModule(_id_, _mode_, _tx_, _rx_, _prescaler\=32_, _sjw\=3_, _bs1\=15_, _bs2\=4_, _triple\_sampling\=False_) Initialise the CAN bus with the given parameters: > * `id` is the can bus id > > * `tx` is the pin to use for transmitting data > > * `rx` is the pin to use for receiving data > > * `mode` is one of: NORMAL, NO\_ACKNOWLEDGE, LISTEN\_ONLY > > * `prescaler` is the value by which the CAN input clock is divided to generate the nominal bit time quanta. The prescaler can be a value between 1 and 1024 inclusive for classic CAN. > > * `sjw` is the resynchronisation jump width in units of time quanta for nominal bits; it can be a value between 1 and 4 inclusive for classic CAN. > > * `bs1` defines the location of the sample point in units of the time quanta for nominal bits; it can be a value between 1 and 16 inclusive for classic CAN. > > * `bs2` defines the location of the transmit point in units of the time quanta for nominal bits; it can be a value between 1 and 8 inclusive for classic CAN. > > * `triple_sampling` is Enables triple sampling when the TWAI controller samples a bit > UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- PwrCANModule class inherits CAN class, See [hardware.CAN](../hardware/can.html#hardware-can) for more details. class PwrCANModuleRS485[](#class-pwrcanmodulers485 "Link to this heading") ---------------------------------------------------------------------------- Constructors[](#id1 "Link to this heading") --------------------------------------------- _class_ PwrCANModuleRS485(_id_, _baudrate=9600_, _bits=8_, _parity=None_, _stop=1_, _\*_, _..._)[](#PwrCANModuleRS485 "Link to this definition") Construct a UART object of the given id. For more parameters, please refer to init. UIFLOW2: > ![init_rs485.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/init_rs485.png) Methods[](#id2 "Link to this heading") ---------------------------------------- PwrCANModuleRS485.init(_baudrate=9600_, _bits=8_, _parity=None_, _stop=1_, _\*_, _..._)[](#PwrCANModuleRS485.init "Link to this definition") Initialise the UART bus with the given parameters: > * _baudrate_ is the clock rate. > > * _bits_ is the number of bits per character, 7, 8 or 9. > > * _parity_ is the parity, `None`, 0 (even) or 1 (odd). > > * _stop_ is the number of stop bits, 1 or 2. > Additional keyword-only parameters that may be supported by a port are: > * _tx_ specifies the TX pin to use. > > * _rx_ specifies the RX pin to use. > > * _rts_ specifies the RTS (output) pin to use for hardware receive flow control. > > * _cts_ specifies the CTS (input) pin to use for hardware transmit flow control. > > * _txbuf_ specifies the length in characters of the TX buffer. > > * _rxbuf_ specifies the length in characters of the RX buffer. > > * _timeout_ specifies the time to wait for the first character (in ms). > > * _timeout\_char_ specifies the time to wait between characters (in ms). > > * _invert_ specifies which lines to invert. > > > * `0` will not invert lines (idle state of both lines is logic high). > > > > * `PwrCANModuleRS485.INV_TX` will invert TX line (idle state of TX line now logic low). > > > > * `PwrCANModuleRS485.INV_RX` will invert RX line (idle state of RX line now logic low). > > > > * `PwrCANModuleRS485.INV_TX | PwrCANModuleRS485.INV_RX` will invert both lines (idle state at logic low). > > > > * _flow_ specifies which hardware flow control signals to use. The value is a bitmask. > > > * `0` will ignore hardware flow control signals. > > > > * `PwrCANModuleRS485.RTS` will enable receive flow control by using the RTS output pin to signal if the receive FIFO has sufficient space to accept more data. > > > > * `PwrCANModuleRS485.CTS` will enable transmit flow control by pausing transmission when the CTS input pin signals that the receiver is running low on buffer space. > > > > * `PwrCANModuleRS485.RTS | PwrCANModuleRS485.CTS` will enable both, for full hardware flow control. > > > Note It is possible to call `init()` multiple times on the same object in order to reconfigure UART on the fly. That allows using single UART peripheral to serve different devices attached to different GPIO pins. Only one device can be served at a time in that case. Also do not call `deinit()` as it will prevent calling `init()` again. UIFLOW2: > ![setup.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/setup.png) PwrCANModuleRS485.deinit()[](#PwrCANModuleRS485.deinit "Link to this definition") Turn off the UART bus. Note You will not be able to call `init()` on the object after `deinit()`. A new instance needs to be created in that case. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/deinit.png) PwrCANModuleRS485.any()[](#PwrCANModuleRS485.any "Link to this definition") Returns an integer counting the number of characters that can be read without blocking. It will return 0 if there are no characters available and a positive number if there are characters. The method may return 1 even if there is more than one character available for reading. For more sophisticated querying of available characters use select.poll: poll \= select.poll() poll.register(uart, select.POLLIN) poll.poll(timeout) UIFLOW2: > ![any.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/any.png) PwrCANModuleRS485.read(\[_nbytes_\])[](#PwrCANModuleRS485.read "Link to this definition") Read characters. If `nbytes` is specified then read at most that many bytes, otherwise read as much data as possible. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: a bytes object containing the bytes read in. Returns `None` on timeout. UIFLOW2: > ![read_all.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/read_all.png) > > ![read_bytes.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/read_bytes.png) PwrCANModuleRS485.readinto(_buf_\[, _nbytes_\])[](#PwrCANModuleRS485.readinto "Link to this definition") Read bytes into the `buf`. If `nbytes` is specified then read at most that many bytes. Otherwise, read at most `len(buf)` bytes. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: number of bytes read and stored into `buf` or `None` on timeout. UIFLOW2: > ![readinto.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/readinto.png) PwrCANModuleRS485.readline()[](#PwrCANModuleRS485.readline "Link to this definition") Read a line, ending in a newline character. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: the line read or `None` on timeout. UIFLOW2: > ![readline.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/readline.png) PwrCANModuleRS485.write(_buf_)[](#PwrCANModuleRS485.write "Link to this definition") Write the buffer of bytes to the bus. Return value: number of bytes written or `None` on timeout. UIFLOW2: > ![write.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/write.png) > > ![write_line.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/write_line.png) > > ![write_list.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/write_list.png) PwrCANModuleRS485.sendbreak()[](#PwrCANModuleRS485.sendbreak "Link to this definition") Send a break condition on the bus. This drives the bus low for a duration longer than required for a normal transmission of a character. UIFLOW2: > ![sendbreak.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/sendbreak.png) PwrCANModuleRS485.flush()[](#PwrCANModuleRS485.flush "Link to this definition") Waits until all data has been sent. In case of a timeout, an exception is raised. The timeout duration depends on the tx buffer size and the baud rate. Unless flow control is enabled, a timeout should not occur. Note For the rp2, esp8266 and nrf ports the call returns while the last byte is sent. If required, a one character wait time has to be added in the calling script. UIFLOW2: > ![flush.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/flush.png) PwrCANModuleRS485.txdone()[](#PwrCANModuleRS485.txdone "Link to this definition") Tells whether all data has been sent or no data transfer is happening. In this case, it returns `True`. If a data transmission is ongoing it returns `False`. Note For the rp2, esp8266 and nrf ports the call may return `True` even if the last byte of a transfer is still being sent. If required, a one character wait time has to be added in the calling script. UIFLOW2: > ![txdone.png](https://static-cdn.m5stack.com/mpy_docs/module/pwrcan/txdone.png) --- # Relay2 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Relay2 Module * [View page source](../_sources/module/relay_2.rst.txt) * * * Relay2 Module[](#relay2-module "Link to this heading") ======================================================== Support the following products: [![Relay2Module](https://static-cdn.m5stack.com/resource/docs/products/module/2Relay/img-07c98873-5b75-4c92-ab16-64c890c6166e.webp)](https://docs.m5stack.com/en/module/2Relay) Micropython Example: > 1\# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from module import Relay2Module > 8from hardware import \* > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16relay2\_0 \= None > 17 > 18 > 19def setup(): > 20 global title0, label0, label1, label2, label3, relay2\_0 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title("2Relay Module Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 label0 \= Widgets.Label("Relay 1:", 2, 53, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 label1 \= Widgets.Label("Relay 2:", 2, 119, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 label2 \= Widgets.Label("I2C Addr:", 1, 177, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 28 label3 \= Widgets.Label( > 29 "FW Version:", 181, 177, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 30 ) > 31 > 32 relay2\_0 \= Relay2Module(address\=0x25) > 33 label2.setText(str((str("I2C Addr:") + str((relay2\_0.get\_i2c\_address()))))) > 34 label3.setText(str((str("FW Version:") + str((relay2\_0.get\_firmware\_version()))))) > 35 > 36 > 37def loop(): > 38 global title0, label0, label1, label2, label3, relay2\_0 > 39 M5.update() > 40 label0.setText(str((str("Relay 1:") + str((relay2\_0.get\_relay\_status(1)))))) > 41 label1.setText(str((str("Relay 2:") + str((relay2\_0.get\_relay\_status(2)))))) > 42 if BtnA.isPressed(): > 43 relay2\_0.set\_relay\_state(1, 1) > 44 else: > 45 relay2\_0.set\_relay\_state(1, 0) > 46 if BtnB.isPressed(): > 47 relay2\_0.set\_relay\_state(2, 1) > 48 else: > 49 relay2\_0.set\_relay\_state(2, 0) > 50 > 51 > 52if \_\_name\_\_ \== "\_\_main\_\_": > 53 try: > 54 setup() > 55 while True: > 56 loop() > 57 except (Exception, KeyboardInterrupt) as e: > 58 try: > 59 from utility import print\_error\_msg > 60 > 61 print\_error\_msg(e) > 62 except ImportError: > 63 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/example.png) class Relay2Module[](#class-relay2module "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Relay2Module(_address_)[](#Relay2Module "Link to this definition") Initialize the 2Relay Module with the specified I2C address. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the Relay2Module. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Relay2Module.set\_relay\_state(_num_, _state_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Relay2Module.set_relay_state "Link to this definition") Set the state of a specific relay. Parameters: * **num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The relay number (1 or 2). * **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – True to turn on, False to turn off. UIFLOW2: > ![set_relay_state.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/set_relay_state.png) Relay2Module.get\_relay\_status(_num_) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Relay2Module.get_relay_status "Link to this definition") Get the status of a specific relay. Parameters: **num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The relay number (1 or 2). UIFLOW2: > ![get_relay_status.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/get_relay_status.png) Relay2Module.set\_all\_relay\_state(_state_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Relay2Module.set_all_relay_state "Link to this definition") Set the state of both relays simultaneously. Parameters: **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – True to turn on both relays, False to turn off both relays. UIFLOW2: > ![set_all_relay_state.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/set_all_relay_state.png) Relay2Module.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Relay2Module.get_firmware_version "Link to this definition") Get the firmware version of the Relay2 Module. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/get_firmware_version.png) Relay2Module.set\_i2c\_address(_addr_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Relay2Module.set_i2c_address "Link to this definition") Set a new I2C address(0x08~0x77) for the Relay2 Module. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address to set. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/set_i2c_address.png) Relay2Module.get\_i2c\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Relay2Module.get_i2c_address "Link to this definition") Get the current I2C address of the Relay2 Module. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/2relay/get_i2c_address.png) --- # Servo2 Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Servo2 Module * [View page source](../_sources/module/servo2.rst.txt) * * * Servo2 Module[](#servo2-module "Link to this heading") ======================================================== SERVO 2 is an updated servo driver module in the M5Stack stackable module series. It uses a PCA9685 16 channel PWM controller to control 16 channel servos at the same time. The power input is 6-12V DC and two SY8368AQQC chips are used for voltage reduction. Support the following products: [![Servo2Module](https://static-cdn.m5stack.com/resource/docs/products/module/servo2/servo2_01.webp)](https://docs.m5stack.com/en/module/servo2) Micropython Example: import os, sys, io import M5 from M5 import \* from module import Servo2Module servo \= Servo2Module() servo.position(0, degrees\=90) servo.release() UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/example.png) class Servo2Module[](#class-servo2module "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Servo2Module(_address_, _freq_, _min\_us_, _max\_us_, _degrees_)[](#Servo2Module "Link to this definition") Create a Servo instance. Parameters: * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address. * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency in Hz. * **min\_us** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The minimum pulse width in microseconds. * **max\_us** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The maximum pulse width in microseconds. * **degrees** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The maximum angle in degrees. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Servo2Module.position(_index_, _degrees_, _radians_, _us_, _duty_)[](#Servo2Module.position "Link to this definition") Set the servo position. Parameters: * **index** – The channel index. * **degrees** – The angle in degrees. * **radians** – The angle in radians. * **us** – The pulse width in microseconds. * **duty** – The duty cycle in percent. UIFLOW2: > ![set_degrees.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/set_degrees.png) > > ![set_duty.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/set_duty.png) > > ![set_pulse_width.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/set_pulse_width.png) > > ![set_radians.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/set_radians.png) Servo2Module.release(_index_)[](#Servo2Module.release "Link to this definition") Release the servo. Parameters: **index** – The channel index. UIFLOW2: > ![release.png](https://static-cdn.m5stack.com/mpy_docs/module/servo2/release.png) --- # StepMotorDriver Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * StepMotorDriver Module * [View page source](../_sources/module/step_motor_driver.rst.txt) * * * StepMotorDriver Module[](#stepmotordriver-module "Link to this heading") ========================================================================== StepMotor Driver Module 13.2 V1.1 is a stepper motor driver adapted to M5 main control, using STM32+HR8825 stepper motor drive scheme, providing 3-way bipolar stepper motor control interface. Support the following products: [![StepMotorDriverModule](https://static-cdn.m5stack.com/resource/docs/products/module/Stepmotor%20Driver%20Module13.2%20v1.1/img-c2b8ceac-b6be-4cec-9a15-228fcf8623e7.webp)](https://docs.m5stack.com/en/module/Stepmotor%20Driver%20Module13.2%20v1.1) 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 module import StepMotorDriverModule > 9import time > 10 > 11 > 12stepmotor\_driver\_0 \= None > 13 > 14 > 15DIR \= None > 16 > 17 > 18def setup(): > 19 global stepmotor\_driver\_0, DIR > 20 > 21 M5.begin() > 22 Widgets.fillScreen(0x222222) > 23 > 24 stepmotor\_driver\_0 \= StepMotorDriverModule( > 25 address\=0x27, step\_pin\=(16, 12, 15), dir\_pin\=(17, 13, 0) > 26 ) > 27 print(stepmotor\_driver\_0.get\_all\_limit\_switch\_state()) > 28 print(stepmotor\_driver\_0.get\_limit\_switch\_state(0)) > 29 print(stepmotor\_driver\_0.get\_fault\_io\_state(StepMotorDriverModule.MOTOR\_X)) > 30 print(stepmotor\_driver\_0.get\_firmware\_version()) > 31 stepmotor\_driver\_0.reset\_motor( > 32 StepMotorDriverModule.MOTOR\_X, StepMotorDriverModule.MOTOR\_STATE\_ENABLE > 33 ) > 34 stepmotor\_driver\_0.set\_motor\_state(StepMotorDriverModule.MOTOR\_STATE\_ENABLE) > 35 stepmotor\_driver\_0.set\_microstep(StepMotorDriverModule.STEP\_FULL) > 36 stepmotor\_driver\_0.set\_motor\_direction(StepMotorDriverModule.MOTOR\_X, 1) > 37 stepmotor\_driver\_0.set\_motor\_pwm\_freq(StepMotorDriverModule.MOTOR\_X, 1000) > 38 stepmotor\_driver\_0.motor\_control(StepMotorDriverModule.MOTOR\_X, 1) > 39 DIR \= 0 > 40 > 41 > 42def loop(): > 43 global stepmotor\_driver\_0, DIR > 44 M5.update() > 45 if DIR: > 46 stepmotor\_driver\_0.set\_motor\_direction(StepMotorDriverModule.MOTOR\_X, 1) > 47 else: > 48 stepmotor\_driver\_0.set\_motor\_direction(StepMotorDriverModule.MOTOR\_X, 0) > 49 DIR \= not DIR > 50 time.sleep(2) > 51 > 52 > 53if \_\_name\_\_ \== "\_\_main\_\_": > 54 try: > 55 setup() > 56 while True: > 57 loop() > 58 except (Exception, KeyboardInterrupt) as e: > 59 try: > 60 from utility import print\_error\_msg > 61 > 62 print\_error\_msg(e) > 63 except ImportError: > 64 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/example.png) [step\_motor\_driver.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/step_motor_driver/step_motor_driver.m5f2) class StepMotorDriverModule[](#class-stepmotordrivermodule "Link to this heading") ------------------------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ StepMotorDriverModule(_address_, _step\_pin_, _dir\_pin_)[](#StepMotorDriverModule "Link to this definition") Initialize the StepMotorDriverModule. Parameters: * **address** (_hex_) – The I2C address of the device. * **step\_pin** ([_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – The step pin (X, Y, Z) of the motor. * **dir\_pin** ([_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – The dir pin (X, Y, Z) of the motor. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- StepMotorDriverModule.reset\_motor(_motor\_id_, _state_)[](#StepMotorDriverModule.reset_motor "Link to this definition") Reset the motor. Parameters: * **motor\_id** – The motor to reset. Options: - `X`: StepMotorDriverModule.MOTOR\_X - `Y`: StepMotorDriverModule.MOTOR\_Y - `Z`: StepMotorDriverModule.MOTOR\_Z * **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – The state of the motor. UIFLOW2: > ![reset_motor.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/reset_motor.png) StepMotorDriverModule.set\_motor\_state(_state_)[](#StepMotorDriverModule.set_motor_state "Link to this definition") Enable or disable the motor. Parameters: **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – The state of the motor. UIFLOW2: > ![set_motor_state.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/set_motor_state.png) StepMotorDriverModule.set\_microstep(_step_)[](#StepMotorDriverModule.set_microstep "Link to this definition") Set the microstep. Parameters: **step** – The microstep value. Options: - `FULL`: StepMotorDriverModule.STEP\_FULL - `1/2`: StepMotorDriverModule.STEP1\_2 - `1/4`: StepMotorDriverModule.STEP1\_4 - `1/8`: StepMotorDriverModule.STEP1\_8 - `1/16`: StepMotorDriverModule.STEP1\_16 - `1/32`: StepMotorDriverModule.STEP1\_32 UIFLOW2: > ![set_microstep.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/set_microstep.png) StepMotorDriverModule.set\_motor\_pwm\_freq(_motor\_id_, _freq_)[](#StepMotorDriverModule.set_motor_pwm_freq "Link to this definition") Set the motor pwm freq. Parameters: * **motor\_id** – The motor to set the freq. Options: - `X`: StepMotorDriverModule.MOTOR\_X - `Y`: StepMotorDriverModule.MOTOR\_Y - `Z`: StepMotorDriverModule.MOTOR\_Z * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The freq value. UIFLOW2: > ![set_motor_pwm_freq.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/set_motor_pwm_freq.png) StepMotorDriverModule.set\_motor\_direction(_motor\_id_, _direction_)[](#StepMotorDriverModule.set_motor_direction "Link to this definition") Set the motor direction. Parameters: * **motor\_id** – The motor to set the direction. Options: - `X`: StepMotorDriverModule.MOTOR\_X - `Y`: StepMotorDriverModule.MOTOR\_Y - `Z`: StepMotorDriverModule.MOTOR\_Z * **direction** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – The direction value. Options: - `Positive`: 1 - `Negative`: 0 UIFLOW2: > ![set_motor_direction.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/set_motor_direction.png) StepMotorDriverModule.get\_all\_limit\_switch\_state()[](#StepMotorDriverModule.get_all_limit_switch_state "Link to this definition") Get all io state. UIFLOW2: > ![get_all_limit_switch_state.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/get_all_limit_switch_state.png) StepMotorDriverModule.get\_limit\_switch\_state(_switch\_id_)[](#StepMotorDriverModule.get_limit_switch_state "Link to this definition") Get the io state. Parameters: **switch\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The io id. UIFLOW2: > ![get_limit_switch_state.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/get_limit_switch_state.png) StepMotorDriverModule.get\_fault\_io\_state(_motor\_id_)[](#StepMotorDriverModule.get_fault_io_state "Link to this definition") Get the fault io state. Parameters: **motor\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor id. Options: - `X`: StepMotorDriverModule.MOTOR\_X - `Y`: StepMotorDriverModule.MOTOR\_Y - `Z`: StepMotorDriverModule.MOTOR\_Z UIFLOW2: > ![get_fault_io_state.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/get_fault_io_state.png) StepMotorDriverModule.motor\_control(_motor\_id_, _state_)[](#StepMotorDriverModule.motor_control "Link to this definition") Control the motor to rotate/stop. Parameters: * **motor\_id** – The motor id. Options: - `X`: StepMotorDriverModule.MOTOR\_X - `Y`: StepMotorDriverModule.MOTOR\_Y - `Z`: StepMotorDriverModule.MOTOR\_Z * **state** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – The state value. Options: - `Rotate`: 1 - `Stop`: 0 UIFLOW2: > ![motor_control.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/motor_control.png) StepMotorDriverModule.get\_firmware\_version()[](#StepMotorDriverModule.get_firmware_version "Link to this definition") Get the firmware version. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/get_firmware_version.png) StepMotorDriverModule.set\_i2c\_address(_new\_address_)[](#StepMotorDriverModule.set_i2c_address "Link to this definition") Set the i2c address. Parameters: **new\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new address. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/module/stepmotor_driver/set_i2c_address.png) Constants[](#constants "Link to this heading") ------------------------------------------------ > StepMotorDriverModule.MOTOR\_X[](#StepMotorDriverModule.MOTOR_X "Link to this definition") > > StepMotorDriverModule.MOTOR\_Y[](#StepMotorDriverModule.MOTOR_Y "Link to this definition") > > StepMotorDriverModule.MOTOR\_Z[](#StepMotorDriverModule.MOTOR_Z "Link to this definition") > > Motor IDs > > StepMotorDriverModule.MOTOR\_STATE\_ENABLE[](#StepMotorDriverModule.MOTOR_STATE_ENABLE "Link to this definition") > > StepMotorDriverModule.MOTOR\_STATE\_DISABLE[](#StepMotorDriverModule.MOTOR_STATE_DISABLE "Link to this definition") > > Motor states > > StepMotorDriverModule.INPUT\_REG[](#StepMotorDriverModule.INPUT_REG "Link to this definition") > > StepMotorDriverModule.OUTPUT\_REG[](#StepMotorDriverModule.OUTPUT_REG "Link to this definition") > > StepMotorDriverModule.POLINV\_REG[](#StepMotorDriverModule.POLINV_REG "Link to this definition") > > StepMotorDriverModule.CONFIG\_REG[](#StepMotorDriverModule.CONFIG_REG "Link to this definition") > > StepMotorDriverModule.FAULT\_REG[](#StepMotorDriverModule.FAULT_REG "Link to this definition") > > StepMotorDriverModule.RESET\_REG[](#StepMotorDriverModule.RESET_REG "Link to this definition") > > StepMotorDriverModule.FIRM\_REG[](#StepMotorDriverModule.FIRM_REG "Link to this definition") > > StepMotorDriverModule.I2C\_REG[](#StepMotorDriverModule.I2C_REG "Link to this definition") > > Register addresses > > StepMotorDriverModule.STEP\_FULL[](#StepMotorDriverModule.STEP_FULL "Link to this definition") > > StepMotorDriverModule.STEP1\_2[](#StepMotorDriverModule.STEP1_2 "Link to this definition") > > StepMotorDriverModule.STEP1\_4[](#StepMotorDriverModule.STEP1_4 "Link to this definition") > > StepMotorDriverModule.STEP1\_8[](#StepMotorDriverModule.STEP1_8 "Link to this definition") > > StepMotorDriverModule.STEP1\_16[](#StepMotorDriverModule.STEP1_16 "Link to this definition") > > StepMotorDriverModule.STEP1\_32[](#StepMotorDriverModule.STEP1_32 "Link to this definition") > > Microstep values --- # RCA Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * RCA Module * [View page source](../_sources/module/rca.rst.txt) * * * RCA Module[](#rca-module "Link to this heading") ================================================== Module RCA is a female jack terminal block for transmitting composite video (audio or video), one of the most common A/V connectors, which transmits video or audio signals from a component device to an output device (i.e., a display or speaker). Support the following products: > [![RCAModule](https://static-cdn.m5stack.com/resource/docs/products/unit/RCA/img-9420bb3d-22b8-4f80-b7fe-e708088f1e51.webp)](https://docs.m5stack.com/en/unit/RCA) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Draw Text[](#draw-text "Link to this heading") Open the [core2\_rca\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/rca/core2_rca_example.m5f2) project in UiFlow2. This example displays the text “RCA” on the screen. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/module/rca/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Draw Text[](#id1 "Link to this heading") This example displays the text “RCA” on the screen. MicroPython Code Block: > 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 module import RCAModule > 9 > 10 > 11label0 \= None > 12label1 \= None > 13module\_rca \= None > 14 > 15 > 16def setup(): > 17 global label0, label1, module\_rca > 18 > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 label0 \= Widgets.Label("Core2", 133, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 module\_rca \= RCAModule( > 24 26, > 25 width\=216, > 26 height\=144, > 27 output\_width\=0, > 28 output\_height\=0, > 29 signal\_type\=RCAModule.NTSC, > 30 use\_psram\=0, > 31 output\_level\=0, > 32 ) > 33 label1 \= Widgets.Label( > 34 "RCA", 88, 61, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18, module\_rca > 35 ) > 36 > 37 > 38def loop(): > 39 global label0, label1, module\_rca > 40 M5.update() > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Class RCAModule[](#class-rcamodule "Link to this heading") _class_ module.rca.RCAModule(_pin\=26_, _width\=216_, _height\=144_, _output\_width\=216_, _output\_height\=144_, _signal\_type\=0_, _use\_psram\=0_, _output\_level\=0_)[](#module.rca.RCAModule "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Initialize the RCA Module. Parameters: * **pin** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The dac pin to which the RCA Module is connected. * **width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The width of the RCA display. * **height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The height of the RCA display. * **output\_width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The width of the output of the RCA display. * **output\_height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The height of the output of the RCA display. * **signal\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The signal type of the RCA display. NTSC=0, NTSC\_J=1, PAL=2, PAL\_M=3, PAL\_N=4. * **use\_psram** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The use of psram of the RCA display. * **output\_level** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The output level of the RCA display. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/rca/init.png) MicroPython Code Block: > from module import RCAModule > module\_rca \= RCAModule(26, width\=216, height\=144, output\_width\=0, output\_height\=0, signal\_type\=RCAModule.NTSC, use\_psram\=0, output\_level\=0) RCAModule class inherits Display class, See [hardware.Display](../hardware/display.html#hardware-display) for more details. NTSC _\= 0_[](#module.rca.RCAModule.NTSC "Link to this definition") signal type. National Television System Committee. NTSC\_J _\= 1_[](#module.rca.RCAModule.NTSC_J "Link to this definition") signal type. National Television System Committee Japan. PAL _\= 2_[](#module.rca.RCAModule.PAL "Link to this definition") signal type. Phase Alternating Line. PAL\_M _\= 3_[](#module.rca.RCAModule.PAL_M "Link to this definition") signal type. Phase Alternating Line M. PAL\_N _\= 4_[](#module.rca.RCAModule.PAL_N "Link to this definition") signal type. Phase Alternating Line N. --- # QRCode Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * QRCode Module * [View page source](../_sources/module/qrcode.rst.txt) * * * QRCode Module[](#qrcode-module "Link to this heading") ======================================================== This library is the driver for Module13.2 QRCode, and the module communicates via UART. Support the following products: > [![Module13.2 QRCode](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/module/QRCodeModule/4.webp)](https://docs.m5stack.com/zh_CN/module/QRCodeModule) UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### QRCode Scan in Continuous Mode[](#qrcode-scan-in-continuous-mode "Link to this heading") Open the [cores3\_qrcode\_continuous\_mode\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/qrcode/cores3_qrcode_continuous_mode_example.m5f2) project in UiFlow2. In **Continuous Mode**, pressing the button once starts decoding, and pressing the button again stops decoding. UiFlow2 Code Block: > ![cores3_qrcode_continuous_mode_example.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/continuous_mode_example.png) Example output: > None ### QRCode Scan in Auto Mode[](#qrcode-scan-in-auto-mode "Link to this heading") Open the [cores3\_qrcode\_auto\_mode\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/qrcode/cores3_qrcode_auto_mode_example.m5f2) project in UiFlow2. In **Auto Mode**, the module starts decoding when powered on and cannot be stopped. UiFlow2 Code Block: > ![cores3_qrcode_auto_mode_example.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/auto_mode_example.png) Example output: > None ### QRCode Scan in Pulse Mode[](#qrcode-scan-in-pulse-mode "Link to this heading") Open the [cores3\_qrcode\_pulse\_mode\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/qrcode/cores3_qrcode_pulse_mode_example.m5f2) project in UiFlow2. In **Pulse Mode**, set the TRIG pin to hold a low level for more than 20ms to trigger decoding once. UiFlow2 Code Block: > ![cores3_qrcode_pulse_mode_example.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/pulse_mode_example.png) Example output: > None ### QRCode Scan in Motion Sensing Mode[](#qrcode-scan-in-motion-sensing-mode "Link to this heading") Open the [cores3\_qrcode\_motion\_sensing\_mode\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/qrcode/cores3_qrcode_motion_sensing_mode_example.m5f2) project in UiFlow2. In **Motion Sensing Mode**, the module automatically triggers decoding when it detects a change in the scene based on visual recognition information. UiFlow2 Code Block: > ![cores3_qrcode_motion_sensing_mode_example.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/motion_sensing_mode_example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### QRCode Scan in Continuous Mode[](#id1 "Link to this heading") In **Continuous Mode**, pressing the button once starts decoding, and pressing the button again stops decoding. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import QRCodeModule > 9 > 10 > 11title0 \= None > 12label\_status \= None > 13label\_data \= None > 14module\_qrcode\_0 \= None > 15is\_scanning \= None > 16data \= None > 17 > 18 > 19def btn\_pwr\_was\_clicked\_event(state): > 20 global title0, label\_status, label\_data, module\_qrcode\_0, is\_scanning, data > 21 if is\_scanning: > 22 module\_qrcode\_0.stop\_decode() > 23 label\_status.setColor(0xFFFFFF, 0x222222) > 24 label\_status.setText(str("stop scan")) > 25 else: > 26 module\_qrcode\_0.start\_decode() > 27 label\_status.setColor(0x00FF00, 0x222222) > 28 label\_status.setText(str("scanning")) > 29 is\_scanning \= not is\_scanning > 30 > 31 > 32def setup(): > 33 global title0, label\_status, label\_data, module\_qrcode\_0, is\_scanning, data > 34 M5.begin() > 35 Widgets.fillScreen(0x222222) > 36 title0 \= Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 37 label\_status \= Widgets.Label( > 38 "stop scan", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24 > 39 ) > 40 label\_data \= Widgets.Label("data", 4, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) > 41 BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btn\_pwr\_was\_clicked\_event) > 42 module\_qrcode\_0 \= QRCodeModule(1, tx\=17, rx\=18) > 43 module\_qrcode\_0.set\_trigger\_mode(QRCodeModule.TRIGGER\_MODE\_CONTINUOUS) > 44 module\_qrcode\_0.stop\_decode() > 45 is\_scanning \= False > 46 > 47 > 48def loop(): > 49 global title0, label\_status, label\_data, module\_qrcode\_0, is\_scanning, data > 50 M5.update() > 51 data \= module\_qrcode\_0.read() > 52 if data: > 53 label\_data.setText(str(data.decode())) > 54 print(data.decode()) > 55 > 56 > 57if \_\_name\_\_ \== "\_\_main\_\_": > 58 try: > 59 setup() > 60 while True: > 61 loop() > 62 except (Exception, KeyboardInterrupt) as e: > 63 try: > 64 from utility import print\_error\_msg > 65 > 66 print\_error\_msg(e) > 67 except ImportError: > 68 print("please update to latest firmware") Example output: > None ### QRCode Scan in Auto Mode[](#id2 "Link to this heading") In **Auto Mode**, the module starts decoding when powered on and cannot be stopped. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import QRCodeModule > 9 > 10 > 11title0 \= None > 12label\_status \= None > 13label\_data \= None > 14module\_qrcode\_0 \= None > 15data \= None > 16 > 17 > 18def setup(): > 19 global title0, label\_status, label\_data, module\_qrcode\_0, data > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 title0 \= Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 23 label\_status \= Widgets.Label( > 24 "scanning", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24 > 25 ) > 26 label\_data \= Widgets.Label("data", 5, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) > 27 module\_qrcode\_0 \= QRCodeModule(2, tx\=17, rx\=18) > 28 module\_qrcode\_0.set\_trigger\_mode(QRCodeModule.TRIGGER\_MODE\_AUTO) > 29 > 30 > 31def loop(): > 32 global title0, label\_status, label\_data, module\_qrcode\_0, data > 33 M5.update() > 34 data \= module\_qrcode\_0.read() > 35 if data: > 36 label\_data.setText(str(data.decode())) > 37 > 38 > 39if \_\_name\_\_ \== "\_\_main\_\_": > 40 try: > 41 setup() > 42 while True: > 43 loop() > 44 except (Exception, KeyboardInterrupt) as e: > 45 try: > 46 from utility import print\_error\_msg > 47 > 48 print\_error\_msg(e) > 49 except ImportError: > 50 print("please update to latest firmware") Example output: > None ### QRCode Scan in Pulse Mode[](#id3 "Link to this heading") In **Pulse Mode**, set the TRIG pin to hold a low level for more than 20ms to trigger decoding once. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import QRCodeModule > 9import time > 10 > 11 > 12title0 \= None > 13label\_status \= None > 14label\_data \= None > 15module\_qrcode\_0 \= None > 16data \= None > 17 > 18 > 19def btn\_pwr\_was\_clicked\_event(state): > 20 global title0, label\_status, label\_data, module\_qrcode\_0, data > 21 module\_qrcode\_0.set\_trig(0) > 22 time.sleep\_ms(20) > 23 module\_qrcode\_0.set\_trig(1) > 24 label\_status.setColor(0x00FF00, 0x222222) > 25 label\_status.setText(str("scanning")) > 26 > 27 > 28def setup(): > 29 global title0, label\_status, label\_data, module\_qrcode\_0, data > 30 M5.begin() > 31 Widgets.fillScreen(0x222222) > 32 title0 \= Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 33 label\_status \= Widgets.Label( > 34 "scanning", 5, 50, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24 > 35 ) > 36 label\_data \= Widgets.Label("data", 5, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) > 37 BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btn\_pwr\_was\_clicked\_event) > 38 module\_qrcode\_0 \= QRCodeModule(2, tx\=17, rx\=18) > 39 module\_qrcode\_0.set\_trigger\_mode(QRCodeModule.TRIGGER\_MODE\_PULSE) > 40 > 41 > 42def loop(): > 43 global title0, label\_status, label\_data, module\_qrcode\_0, data > 44 M5.update() > 45 data \= module\_qrcode\_0.read() > 46 if data: > 47 label\_data.setText(str(data.decode())) > 48 label\_status.setColor(0xFFFFFF, 0x222222) > 49 label\_status.setText(str("stop scan")) > 50 > 51 > 52if \_\_name\_\_ \== "\_\_main\_\_": > 53 try: > 54 setup() > 55 while True: > 56 loop() > 57 except (Exception, KeyboardInterrupt) as e: > 58 try: > 59 from utility import print\_error\_msg > 60 > 61 print\_error\_msg(e) > 62 except ImportError: > 63 print("please update to latest firmware") Example output: > None ### QRCode Scan in Motion Sensing Mode[](#id4 "Link to this heading") In **Motion Sensing Mode**, the module automatically triggers decoding when it detects a change in the scene based on visual recognition information. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from module import QRCodeModule > 9 > 10 > 11title0 \= None > 12label\_status \= None > 13label\_data \= None > 14module\_qrcode\_0 \= None > 15data \= None > 16 > 17 > 18def setup(): > 19 global title0, label\_status, label\_data, module\_qrcode\_0, data > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 title0 \= Widgets.Title("QRCode", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) > 23 label\_status \= Widgets.Label( > 24 "detecting", 5, 50, 1.0, 0x00FF00, 0x222222, Widgets.FONTS.DejaVu24 > 25 ) > 26 label\_data \= Widgets.Label("data", 5, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) > 27 module\_qrcode\_0 \= QRCodeModule(2, tx\=17, rx\=18) > 28 module\_qrcode\_0.set\_trigger\_mode(QRCodeModule.TRIGGER\_MODE\_MOTION\_SENSING) > 29 module\_qrcode\_0.set\_motion\_sensitivity(1) > 30 > 31 > 32def loop(): > 33 global title0, label\_status, label\_data, module\_qrcode\_0, data > 34 M5.update() > 35 data \= module\_qrcode\_0.read() > 36 if data: > 37 label\_data.setText(str(data.decode())) > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### QRCodeModule[](#qrcodemodule "Link to this heading") _class_ module.qrcode.QRCodeModule[](#module.qrcode.QRCodeModule "Link to this definition") Create an QRCodeModule object. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART id. * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART TX pin. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – the UART RX pin. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/init.png) MicroPython Code Block: > from module import ModuleQRCode > > module\_qrcode \= ModuleQRCode(id \= 1, tx \= 17, rx \= 18) set\_power(_enable_)[](#module.qrcode.QRCodeModule.set_power "Link to this definition") Set power. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – * `True` : power on. * `False` : power off. UiFlow2 Code Block: > ![set_power.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_power.png) MicroPython Code Block: > module\_qrcode.set\_power(enable) set\_trig(_value_)[](#module.qrcode.QRCodeModule.set_trig "Link to this definition") Set trigger pin value. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – * `0` : low level. * `1` : high level. UiFlow2 Code Block: > ![set_trig.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_trig.png) MicroPython Code Block: > module\_qrcode.set\_trig(value) start\_decode()[](#module.qrcode.QRCodeModule.start_decode "Link to this definition") Start decode. UiFlow2 Code Block: > ![start_decode.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/start_decode.png) MicroPython Code Block: > module\_qrcode.start\_decode() stop\_decode()[](#module.qrcode.QRCodeModule.stop_decode "Link to this definition") Stop decode. UiFlow2 Code Block: > ![stop_decode.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/stop_decode.png) MicroPython Code Block: > module\_qrcode.stop\_decode() read()[](#module.qrcode.QRCodeModule.read "Link to this definition") Read decode data. Returns: qrcode data. Return type: None | [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") If no data is received, return None. UiFlow2 Code Block: > ![read.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/read.png) MicroPython Code Block: > module\_qrcode.read() set\_trigger\_mode(_mode_)[](#module.qrcode.QRCodeModule.set_trigger_mode "Link to this definition") Set trigger mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The trigger mode. Available options: * `TRIGGER_MODE_KEY`: Key Mode, Triggers a single decode; decoding stops after a successful read. * `TRIGGER_MODE_CONTINUOUS`: Continuous Mode, Triggers continuous decoding; decoding continues even after a successful read and stops only when triggered again. * `TRIGGER_MODE_AUTO`: Auto Mode, Performs continuous decoding upon power-up and cannot be stopped. * `TRIGGER_MODE_PULSE`: Pulse Mode, The Trig pin’s low-level signal triggers decoding, which stops after a successful read or when the single read time limit is reached. * `TRIGGER_MODE_MOTION_SENSING`: Motion Sensing Mode, Uses image recognition; decoding starts when a scene change is detected. UiFlow2 Code Block: > ![set_trigger_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_trigger_mode.png) MicroPython Code Block: > module\_qrcode.set\_trigger\_mode(mode) set\_decode\_delay(_delay\_ms_)[](#module.qrcode.QRCodeModule.set_decode_delay "Link to this definition") Set decode delay. Parameters: **delay\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – decode delay time(ms), 0 means continuous decoding until success. UiFlow2 Code Block: > ![set_decode_delay.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_decode_delay.png) MicroPython Code Block: > module\_qrcode.set\_decode\_delay(delay\_ms) set\_trigger\_timeout(_timeout\_ms_)[](#module.qrcode.QRCodeModule.set_trigger_timeout "Link to this definition") Set trigger timeout. Parameters: **timeout\_ms** – trigger timeout time(ms), Decoding will automatically stop when the duration exceeds this value. UiFlow2 Code Block: > ![set_trigger_timeout.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_trigger_timeout.png) MicroPython Code Block: > module\_qrcode.set\_trigger\_timeout(timeout\_ms) set\_motion\_sensitivity(_level_)[](#module.qrcode.QRCodeModule.set_motion_sensitivity "Link to this definition") Set motion detection sensitivity. (in Motion Sensing Mode) Parameters: **level** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – sensitivity level. Range: 1~5. The higher the level, the more sensitive it is to scene changes. UiFlow2 Code Block: > ![set_motion_sensitivity.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_motion_sensitivity.png) MicroPython Code Block: > module\_qrcode.set\_motion\_sensitivity(level) set\_continuous\_decode\_delay(_delay\_100ms_)[](#module.qrcode.QRCodeModule.set_continuous_decode_delay "Link to this definition") Set continuous decode delay. (in Motion Sensing Mode) Parameters: **delay\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – delay time(unit: 100ms), 0 means continuous decoding until timeout. UiFlow2 Code Block: > ![set_continuous_decode_delay.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_continuous_decode_delay.png) MicroPython Code Block: > module\_qrcode.set\_continuous\_decode\_delay(delay\_ms) set\_trigger\_decode\_delay(delay\_ms): Set trigger decode delay. (in Motion Sensing Mode) Sets the trigger decoding delay time. This is the delay between re-entering the scene change detection phase and starting recognition again after detecting a change. Parameters: **delay\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Trigger decode delay time(unit: ms). UiFlow2 Code Block: > ![set_trigger_decode_delay.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_trigger_decode_delay.png) MicroPython Code Block: > module\_qrcode.set\_trigger\_decode\_delay(delay\_ms) set\_same\_code\_interval(_interval\_ms_)[](#module.qrcode.QRCodeModule.set_same_code_interval "Link to this definition") Set same code interval. Parameters: **interval\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The interval time for repeated recognition of the same code (unit: ms). UiFlow2 Code Block: > ![set_same_code_interval.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_same_code_interval.png) MicroPython Code Block: > module\_qrcode.set\_same\_code\_interval(interval\_ms) set\_diff\_code\_interval(_interval\_ms_)[](#module.qrcode.QRCodeModule.set_diff_code_interval "Link to this definition") Set difference code interval. Parameters: **interval\_ms** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The interval time for repeated recognition of the difference code (unit: ms). UiFlow2 Code Block: > ![set_diff_code_interval.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_diff_code_interval.png) MicroPython Code Block: > module\_qrcode.set\_diff\_code\_interval(interval\_ms) set\_same\_code\_no\_delay(_enable_)[](#module.qrcode.QRCodeModule.set_same_code_no_delay "Link to this definition") Set same code no delay. Parameters: **enable** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to enable non-delay output for the same code. True means enabled, False means disabled. UiFlow2 Code Block: > ![set_same_code_no_delay.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_same_code_no_delay.png) MicroPython Code Block: > module\_qrcode.set\_same\_code\_no\_delay(enable) set\_fill\_light\_mode(_mode_)[](#module.qrcode.QRCodeModule.set_fill_light_mode "Link to this definition") Set fill light mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The fill light mode. Available options: * `FILL_LIGHT_OFF`: Light off. * `FILL_LIGHT_ON`: Light on. * `FILL_LIGHT_ON_DECODE`: Light on during decoding. UiFlow2 Code Block: > ![set_fill_light_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_fill_light_mode.png) MicroPython Code Block: > module\_qrcode.set\_fill\_light\_mode(mode) set\_fill\_light\_brightness(_brightness_)[](#module.qrcode.QRCodeModule.set_fill_light_brightness "Link to this definition") Set fill light brightness. Parameters: **brightness** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The fill light brightness. Range: 0~100. UiFlow2 Code Block: > ![set_fill_light_brightness.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_fill_light_brightness.png) MicroPython Code Block: > module\_qrcode.set\_fill\_light\_brightness(brightness) set\_pos\_light\_mode(_mode_)[](#module.qrcode.QRCodeModule.set_pos_light_mode "Link to this definition") Set positioning light mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The positioning light mode. Available options: * `POS_LIGHT_OFF`: Light off. * `POS_LIGHT_ON_DECODE`: Light on during decoding. * `POS_LIGHT_FLASH_ON_DECODE`: Light flash during decoding. UiFlow2 Code Block: > ![set_pos_light_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_pos_light_mode.png) MicroPython Code Block: > module\_qrcode.set\_pos\_light\_mode(mode) set\_startup\_tone(_mode_)[](#module.qrcode.QRCodeModule.set_startup_tone "Link to this definition") Set startup tone. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – * `0`: Disable startup tone. * `1`: Play 4 beeps. * `2`: Play 2 beeps. UiFlow2 Code Block: > ![set_startup_tone.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_startup_tone.png) MicroPython Code Block: > module\_qrcode.set\_startup\_tone(mode) set\_decode\_success\_beep(_count_)[](#module.qrcode.QRCodeModule.set_decode_success_beep "Link to this definition") Set decode success beep. Parameters: **count** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – * `0`: No prompt sound. * `1`: Play prompt sound once. * `2`: Play prompt sound twice. UiFlow2 Code Block: > ![set_decode_success_beep.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_decode_success_beep.png) MicroPython Code Block: > module\_qrcode.set\_decode\_success\_beep(count) set\_case\_conversion(_mode_)[](#module.qrcode.QRCodeModule.set_case_conversion "Link to this definition") Set case conversion. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – * `0`: Off (Original data). * `1`: Convert to uppercase. * `2`: Convert to lowercase. UiFlow2 Code Block: > ![set_case_conversion.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_case_conversion.png) MicroPython Code Block: > module\_qrcode.set\_case\_conversion(mode) set\_protocol\_format(mode): set\_protocol\_format(_mode_)[](#module.qrcode.QRCodeModule.set_protocol_format "Link to this definition") Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – * `0`: No protocol * `1`: Format 1: \[0x03\] + Data Length (2 bytes) + Data * `2`: Format 2: \[0x03\] + Data Length + Number of Barcodes + Code 1 Data Length + Code 1 Data + … + CRC * `3`: Format 3: \[0x03\] + Data Length + Number of Barcodes + Code 1 ID + Code 1 Data Length + Code 1 Data + … + CRC CRC generate reference program. > def crc16\_calc(data: bytes) \-> int: > ca\_crc \= 0 > for byte in data: > for i in range(7, \-1, \-1): > if ca\_crc & 0x8000: > ca\_crc \= (ca\_crc << 1) ^ 0x18005 > else: > ca\_crc <<= 1 > if (byte & (1 << i)) != 0: > ca\_crc ^= 0x18005 > return ca\_crc & 0xFFFF UiFlow2 Code Block: > ![set_protocol_format.png](https://static-cdn.m5stack.com/mpy_docs/module/qrcode/set_protocol_format.png) MicroPython Code Block: > module\_qrcode.set\_protocol\_format(mode) --- # RS232F/M Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * RS232F/M Module * [View page source](../_sources/module/rs232.rst.txt) * * * RS232F/M Module[](#rs232f-m-module "Link to this heading") ============================================================ Supported Products: > | | | > | --- | --- | > | [![RS232F Module](https://static-cdn.m5stack.com/resource/docs/products/module/RS232F%20Module%2013.2/img-eeb9c1c5-e971-4384-8bfd-d0c8992c7c35.webp)](https://docs.m5stack.com/en/module/RS232F%20Module%2013.2) | [![RS232M Module](https://static-cdn.m5stack.com/resource/docs/products/module/RS232M%20Module%2013.2/img-6071f525-97b7-4acc-a283-d66a7a5b53cd.webp)](https://docs.m5stack.com/en/module/RS232M%20Module%2013.2) | Micropython TX 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 module import RS232Module > 9import time > 10 > 11 > 12rs232\_0 \= None > 13 > 14 > 15def setup(): > 16 global rs232\_0 > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 > 21 rs232\_0 \= RS232Module( > 22 1, > 23 baudrate\=115200, > 24 bits\=8, > 25 parity\=None, > 26 stop\=1, > 27 tx\=(0), > 28 rx\=(35), > 29 txbuf\=256, > 30 rxbuf\=256, > 31 timeout\=0, > 32 timeout\_char\=0, > 33 invert\=0, > 34 flow\=0, > 35 ) > 36 > 37 > 38def loop(): > 39 global rs232\_0 > 40 M5.update() > 41 rs232\_0.write("hello M5" + "\\r\\n") > 42 time.sleep(1) > 43 > 44 > 45if \_\_name\_\_ \== "\_\_main\_\_": > 46 try: > 47 setup() > 48 while True: > 49 loop() > 50 except (Exception, KeyboardInterrupt) as e: > 51 try: > 52 from utility import print\_error\_msg > 53 > 54 print\_error\_msg(e) > 55 except ImportError: > 56 print("please update to latest firmware") Micropython RX 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 module import RS232Module > 9import time > 10 > 11 > 12rs232\_0 \= None > 13 > 14 > 15def setup(): > 16 global rs232\_0 > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 > 21 rs232\_0 \= RS232Module( > 22 1, > 23 baudrate\=115200, > 24 bits\=8, > 25 parity\=None, > 26 stop\=1, > 27 tx\=(0), > 28 rx\=(10), > 29 txbuf\=256, > 30 rxbuf\=256, > 31 timeout\=0, > 32 timeout\_char\=0, > 33 invert\=0, > 34 flow\=0, > 35 ) > 36 > 37 > 38def loop(): > 39 global rs232\_0 > 40 M5.update() > 41 if rs232\_0.any(): > 42 print(rs232\_0.readline()) > 43 time.sleep(1) > 44 > 45 > 46if \_\_name\_\_ \== "\_\_main\_\_": > 47 try: > 48 setup() > 49 while True: > 50 loop() > 51 except (Exception, KeyboardInterrupt) as e: > 52 try: > 53 from utility import print\_error\_msg > 54 > 55 print\_error\_msg(e) > 56 except ImportError: > 57 print("please update to latest firmware") UIFLOW2 TX Example: > ![tx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/tx_example.png) UIFLOW2 RX Example: > ![rx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/rx_example.png) [core\_rs232\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/rs232/core_rs232_tx_example.m5f2) [cores3\_rs232\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/rs232/cores3_rs232_rx_example.m5f2) class RS232Module[](#class-rs232module "Link to this heading") ---------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ RS232Module(_id_, _baudrate=9600_, _bits=8_, _parity=None_, _stop=1_, _\*_, _..._)[](#RS232Module "Link to this definition") Construct a UART object of the given id. For more parameters, please refer to init. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- RS232Module.init(_baudrate=9600_, _bits=8_, _parity=None_, _stop=1_, _\*_, _..._)[](#RS232Module.init "Link to this definition") Initialise the UART bus with the given parameters: > * _baudrate_ is the clock rate. > > * _bits_ is the number of bits per character, 7, 8 or 9. > > * _parity_ is the parity, `None`, 0 (even) or 1 (odd). > > * _stop_ is the number of stop bits, 1 or 2. > Additional keyword-only parameters that may be supported by a port are: > * _tx_ specifies the TX pin to use. > > * _rx_ specifies the RX pin to use. > > * _rts_ specifies the RTS (output) pin to use for hardware receive flow control. > > * _cts_ specifies the CTS (input) pin to use for hardware transmit flow control. > > * _txbuf_ specifies the length in characters of the TX buffer. > > * _rxbuf_ specifies the length in characters of the RX buffer. > > * _timeout_ specifies the time to wait for the first character (in ms). > > * _timeout\_char_ specifies the time to wait between characters (in ms). > > * _invert_ specifies which lines to invert. > > > * `0` will not invert lines (idle state of both lines is logic high). > > > > * `RS232Module.INV_TX` will invert TX line (idle state of TX line now logic low). > > > > * `RS232Module.INV_RX` will invert RX line (idle state of RX line now logic low). > > > > * `RS232Module.INV_TX | RS232Module.INV_RX` will invert both lines (idle state at logic low). > > > > * _flow_ specifies which hardware flow control signals to use. The value is a bitmask. > > > * `0` will ignore hardware flow control signals. > > > > * `RS232Module.RTS` will enable receive flow control by using the RTS output pin to signal if the receive FIFO has sufficient space to accept more data. > > > > * `RS232Module.CTS` will enable transmit flow control by pausing transmission when the CTS input pin signals that the receiver is running low on buffer space. > > > > * `RS232Module.RTS | RS232Module.CTS` will enable both, for full hardware flow control. > > > Note It is possible to call `init()` multiple times on the same object in order to reconfigure UART on the fly. That allows using single UART peripheral to serve different devices attached to different GPIO pins. Only one device can be served at a time in that case. Also do not call `deinit()` as it will prevent calling `init()` again. UIFLOW2: > ![setup.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/setup.png) RS232Module.deinit()[](#RS232Module.deinit "Link to this definition") Turn off the UART bus. Note You will not be able to call `init()` on the object after `deinit()`. A new instance needs to be created in that case. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/deinit.png) RS232Module.any()[](#RS232Module.any "Link to this definition") Returns an integer counting the number of characters that can be read without blocking. It will return 0 if there are no characters available and a positive number if there are characters. The method may return 1 even if there is more than one character available for reading. For more sophisticated querying of available characters use select.poll: poll \= select.poll() poll.register(uart, select.POLLIN) poll.poll(timeout) UIFLOW2: > ![any.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/any.png) RS232Module.read(\[_nbytes_\])[](#RS232Module.read "Link to this definition") Read characters. If `nbytes` is specified then read at most that many bytes, otherwise read as much data as possible. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: a bytes object containing the bytes read in. Returns `None` on timeout. UIFLOW2: > ![read_all.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/read_all.png) > > ![read_bytes.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/read_bytes.png) > > ![read_raw_data.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/read_raw_data.png) RS232Module.readinto(_buf_\[, _nbytes_\])[](#RS232Module.readinto "Link to this definition") Read bytes into the `buf`. If `nbytes` is specified then read at most that many bytes. Otherwise, read at most `len(buf)` bytes. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: number of bytes read and stored into `buf` or `None` on timeout. UIFLOW2: > ![readinto.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/readinto.png) RS232Module.readline()[](#RS232Module.readline "Link to this definition") Read a line, ending in a newline character. It may return sooner if a timeout is reached. The timeout is configurable in the constructor. Return value: the line read or `None` on timeout. UIFLOW2: > ![readline.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/read_line.png) RS232Module.write(_buf_)[](#RS232Module.write "Link to this definition") Write the buffer of bytes to the bus. Return value: number of bytes written or `None` on timeout. UIFLOW2: > ![write.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write.png) > > ![write1.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write1.png) > > ![write_line.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write_line.png) > > ![write_list.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write_list.png) > > ![write_raw_data.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write_raw_data.png) > > ![write_raw_data_list.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/write_raw_data_list.png) RS232Module.sendbreak()[](#RS232Module.sendbreak "Link to this definition") Send a break condition on the bus. This drives the bus low for a duration longer than required for a normal transmission of a character. UIFLOW2: > ![sendbreak.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/sendbreak.png) RS232Module.flush()[](#RS232Module.flush "Link to this definition") Waits until all data has been sent. In case of a timeout, an exception is raised. The timeout duration depends on the tx buffer size and the baud rate. Unless flow control is enabled, a timeout should not occur. Note For the rp2, esp8266 and nrf ports the call returns while the last byte is sent. If required, a one character wait time has to be added in the calling script. UIFLOW2: > ![flush.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/flush.png) RS232Module.txdone()[](#RS232Module.txdone "Link to this definition") Tells whether all data has been sent or no data transfer is happening. In this case, it returns `True`. If a data transmission is ongoing it returns `False`. Note For the rp2, esp8266 and nrf ports the call may return `True` even if the last byte of a transfer is still being sent. If required, a one character wait time has to be added in the calling script. UIFLOW2: > ![txdone.png](https://static-cdn.m5stack.com/mpy_docs/module/rs232/txdone.png) --- # USB Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * USB Module * [View page source](../_sources/module/usb.rst.txt) * * * USB Module[](#usb-module "Link to this heading") ================================================== The USB Module is a module that uses the SPI interface to expand USB functionality, implemented with the MAX3421E. Support the following products: [![USB Module](https://static-cdn.m5stack.com/resource/docs/products/module/USB%20v1.2%20Module/img-2b9ca068-4799-46ee-a4f1-e7abc5314e7a.webp)](https://docs.m5stack.com/zh_CN/module/USB%20v1.2%20Module) Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- Note Before using the following examples, please check the DIP switches on the module to ensure that the pins used in the example match the DIP switch positions. For specific configurations, please refer to the product manual page. The SPI configuration has been implemented internally, so users do not need to worry about it. ### Input/Output Pin Control[](#input-output-pin-control "Link to this heading") The module exposes 5 IN (input) pins and 5 OUT (output) pins through headers. This example demonstrates controlling the high and low level switching of the output pins, as well as reading and printing the level status of the input pins. > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from module import USBModule > 8import time > 9 > 10 > 11module\_usb\_0 \= None > 12last\_time \= None > 13i \= None > 14last\_set\_time \= None > 15value \= None > 16state \= None > 17toggle \= None > 18 > 19 > 20def setup(): > 21 global module\_usb\_0, last\_time, last\_set\_time, value, state, toggle, i > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 module\_usb\_0 \= USBModule(pin\_cs\=1, pin\_int\=10) > 25 module\_usb\_0.write\_gpout(0, 0) > 26 module\_usb\_0.write\_gpout(1, 1) > 27 module\_usb\_0.write\_gpout(2, 0) > 28 module\_usb\_0.write\_gpout(3, 1) > 29 module\_usb\_0.write\_gpout(4, 0) > 30 state \= \[0\] \* 5 > 31 toggle \= True > 32 > 33 > 34def loop(): > 35 global module\_usb\_0, last\_time, last\_set\_time, value, state, toggle, i > 36 M5.update() > 37 module\_usb\_0.poll\_data() > 38 if (time.ticks\_diff((time.ticks\_ms()), last\_time)) \> 200: > 39 last\_time \= time.ticks\_ms() > 40 for i in range(5): > 41 value \= module\_usb\_0.read\_gpin(i) > 42 state\[int((i + 1) \- 1)\] \= value > 43 print(state) > 44 if (time.ticks\_diff((time.ticks\_ms()), last\_set\_time)) \> 1000: > 45 last\_set\_time \= time.ticks\_ms() > 46 if toggle: > 47 for i in range(5): > 48 module\_usb\_0.write\_gpout(i, 1) > 49 else: > 50 for i in range(5): > 51 module\_usb\_0.write\_gpout(i, 0) > 52 toggle \= not toggle > 53 > 54 > 55if \_\_name\_\_ \== "\_\_main\_\_": > 56 try: > 57 setup() > 58 while True: > 59 loop() > 60 except (Exception, KeyboardInterrupt) as e: > 61 try: > 62 from utility import print\_error\_msg > 63 > 64 print\_error\_msg(e) > 65 except ImportError: > 66 print("please update to latest firmware") ### Mouse[](#mouse "Link to this heading") Implementing USB host to capture mouse input > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from module import USBModule > 8 > 9 > 10title0 \= None > 11label\_x \= None > 12label\_y \= None > 13module\_usb\_0 \= None > 14x \= None > 15y \= None > 16mouse\_move \= None > 17dx \= None > 18dy \= None > 19 > 20 > 21def setup(): > 22 global title0, label\_x, label\_y, module\_usb\_0, x, y, mouse\_move, dx, dy > 23 M5.begin() > 24 Widgets.fillScreen(0x222222) > 25 title0 \= Widgets.Title( > 26 "Module USB Example mouse", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 27 ) > 28 label\_x \= Widgets.Label("x", 130, 90, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label\_y \= Widgets.Label("y", 180, 90, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 module\_usb\_0 \= USBModule(pin\_cs\=1, pin\_int\=10) > 31 x \= 0 > 32 y \= 0 > 33 > 34 > 35def loop(): > 36 global title0, label\_x, label\_y, module\_usb\_0, x, y, mouse\_move, dx, dy > 37 module\_usb\_0.poll\_data() > 38 if module\_usb\_0.is\_left\_btn\_pressed(): > 39 print("click left") > 40 if module\_usb\_0.is\_right\_btn\_pressed(): > 41 print("click right") > 42 if module\_usb\_0.is\_middle\_btn\_pressed(): > 43 print("click middle") > 44 mouse\_move \= module\_usb\_0.read\_mouse\_move() > 45 dx \= mouse\_move\[0\] > 46 dy \= mouse\_move\[1\] > 47 if dx != 0 or dy != 0: > 48 print((str("move: ") + str((str(dx) + str((str(", ") + str(dy))))))) > 49 x \= min(max(x + dx, 0), 320) > 50 y \= min(max(y + dy, 0), 240) > 51 label\_x.setText(str(x)) > 52 label\_y.setText(str(y)) > 53 > 54 > 55if \_\_name\_\_ \== "\_\_main\_\_": > 56 try: > 57 setup() > 58 while True: > 59 loop() > 60 except (Exception, KeyboardInterrupt) as e: > 61 try: > 62 from utility import print\_error\_msg > 63 > 64 print\_error\_msg(e) > 65 except ImportError: > 66 print("please update to latest firmware") ### Keyboard[](#keyboard "Link to this heading") Implementing USB host to capture keyboard input > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4import os, sys, io > 5import M5 > 6from M5 import \* > 7from module import USBModule > 8 > 9 > 10module\_usb\_0 \= None > 11modifier \= None > 12indata \= None > 13 > 14 > 15def setup(): > 16 global module\_usb\_0, modifier, indata > 17 M5.begin() > 18 Widgets.fillScreen(0x222222) > 19 module\_usb\_0 \= USBModule(pin\_cs\=1, pin\_int\=10) > 20 > 21 > 22def loop(): > 23 global module\_usb\_0, modifier, indata > 24 M5.update() > 25 module\_usb\_0.poll\_data() > 26 modifier \= module\_usb\_0.read\_kb\_modifier() > 27 if modifier & 0x01: > 28 print("Left Control pressed") > 29 if modifier & 0x02: > 30 print("Left Shift pressed") > 31 if modifier & 0x04: > 32 print("Left Alt pressed") > 33 if modifier & 0x08: > 34 print("Left GUI pressed") > 35 if modifier & 0x10: > 36 print("Right Control pressed") > 37 if modifier & 0x20: > 38 print("Right Shift pressed") > 39 if modifier & 0x40: > 40 print("Right Alt pressed") > 41 if modifier & 0x80: > 42 print("Right GUI pressed") > 43 indata \= module\_usb\_0.read\_kb\_input(True) > 44 if indata: > 45 print(indata) > 46 > 47 > 48if \_\_name\_\_ \== "\_\_main\_\_": > 49 try: > 50 setup() > 51 while True: > 52 loop() > 53 except (Exception, KeyboardInterrupt) as e: > 54 try: > 55 from utility import print\_error\_msg > 56 > 57 print\_error\_msg(e) > 58 except ImportError: > 59 print("please update to latest firmware") UIFlow2.0 Example[](#uiflow2-0-example "Link to this heading") ---------------------------------------------------------------- ### Input/Output Pin Control[](#id1 "Link to this heading") > ![gpio_example.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/gpio_example.png) [cores3\_module\_usb\_gpio\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/usb/cores3_module_usb_gpio_example.m5f2) ### Mouse[](#id2 "Link to this heading") > ![mouse_example.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/mouse_example.png) [cores3\_module\_usb\_mouse\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/usb/cores3_module_usb_mouse_example.m5f2) ### Keyboard[](#id3 "Link to this heading") > ![kb_example.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/kb_example.png) [cores3\_module\_usb\_kb\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/usb/cores3_module_usb_kb_example.m5f2) class USBModule[](#class-usbmodule "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ USBModule(_pin\_cs: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 1_, _pin\_int: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 10_)[](#USBModule "Link to this definition") Parameters: * **pin\_cs** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (RST) 复位引脚 * **pin\_irq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (INT) 中断引脚 UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/init.png) poll\_data()[](#poll_data "Link to this definition") poll data **Note**: It needs to be called in the main loop UIFlow2.0 > ![poll_data.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/poll_data.png) is\_left\_btn\_pressed() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#is_left_btn_pressed "Link to this definition") Check if the left mouse button is pressed. UIFlow2.0 > ![is_left_btn_pressed.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/is_left_btn_pressed.png) is\_right\_btn\_pressed() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#is_right_btn_pressed "Link to this definition") Check if the right mouse button is pressed. UIFlow2.0 > ![is_right_btn_pressed.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/is_right_btn_pressed.png) is\_middle\_btn\_pressed() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#is_middle_btn_pressed "Link to this definition") Check if the middle mouse button is pressed. UIFlow2.0 > ![is_middle_btn_pressed.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/is_middle_btn_pressed.png) is\_forward\_btn\_pressed() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#is_forward_btn_pressed "Link to this definition") Check if the forward mouse button is pressed. UIFlow2.0 > ![is_forward_btn_pressed.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/is_forward_btn_pressed.png) is\_back\_btn\_pressed() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#is_back_btn_pressed "Link to this definition") Check if the back mouse button is pressed. UIFlow2.0 > ![is_back_btn_pressed.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/is_back_btn_pressed.png) read\_mouse\_move() → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \][](#read_mouse_move "Link to this definition") Read Mouse Cursor Movement Returns a tuple (x, y) containing the horizontal displacement x and vertical displacement y of the mouse; x range: -127 to 127; 0 indicates no movement, negative values indicate movement to the left, and positive values indicate movement to the right; y range: -127 to 127; 0 indicates no movement, negative values indicate movement upward, and positive values indicate movement downward. **Example:** move \= usb\_module.read\_mouse\_move() x \= move\[0\] y \= move\[1\] UIFlow2.0 > ![read_mouse_move.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/read_mouse_move.png) read\_wheel\_move() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#read_wheel_move "Link to this definition") Read Mouse Wheel Movement Returns a value in the range of -127 to 127, 0 indicates no movement, Positive values indicate forward scrolling, Negative values indicate backward scrolling. UIFlow2.0 > ![read_wheel_move.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/read_wheel_move.png) read\_kb\_input(_convert: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_) → [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") [](#read_kb_input "Link to this definition") Read keyboard input * `convert` Whether to convert HID Keycode to the corresponding string. Returns a list containing keyboard inputs (up to 6 elements, meaning a maximum of 6 key values can be input at once). **Example:** res \= usb\_module.read\_kb\_input(convert\=True) \# output \['a', 'b', 'Enter'\] res \= usb\_module.read\_kb\_input(convert\=False) \# output \[0x04, 0x05, 0x28\] UIFlow2.0 > ![read_kb_input.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/read_kb_input.png) read\_kb\_modifier() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#read_kb_modifier "Link to this definition") Read the keyboard modifier keys, namely “Ctrl”, “Shift”, “Alt”, and “Win” keys. * `Return`: The status of the keyboard modifier keys, usually represented by a bit mask to indicate the status of different modifier keys. * 0x01: Left Control key * 0x02: Left Shift key * 0x04: Left Alt key * 0x08: Left Windows key (Left GUI) * 0x10: Right Control key * 0x20: Right Shift key * 0x40: Right Alt key * 0x80: Right Windows key (Right GUI) **Example:** modifier \= module\_usb.read\_kb\_modifier() if modifier & 0x01: print("left ctrl key pressed") UIFlow2.0 > ![read_kb_modifier.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/read_kb_modifier.png) read\_gpin(_pin_) → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#read_gpin "Link to this definition") Read input pin value * `pin` pin number * `Return` 1 represents high level, and 0 represents low level. UIFlow2.0 > ![read_gpin.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/read_gpin.png) write\_gpout(_pin_, _value_)[](#write_gpout "Link to this definition") Write output pin value * `pin` pin number * `Return` 1 represents high level, and 0 represents low level. UIFlow2.0 > ![write_gpout.png](https://static-cdn.m5stack.com/mpy_docs/module/usb/write_gpout.png) --- # Zigbee Module — UIFlow2 Programming Guide master documentation * [](../index.html) * [Module](index.html) * Zigbee Module * [View page source](../_sources/module/zigbee.rst.txt) * * * Zigbee Module[](#zigbee-module "Link to this heading") ======================================================== Zigbee is a self-organizing network communication module launched by M5Stack. The module adopts the CC2630F128 solution, integrates the Zigbee protocol stack internally, and provides an open serial communication interface. It features an external antenna, with a stable single-node communication distance of up to 1 km and supports up to 200 levels of router depth. Through MESH networking, it can significantly extend the range of your IoT applications, offering both ultra-low power consumption and high sensitivity. The Zigbee network can support hundreds of nodes and has enhanced security features, providing a complete and interoperable IoT solution for home and building automation. Support the following products: > [![ZigbeeModule](https://static-cdn.m5stack.com/resource/docs/products/module/comx_zigbee/comx_zigbee_01.webp)](https://docs.m5stack.com/en/module/comx_zigbee) Micropython TX 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 module import ZigbeeModule > 9import time > 10 > 11 > 12label0 \= None > 13com\_zigbee\_0 \= None > 14zigbee\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, com\_zigbee\_0, zigbee\_0 > 19 > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 label0 \= Widgets.Label("label0", 32, 35, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 23 > 24 com\_zigbee\_0 \= ZigbeeModule(2, 17, 18, verbose\=True) > 25 com\_zigbee\_0.set\_module\_param( > 26 ZigbeeModule.DEVICE\_TYPE\_COORDINATOR, > 27 0x1620, > 28 11, > 29 ZigbeeModule.TRANSFER\_MODE\_PASS\_THROUGH, > 30 0x6677, > 31 ) > 32 label0.setText(str("start")) > 33 > 34 > 35def loop(): > 36 global label0, com\_zigbee\_0, zigbee\_0 > 37 M5.update() > 38 com\_zigbee\_0.p2p\_transmission(0x0066, "p2p") > 39 time.sleep(3) > 40 com\_zigbee\_0.broadcast("broadcast") > 41 time.sleep(3) > 42 > 43 > 44if \_\_name\_\_ \== "\_\_main\_\_": > 45 try: > 46 setup() > 47 while True: > 48 loop() > 49 except (Exception, KeyboardInterrupt) as e: > 50 try: > 51 com\_zigbee\_0.stop\_receive() > 52 from utility import print\_error\_msg > 53 > 54 print\_error\_msg(e) > 55 except ImportError: > 56 print("please update to latest firmware") Micropython RX 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 module import ZigbeeModule > 9 > 10 > 11label0 \= None > 12com\_zigbee\_0 \= None > 13 > 14 > 15zigbee\_str\_data \= None > 16zigbee\_dest\_address \= None > 17zigbee\_src\_address \= None > 18 > 19 > 20def com\_zigbee\_0\_receive\_event(dest\_address, src\_address, received\_data): > 21 global label0, com\_zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 22 zigbee\_dest\_address \= dest\_address > 23 zigbee\_src\_address \= src\_address > 24 try: > 25 zigbee\_str\_data \= received\_data.decode() > 26 except: > 27 zigbee\_str\_data \= str(received\_data) > 28 label0.setText(str(zigbee\_str\_data)) > 29 > 30 > 31def setup(): > 32 global label0, com\_zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 33 > 34 M5.begin() > 35 Widgets.fillScreen(0x222222) > 36 label0 \= Widgets.Label("label0", 50, 34, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 37 > 38 com\_zigbee\_0 \= ZigbeeModule(2, 14, 13, verbose\=True) > 39 com\_zigbee\_0.set\_module\_param( > 40 ZigbeeModule.DEVICE\_TYPE\_ROUTER, > 41 0x1620, > 42 11, > 43 ZigbeeModule.TRANSFER\_MODE\_PASS\_THROUGH, > 44 0x0066, > 45 ) > 46 while not (com\_zigbee\_0.isconnected()): > 47 pass > 48 label0.setText(str(com\_zigbee\_0.get\_custom\_address())) > 49 com\_zigbee\_0.receive\_none\_block(com\_zigbee\_0\_receive\_event) > 50 > 51 > 52def loop(): > 53 global label0, com\_zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 54 M5.update() > 55 > 56 > 57if \_\_name\_\_ \== "\_\_main\_\_": > 58 try: > 59 setup() > 60 while True: > 61 loop() > 62 except (Exception, KeyboardInterrupt) as e: > 63 try: > 64 com\_zigbee\_0.stop\_receive() > 65 from utility import print\_error\_msg > 66 > 67 print\_error\_msg(e) > 68 except ImportError: > 69 print("please update to latest firmware") UIFLOW2 TX Example: > ![tx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/tx_example.png) UIFLOW2 RX Example: > ![rx_example.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/rx_example.png) [cores3\_zigbee\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/com_zigbee/cores3_zigbee_tx_example.m5f2) [stickc\_plus2\_zigbee\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/com_zigbee/stickc_plus2_zigbee_rx_example.m5f2) class ZigbeeModule[](#class-zigbeemodule "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ZigbeeModule(_id: Literal\[0, 1, 2\]_, _port: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _, _verbose: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_)[](#ZigbeeModule "Link to this definition") Create a Zigbee unit. Parameters: * **id** – The ID of the unit. * **port** – The port that the unit is connected to. * **verbose** – Print the log information. Default is True. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ZigbeeModule.set\_module\_param(_device\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _pan\_id: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _transfer\_mode: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _custom\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _ant\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _encryption\_enable\=ENCRYPTION\_ENABLE_, _encryption\_key\=b'\\x11\\x12\\x13\\x14'_, _node\_type\=DEVICE\_TYPE\_ROUTER_, _node\_ant\_type\=ANT\_TYPRE\_ON\_BOARD_, _node\_transfer\_mode\=TRANSFER\_MODE\_PASS\_THROUGH_, _node\_custom\_address\=0x0066_)[](#ZigbeeModule.set_module_param "Link to this definition") Parameters: * **device\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The device type of the Zigbee module. * **pan\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PAN ID of the Zigbee module. The PAN ID is a 16-bit value that is used to identify the network. * **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel of the Zigbee module. The channel range is from 11 to 26 * **transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee module. * **custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module. * **ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee module. * **encryption\_enable** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The encryption status of the Zigbee module. * **encryption\_key** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The encryption key of the Zigbee module. * **node\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The node type of the Zigbee module. * **node\_ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee node. * **node\_transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee node. * **node\_custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee node. Set the parameters of the Zigbee module. UIFLOW2: > ![set_module_param.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_module_param.png) > > ![set_module_param1.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_module_param1.png) > > ![set_module_param2.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_module_param2.png) ZigbeeModule.set\_device\_type(_device\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_device_type "Link to this definition") Parameters: **device\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The device type of the Zigbee module. Set the device type of the Zigbee module. UIFLOW2: > ![set_device_type.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_device_type.png) ZigbeeModule.set\_pan\_id(_pan\_id: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_pan_id "Link to this definition") Parameters: **pan\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PAN ID of the Zigbee module. Set the PAN ID of the Zigbee module. UIFLOW2: > ![set_pan_id.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_pan_id.png) ZigbeeModule.set\_channel(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_channel "Link to this definition") Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel of the Zigbee module. Set the channel of the Zigbee module. UIFLOW2: > ![set_channel.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_channel.png) ZigbeeModule.set\_transfer\_mode(_transfer\_mode: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_transfer_mode "Link to this definition") Parameters: **transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee module. Set the transfer mode of the Zigbee module. UIFLOW2: > ![set_transfer_mode.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_transfer_mode.png) ZigbeeModule.get\_custom\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ZigbeeModule.get_custom_address "Link to this definition") Get the custom address of the Zigbee module. Returns: The custom address of the Zigbee module. UIFLOW2: > ![get_custom_address.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/get_custom_address.png) ZigbeeModule.set\_custom\_address(_custom\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_custom_address "Link to this definition") Parameters: **custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module. Set the custom address of the Zigbee module. UIFLOW2: > ![set_custom_address.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_custom_address.png) ZigbeeModule.set\_ant\_type(_ant\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeModule.set_ant_type "Link to this definition") Parameters: **ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee module. Set the antenna type of the Zigbee module. UIFLOW2: > ![set_ant_type.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/set_ant_type.png) ZigbeeModule.get\_short\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ZigbeeModule.get_short_address "Link to this definition") Get the short address of the Zigbee module. Returns: The short address of the Zigbee module. UIFLOW2: > ![get_short_address.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/get_short_address.png) ZigbeeModule.isconnected() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#ZigbeeModule.isconnected "Link to this definition") Check whether the Zigbee module is connected to the Zigbee network. Returns: True if the Zigbee module is connected to the Zigbee network, False otherwise. UIFLOW2: > ![isconnected.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/isconnected.png) ZigbeeModule.receive\_none\_block(_receive\_callback_)[](#ZigbeeModule.receive_none_block "Link to this definition") Parameters: **receive\_callback** – The callback function that is called when the Zigbee module receives data. Receive data from the Zigbee module. UIFLOW2: > ![receive_none_block.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/receive_none_block.png) > > ![receive_data_str_event.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/receive_data_str_event.png) > > ![receive_data_event.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/receive_data_event.png) ZigbeeModule.stop\_receive()[](#ZigbeeModule.stop_receive "Link to this definition") Stop receiving data from the Zigbee module. UIFLOW2: > ![stop_receive.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/stop_receive.png) ZigbeeModule.p2p\_transmission(_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _data: [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") _)[](#ZigbeeModule.p2p_transmission "Link to this definition") Parameters: * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module that the data is sent to. * **data** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The data that is sent to the Zigbee module. Send data to the Zigbee module. UIFLOW2: > ![p2p_transmission.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/p2p_transmission.png) ZigbeeModule.broadcast(_data: [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") _)[](#ZigbeeModule.broadcast "Link to this definition") Parameters: **data** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The data that is sent to the Zigbee module. Broadcast data to all Zigbee modules. UIFLOW2: > ![broadcast.png](https://static-cdn.m5stack.com/mpy_docs/module/com_zigbee/broadcast.png) --- # Unknown Module ====== .. toctree:: :maxdepth: 1 4in8out.rst ain4.rst bala2.rst commu.rst display.rst dmx.rst dualkmeter.rst ecg.rst encoder4\_motor.rst fan.rst gateway\_h2.rst gnss.rst gps.rst gpsv2.rst grbl.rst goplus2.rst hmi.rst llm.rst lora.rst lora\_sx1262.rst lorawan868.rst lte.rst nbiot.rst odrive.rst plus.rst pm25.rst pps.rst pwrcan.rst qrcode.rst rca.rst relay\_2.rst rs232.rst servo2.rst step\_motor\_driver.rst usb.rst zigbee.rst --- # Zigbee Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * Zigbee Unit * [View page source](../_sources/units/zigbee.rst.txt) * * * Zigbee Unit[](#zigbee-unit "Link to this heading") ==================================================== Zigbee is a self-organizing network communication module launched by M5Stack. The module adopts the CC2630F128 solution, integrates the Zigbee protocol stack internally, and provides an open serial communication interface. It features an external antenna, with a stable single-node communication distance of up to 1 km and supports up to 200 levels of router depth. Through MESH networking, it can significantly extend the range of your IoT applications, offering both ultra-low power consumption and high sensitivity. The Zigbee network can support hundreds of nodes and has enhanced security features, providing a complete and interoperable IoT solution for home and building automation. Support the following products: > [![ZigbeeUnit](https://static-cdn.m5stack.com/resource/docs/products/unit/zigbee/zigbee_01.webp)](https://docs.m5stack.com/en/unit/zigbee) Micropython TX 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 unit import ZigbeeUnit > 9import time > 10 > 11 > 12label0 \= None > 13zigbee\_0 \= None > 14 > 15 > 16def setup(): > 17 global label0, zigbee\_0 > 18 > 19 M5.begin() > 20 Widgets.fillScreen(0x222222) > 21 label0 \= Widgets.Label("label0", 67, 43, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 22 > 23 zigbee\_0 \= ZigbeeUnit(1, port\=(18, 17), verbose\=True) > 24 zigbee\_0.set\_module\_param( > 25 ZigbeeUnit.DEVICE\_TYPE\_COORDINATOR, > 26 0x1620, > 27 11, > 28 ZigbeeUnit.TRANSFER\_MODE\_PASS\_THROUGH, > 29 0x6677, > 30 ) > 31 label0.setText(str("start")) > 32 > 33 > 34def loop(): > 35 global label0, zigbee\_0 > 36 M5.update() > 37 zigbee\_0.p2p\_transmission(0x0066, "p2p") > 38 time.sleep(3) > 39 zigbee\_0.broadcast("broadcast") > 40 time.sleep(3) > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Micropython RX 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 unit import ZigbeeUnit > 9 > 10 > 11label0 \= None > 12zigbee\_0 \= None > 13 > 14 > 15zigbee\_str\_data \= None > 16zigbee\_dest\_address \= None > 17zigbee\_src\_address \= None > 18 > 19 > 20def zigbee\_0\_receive\_event(dest\_address, src\_address, received\_data): > 21 global label0, zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 22 zigbee\_dest\_address \= dest\_address > 23 zigbee\_src\_address \= src\_address > 24 try: > 25 zigbee\_str\_data \= received\_data.decode() > 26 except: > 27 zigbee\_str\_data \= str(received\_data) > 28 label0.setText(str(zigbee\_str\_data)) > 29 > 30 > 31def setup(): > 32 global label0, zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 33 > 34 M5.begin() > 35 label0 \= Widgets.Label("label0", 21, 83, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 36 > 37 zigbee\_0 \= ZigbeeUnit(1, port\=(33, 32), verbose\=True) > 38 zigbee\_0.set\_module\_param( > 39 ZigbeeUnit.DEVICE\_TYPE\_ROUTER, 0x1620, 11, ZigbeeUnit.TRANSFER\_MODE\_PASS\_THROUGH, 0x0066 > 40 ) > 41 while not (zigbee\_0.isconnected()): > 42 pass > 43 label0.setText(str(zigbee\_0.get\_custom\_address())) > 44 zigbee\_0.receive\_none\_block(zigbee\_0\_receive\_event) > 45 > 46 > 47def loop(): > 48 global label0, zigbee\_0, zigbee\_str\_data, zigbee\_dest\_address, zigbee\_src\_address > 49 M5.update() > 50 > 51 > 52if \_\_name\_\_ \== "\_\_main\_\_": > 53 try: > 54 setup() > 55 while True: > 56 loop() > 57 except (Exception, KeyboardInterrupt) as e: > 58 try: > 59 from utility import print\_error\_msg > 60 > 61 print\_error\_msg(e) > 62 except ImportError: > 63 print("please update to latest firmware") UIFLOW2 TX Example: > ![tx_example.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/tx_example.png) UIFLOW2 RX Example: > ![rx_example.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/rx_example.png) [cores3\_zigbee\_tx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/zigbee/cores3_zigbee_tx_example.m5f2) [stickc\_plus2\_zigbee\_rx\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/zigbee/stickc_plus2_zigbee_rx_example.m5f2) class ZigbeeUnit[](#class-zigbeeunit "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ZigbeeUnit(_id: Literal\[0, 1, 2\]_, _port: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _, _verbose: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= True_)[](#ZigbeeUnit "Link to this definition") Create a Zigbee unit. Parameters: * **id** – The ID of the unit. * **port** – The port that the unit is connected to. * **verbose** – Print the log information. Default is True. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ZigbeeUnit.set\_module\_param(_device\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _pan\_id: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _transfer\_mode: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _custom\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _ant\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _encryption\_enable\=ENCRYPTION\_ENABLE_, _encryption\_key\=b'\\x11\\x12\\x13\\x14'_, _node\_type\=DEVICE\_TYPE\_ROUTER_, _node\_ant\_type\=ANT\_TYPRE\_ON\_BOARD_, _node\_transfer\_mode\=TRANSFER\_MODE\_PASS\_THROUGH_, _node\_custom\_address\=0x0066_)[](#ZigbeeUnit.set_module_param "Link to this definition") Parameters: * **device\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The device type of the Zigbee module. * **pan\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PAN ID of the Zigbee module. The PAN ID is a 16-bit value that is used to identify the network. * **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel of the Zigbee module. The channel range is from 11 to 26 * **transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee module. * **custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module. * **ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee module. * **encryption\_enable** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The encryption status of the Zigbee module. * **encryption\_key** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The encryption key of the Zigbee module. * **node\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The node type of the Zigbee module. * **node\_ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee node. * **node\_transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee node. * **node\_custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee node. Set the parameters of the Zigbee module. UIFLOW2: > ![set_module_param.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_module_param.png) > > ![set_module_param1.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_module_param1.png) > > ![set_module_param2.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_module_param2.png) ZigbeeUnit.set\_device\_type(_device\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_device_type "Link to this definition") Parameters: **device\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The device type of the Zigbee module. Set the device type of the Zigbee module. UIFLOW2: > ![set_device_type.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_device_type.png) ZigbeeUnit.set\_pan\_id(_pan\_id: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_pan_id "Link to this definition") Parameters: **pan\_id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PAN ID of the Zigbee module. Set the PAN ID of the Zigbee module. UIFLOW2: > ![set_pan_id.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_pan_id.png) ZigbeeUnit.set\_channel(_channel: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_channel "Link to this definition") Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel of the Zigbee module. Set the channel of the Zigbee module. UIFLOW2: > ![set_channel.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_channel.png) ZigbeeUnit.set\_transfer\_mode(_transfer\_mode: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_transfer_mode "Link to this definition") Parameters: **transfer\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The transfer mode of the Zigbee module. Set the transfer mode of the Zigbee module. UIFLOW2: > ![set_transfer_mode.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_transfer_mode.png) ZigbeeUnit.get\_custom\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ZigbeeUnit.get_custom_address "Link to this definition") Get the custom address of the Zigbee module. Returns: The custom address of the Zigbee module. UIFLOW2: > ![get_custom_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/get_custom_address.png) ZigbeeUnit.set\_custom\_address(_custom\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_custom_address "Link to this definition") Parameters: **custom\_address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module. Set the custom address of the Zigbee module. UIFLOW2: > ![set_custom_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_custom_address.png) ZigbeeUnit.set\_ant\_type(_ant\_type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#ZigbeeUnit.set_ant_type "Link to this definition") Parameters: **ant\_type** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The antenna type of the Zigbee module. Set the antenna type of the Zigbee module. UIFLOW2: > ![set_ant_type.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/set_ant_type.png) ZigbeeUnit.get\_short\_address() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ZigbeeUnit.get_short_address "Link to this definition") Get the short address of the Zigbee module. Returns: The short address of the Zigbee module. UIFLOW2: > ![get_short_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/get_short_address.png) ZigbeeUnit.isconnected() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#ZigbeeUnit.isconnected "Link to this definition") Check whether the Zigbee module is connected to the Zigbee network. Returns: True if the Zigbee module is connected to the Zigbee network, False otherwise. UIFLOW2: > ![isconnected.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/isconnected.png) ZigbeeUnit.receive\_none\_block(_receive\_callback_)[](#ZigbeeUnit.receive_none_block "Link to this definition") Parameters: **receive\_callback** – The callback function that is called when the Zigbee module receives data. Receive data from the Zigbee module. UIFLOW2: > ![receive_none_block.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/receive_none_block.png) > > ![receive_data_str_event.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/receive_data_str_event.png) > > ![receive_data_event.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/receive_data_event.png) ZigbeeUnit.stop\_receive()[](#ZigbeeUnit.stop_receive "Link to this definition") Stop receiving data from the Zigbee module. UIFLOW2: > ![stop_receive.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/stop_receive.png) ZigbeeUnit.p2p\_transmission(_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _data: [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") _)[](#ZigbeeUnit.p2p_transmission "Link to this definition") Parameters: * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The custom address of the Zigbee module that the data is sent to. * **data** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The data that is sent to the Zigbee module. Send data to the Zigbee module. UIFLOW2: > ![p2p_transmission.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/p2p_transmission.png) ZigbeeUnit.broadcast(_data: [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") _)[](#ZigbeeUnit.broadcast "Link to this definition") Parameters: **data** ([_bytes_](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.13)") ) – The data that is sent to the Zigbee module. Broadcast data to all Zigbee modules. UIFLOW2: > ![broadcast.png](https://static-cdn.m5stack.com/mpy_docs/unit/zigbee/broadcast.png) --- # class Label – display text — UIFlow2 Programming Guide master documentation * [](../index.html) * [`Widgets` — A basic UI library](index.html) * class Label – display text * [View page source](../_sources/widgets/label.rst.txt) * * * class Label – display text[](#class-label-display-text "Link to this heading") ================================================================================ Label is the basic object type used to display text. 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 \* > 8 > 9 > 10label0 \= None > 11 > 12 > 13def setup(): > 14 global label0 > 15 > 16 M5.begin() > 17 Widgets.fillScreen(0x222222) > 18 label0 \= Widgets.Label("Text", 38, 47, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 19 > 20 label0.setText(str("Label")) > 21 label0.setFont(Widgets.FONTS.DejaVu12) > 22 > 23 > 24def loop(): > 25 global label0 > 26 M5.update() > 27 > 28 > 29if \_\_name\_\_ \== "\_\_main\_\_": > 30 try: > 31 setup() > 32 while True: > 33 loop() > 34 except (Exception, KeyboardInterrupt) as e: > 35 try: > 36 from utility import print\_error\_msg > 37 > 38 print\_error\_msg(e) > 39 except ImportError: > 40 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/example.png) [cores3\_label\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/widgets/label/cores3_label_example.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Widgets.Label(_text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _text\_sz: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") _, _text\_c: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0xFFFFFF_, _bg\_c: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x000000_, _font\=None_, _parent\=None_)[](#Widgets.Widgets.Label "Link to this definition") Create a Label object. It accepts the following parameters: > * `text` is the text to be displayed. > > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > > * `text_sz` is the font size for displaying text, usually 1.0. > > * `text_c` is the font color for displaying text. The default is white. > > * bg\_c is the background color of the displayed text, the default is black. > > * `font` is the set of fonts used to display text. For the built-in fonts, see `Widgets.FONTS`. > > * parent is the output target of the Label object, the default output is to the LCD, can also be output to the Canvas. > Methods[](#methods "Link to this heading") -------------------------------------------- Label.setColor(_text\_c: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _bg\_c: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_)[](#Widgets.Label.setColor "Link to this definition") Sets the text font color of the Label object. Accept the following parameters: > * `text_c` is the font color for displaying text. > > * bg\_c is the background color of the displayed text, the default is black. > UIFLOW2: > ![setColor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setColor.png) Label.setCursor(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _)[](#Widgets.Label.setCursor "Link to this definition") Sets the starting coordinates of the Label object. Accept the following parameters: > * `x` is the starting X-axis coordinate displayed. > > * `y` is the starting Y-axis coordinate displayed. > UIFLOW2: > ![setCursor.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setCursor.png) Label.setFont(_font_)[](#Widgets.Label.setFont "Link to this definition") Sets the font set of the Label object. font is the set of fonts used to display text, the built-in font, see `Widgets.FONTS`. UIFLOW2: > ![setFont.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setFont.png) Label.setSize(_text\_sz: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") _)[](#Widgets.Label.setSize "Link to this definition") Set the text font size of the Label object, text\_sz is the font size of the displayed text. UIFLOW2: > ![setSize.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setSize.png) Label.setText(_text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _)[](#Widgets.Label.setText "Link to this definition") Sets the text content of the Label object. UIFLOW2: > ![setText.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setText.png) Label.setVisible(_visible: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _)[](#Widgets.Label.setVisible "Link to this definition") Set the visible property of the Label object, when `visible` is True, the Label object content will be visible, otherwise it will not be visible. UIFLOW2: > ![setVisible.png](https://static-cdn.m5stack.com/mpy_docs/widgets/label/setVisible.png) --- # ALS — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * ALS * [View page source](../_sources/hardware/als.rst.txt) * * * ALS[](#als "Link to this heading") ==================================== ALS is used to read the built-in ambient light sensor inside the host device. The following are the details of the host’s support for ALS: | | ALS | | --- | --- | | CoreS3 | ✔ | | CoreS3 SE | | 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 \* > 8 > 9 > 10title0 \= None > 11label0 \= None > 12 > 13 > 14def setup(): > 15 global title0, label0 > 16 > 17 M5.begin() > 18 Widgets.fillScreen(0x222222) > 19 title0 \= Widgets.Title("CoreS3 Als", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 20 label0 \= Widgets.Label("Als:", 2, 104, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 21 > 22 > 23def loop(): > 24 global title0, label0 > 25 M5.update() > 26 label0.setText(str((str("Als:") + str((M5.Als.getLightSensorData()))))) > 27 > 28 > 29if \_\_name\_\_ \== "\_\_main\_\_": > 30 try: > 31 setup() > 32 while True: > 33 loop() > 34 except (Exception, KeyboardInterrupt) as e: > 35 try: > 36 from utility import print\_error\_msg > 37 > 38 print\_error\_msg(e) > 39 except ImportError: > 40 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/als/example.png) [als\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/als/als_cores3_example.m5f2) class ALS[](#class-als "Link to this heading") ------------------------------------------------ Important Methods of the ALS Class heavily rely on `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg) and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg). All calls to methods of ALS objects should be placed after `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg), and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg) should be called in the main loop. Methods[](#methods "Link to this heading") -------------------------------------------- ALS.getLightSensorData() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ALS.getLightSensorData "Link to this definition") Read the ambient light sensor value built into the host device. UIFLOW2: > ![getLightSensorData.png](https://static-cdn.m5stack.com/mpy_docs/hardware/als/getLightSensorData.png) --- # umqtt – a simple MQTT client — UIFlow2 Programming Guide master documentation * [](../index.html) * [Software](index.html) * `umqtt` – a simple MQTT client * [View page source](../_sources/software/umqtt.rst.txt) * * * [`umqtt`](#module-umqtt "umqtt: a simple MQTT client") – a simple MQTT client[](#module-umqtt "Link to this heading") ======================================================================================================================== umqtt is a simple MQTT client for MicroPython. (Note that it uses some MicroPython shortcuts and doesn’t work with CPython). Supported MQTT features[](#supported-mqtt-features "Link to this heading") ---------------------------------------------------------------------------- QoS 0 and 1 are supported for both publish and subscribe. QoS2 isn’t supported to keep code size small. Besides ClientID, only “clean session” parameter is supported for connect as of now. Design requirements[](#design-requirements "Link to this heading") -------------------------------------------------------------------- * Memory efficiency. * Avoid infamous design anti-patterns like “callback hell”. * Support for both publishing and subscription via a single client object (another alternative would be to have separate client classes for publishing and subscription). MQTT client with automatic reconnect[](#mqtt-client-with-automatic-reconnect "Link to this heading") ------------------------------------------------------------------------------------------------------ There’s a separate [umqtt.robust](https://github.com/micropython/micropython-lib/blob/master/micropython/umqtt.robust/README.rst) module which builds on [umqtt.simple](https://github.com/micropython/micropython-lib/blob/master/micropython/umqtt.simple/README.rst) and adds automatic reconnect support in case of network errors. Please see its [documentation](https://github.com/micropython/micropython-lib/blob/master/micropython/umqtt.robust/README.rst) for further details. MQTT client with SSL file[](#mqtt-client-with-ssl-file "Link to this heading") -------------------------------------------------------------------------------- There is a separate [umqtt.default](umqtt.default.html) module that builds on top of [umqtt.robust](https://github.com/micropython/micropython-lib/blob/master/micropython/umqtt.robust/README.rst) and supports SSL certificates passed in as files and callback delivery for each subscribed topic. Please see its [documentation](umqtt.default.html) for further details. API design[](#api-design "Link to this heading") -------------------------------------------------- Based on the requirements above, there are following API traits: * All data related to MQTT messages is encoded as bytes. This includes both message content AND topic names (even though MQTT spec states that topic name is UTF-8 encoded). The reason for this is simple: what is received over network socket is binary data (bytes) and it would require extra step to convert that to a string, spending memory on that. Note that this applies only to topic names (because they can be both sent and received). Other parameters specified by MQTT as UTF-8 encoded (e.g. ClientID) are accepted as strings. * Subscribed messages are delivered via a callback. This is to avoid using a queue for subscribed messages, as otherwise they may be received at any time (including when client expects other type of server response, so there’re 2 choices: either deliver them immediately via a callback or queue up until an “expected” response arrives). Note that lack of need for a queue is delusive: the runtime call stack forms an implicit queue in this case. And unlike explicit queue, it’s much harder to control. This design was chosen because in a common case of processing subscribed messages it’s the most efficient. However, if in subscription callback, new messages of QoS>0 are published, this may lead to deep, or infinite recursion (the latter means an application will terminate with `RuntimeException`). Usage Model: \# uiflow2 uses this class by default from umqtt import MQTTClient \# If you want to use the \`umqtt.default\` module, go this way. from umqtt.simple import MQTTClient \# If you want to use the \`umqtt.robust\` module, go this way. from umqtt.robust import MQTTClient Classes[](#classes "Link to this heading") -------------------------------------------- * [umqtt.default](umqtt.default.html) --- # M5-ESPNOW — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * M5-ESPNOW * [View page source](../_sources/system/m5espnow.rst.txt) * * * M5-ESPNOW[](#m5-espnow "Link to this heading") ================================================ M5-ESPNOW is a connection-less wireless communication protocol supporting: * Direct communication between up to 20 registered peers: > * Without the need for a wireless access point (AP), > * Encrypted and unencrypted communication (up to 6 encrypted peers), * Message sizes up to 250 bytes, * Can operate alongside Wifi operation (network.WLAN) on ESP32 Series. It provides simpler and more user-friendly APIs. ESPNOW example: import os, sys, io import M5 from M5 import \* from m5espnow import \* import time import random def espnow\_recv\_callback(espnow\_obj): espnow\_mac, espnow\_data \= espnow\_obj.recv\_data() print(espnow\_mac) print(espnow\_data) espnow\_0 \= M5ESPNow(0) espnow\_0.set\_irq\_callback(espnow\_recv\_callback) espnow\_0.set\_add\_peer('xxxxxxxxxxxx', 1, 0, False) while True:: espnow\_0.send\_data(1, random.randint(1000000, 9999999)) time.sleep(2) UIFLOW2 Example: > ![m5espnow-example.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/example.png) [m5espnow-example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/m5espnow/m5espnow-example.m5f2) class M5ESPNow[](#class-m5espnow "Link to this heading") ---------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ M5ESPNow(_wifi\_ch_)[](#M5ESPNow "Link to this definition") Create a M5ESPNow object Arguments: * `wifi_ch`: The wifi channel (2.4GHz) to communicate with this peer. Must be an integer from 0 to 14. If channel is set to 0 the current channel of the wifi device will be used. (default=0) UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/init.png) M5ESPNow.deinit()[](#M5ESPNow.deinit "Link to this definition") De-initialise the ESP-NOW software stack, disable callbacks, deallocate the recv data buffer and deregister all peers. UIFLOW2: > ![deinit.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/deinit.png) M5ESPNow.get\_mac(_mode_)[](#M5ESPNow.get_mac "Link to this definition") Get the device network MAC address. Arguments: `mode`: 0: M5ESPNow.STA 1: M5ESPNow.AP * Return: `bytes` UIFLOW2: > ![get_mac.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/get_mac.png) M5ESPNow.get\_peer\_list(_encrypt_)[](#M5ESPNow.get_peer_list "Link to this definition") Return the parameters for all the registered peers (as a list). Arguments: `encrypt`: 0: normal peer MAC address 1: encrypt peer MAC address * Return: `list` UIFLOW2: > ![get_peer_list.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/get_peer_list.png) M5ESPNow.get\_remote\_mac(_select_, _ssid_)[](#M5ESPNow.get_remote_mac "Link to this definition") To find remote mac by remote ssid. Arguments: `select`: 0: channel 1: MAC. `ssid`: WiFi access point name in string. UIFLOW2: > ![get_remote_mac.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/get_remote_mac.png) M5ESPNow.set\_ap\_ssid(_ssid_)[](#M5ESPNow.set_ap_ssid "Link to this definition") Set the SSID configure in AP mode. Arguments: `ssid`: WiFi access point name in string. UIFLOW2: > ![set_ap_ssid.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/set_ap_ssid.png) Methods[](#methods "Link to this heading") -------------------------------------------- M5ESPNow.set\_add\_peer(_peer\_mac_, _peer\_id_, _ifidx_, _encrypt_, _lmk_)[](#M5ESPNow.set_add_peer "Link to this definition") Add/register the provided mac address as a peer. Arguments: * `peer_mac`: The MAC address of the peer (as a Hex-string). * `peer_id`: The MAC address is stored in the ID list. ID is must be an integer from 1 to 20 * `ifidx`: Index of the wifi interface which will be used to send data to this peer.Must be an integer set to `network.STA_IF` (=0) or `network.AP_IF` (=1). (default=0/`network.STA_IF`). * `encrypt`: If set to `True` data exchanged with this peer will be encrypted with the PMK and LMK. (default = `False` if `lmk` is set to a valid key, else `False`) * `lmk`: The Local Master Key (LMK) key used to encrypt data transfers with this peer (unless the `encrypt` parameter is set to `False`). Must be: * a byte-string or bytearray or string of length 16 bytes. UIFLOW2: > ![set_add_peer.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/set_add_peer.png) M5ESPNow.set\_delete\_peer(_peer\_id_)[](#M5ESPNow.set_delete_peer "Link to this definition") Deregister the peer associated with the provided `peer_mac` address. Arguments: * `peer_id`: The MAC address is stored in the ID list. ID is must be an integer from 1 to 20 UIFLOW2: > ![set_delete_peer.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/set_delete_peer.png) M5ESPNow.set\_pmk\_encrypt(_pmk_)[](#M5ESPNow.set_pmk_encrypt "Link to this definition") Set the Primary Master Key (PMK) which is used to encrypt the Local Master Keys (LMK) for encrypting messages. If this is not set, a default PMK is used by the underlying Espressif ESP-NOW software stack. Arguments: `pmk`: Must be a byte string, bytearray or string of length(16 bytes) UIFLOW2: > ![set_pmk_encrypt.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/set_pmk_encrypt.png) M5ESPNow.send\_data(_peer\_id_, _msg_)[](#M5ESPNow.send_data "Link to this definition") Send the data in `msg` to the stored peer ID `peer_id` with the given network. Arguments: * `peer_id`: The MAC address is stored in the ID list. ID is must be an integer from 1 to 20 * `msg`: int, float, list, string and byte-string up to 250 bytes UIFLOW2: > ![send_data.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/send_data.png) > > ![send_data1.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/send_data1.png) > > ![send_data2.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/send_data2.png) M5ESPNow.broadcast\_data(_msg_)[](#M5ESPNow.broadcast_data "Link to this definition") All devices will also receive messages sent to the `broadcast` MAC address (`b'\xff\xff\xff\xff\xff\xff'`) Arguments: * `msg`: int, float, list, string and byte-string up to 250 bytes UIFLOW2: > ![broadcast_data.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/broadcast_data.png) > > ![broadcast_data1.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/broadcast_data1.png) > > ![broadcast_data2.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/broadcast_data2.png) M5ESPNow.set\_irq\_callback(_callback_)[](#M5ESPNow.set_irq_callback "Link to this definition") Set a callback function to be called as soon as possible after a message has been received from another ESPNow device. The callback function will be called with the ESPNow instance object as an argument. For more reliable operation, it is recommended to read out as many messages as are available when the callback is invoked. def espnow\_recv\_callback(espnow\_obj): espnow\_mac, espnow\_data \= espnow\_obj.recv\_data() print(espnow\_mac, espnow\_data) M5ESPNow.set\_irq\_callback(espnow\_recv\_callback) recv\_data()[](#M5ESPNow.recv_data "Link to this definition") Wait for an incoming message and return values: `[mac, msg]`. UIFLOW2: > ![set_irq_callback.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/recv_data.png) M5ESPNow.\_bytes\_to\_hex\_str(_bytes_)[](#M5ESPNow._bytes_to_hex_str "Link to this definition") To get a hex string from a bytes string Arguments: `bytes`: bytearray * Return: `string`: Hex-string UIFLOW2: > ![_bytes_to_hex_str.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/_bytes_to_hex_str.png) M5ESPNow.\_hex\_str\_to\_bytes(_hexstr_)[](#M5ESPNow._hex_str_to_bytes "Link to this definition") To get a bytes string from a hex string Arguments: `hexstr`: Hex-string * Return: `bytes`: bytearray UIFLOW2: > ![_hex_str_to_bytes.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/_hex_str_to_bytes.png) M5ESPNow.\_bytes\_to(_bytes_, _format_)[](#M5ESPNow._bytes_to "Link to this definition") > To get a int or float or list valuefrom a bytes string. Arguments: `bytes`: bytearray. `format`: 0: int, 1: float. * Return: `int or float` UIFLOW2: > ![_bytes_to.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/_bytes_to.png) M5ESPNow.\_to\_bytes(_variable_)[](#M5ESPNow._to_bytes "Link to this definition") To get a bytes string from a int or float or list value Arguments: `variable`: int or float or list * Return: `bytes`: bytearray UIFLOW2: > ![_to_bytes.png](https://static-cdn.m5stack.com/mpy_docs/system/espnow/_to_bytes.png) --- # Button — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * Button * [View page source](../_sources/hardware/button.rst.txt) * * * Button[](#button "Link to this heading") ========================================== Button is used to control the built-in buttons inside the host device. Below is the detailed Button support for the host: | | BtnA | BtnB | BtnC | BtnPWR | BtnEXT | | --- | --- | --- | --- | --- | --- | | AtomS3 | ✔ | | | | | | AtomS3 Lite | ✔ | | | | | | AtomS3U | ✔ | | | | | | StampS3 | ✔ | | | | | | CoreS3 | | | | ✔ | | | Core2 | ✔ | ✔ | ✔ | | | | TOUGH | | | | | | Micropython Example: import os, sys, io import M5 from M5 import \* def btnPWR\_wasClicked\_event(state): global label0 label0.setText('clicked') def btnPWR\_wasHold\_event(state): global label0 label0.setText('hold') M5.begin() Widgets.fillScreen(0x222222) label0 \= Widgets.Label("Text", 58, 43, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu24) BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_CLICKED, cb\=btnPWR\_wasClicked\_event) BtnPWR.setCallback(type\=BtnPWR.CB\_TYPE.WAS\_HOLD, cb\=btnPWR\_wasHold\_event) while True: M5.update() UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/example.svg) [button\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/button/button_cores3.m5f2) class Button[](#class-button "Link to this heading") ------------------------------------------------------ Important Methods of Button Class heavily rely on `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg) and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg). All calls to methods of Button objects should be placed after `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg) and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg) should be called in the main loop. Methods[](#methods "Link to this heading") -------------------------------------------- Button.isHolding()[](#Button.isHolding "Link to this definition") Returns whether the Button object is in a long press state. UIFLOW2: > ![isHolding.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/isHolding.svg) Button.isPressed()[](#Button.isPressed "Link to this definition") Returns whether the Button object is in a pressed state. UIFLOW2: > ![isPressed.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/isPressed.svg) Button.isReleased()[](#Button.isReleased "Link to this definition") Returns whether the Button object is in a released state. UIFLOW2: > ![isReleased.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/isReleased.svg) Button.wasClicked()[](#Button.wasClicked "Link to this definition") Returns True when the Button object is briefly pressed and released. UIFLOW2: > ![wasClicked.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasClicked.svg) Button.wasDoubleClicked()[](#Button.wasDoubleClicked "Link to this definition") Returns True when the Button object is double-clicked after a certain amount of time. UIFLOW2: > ![wasDoubleClicked.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasDoubleClicked.svg) Button.wasHold()[](#Button.wasHold "Link to this definition") Returns True when the Button object is held down for a certain amount of time. UIFLOW2: > ![wasHold.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasHold.svg) Button.wasPressed()[](#Button.wasPressed "Link to this definition") Returns True when the Button object is pressed. UIFLOW2: > ![wasPressed.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasPressed.svg) Button.wasReleased()[](#Button.wasReleased "Link to this definition") Returns True when the Button object is released. UIFLOW2: > ![wasReleased.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasReleased.svg) Button.wasSingleClicked()[](#Button.wasSingleClicked "Link to this definition") Returns True when the Button object is single-clicked after a certain amount of time. UIFLOW2: > ![wasSingleClicked.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/wasSingleClicked.svg) Event Handling[](#event-handling "Link to this heading") ---------------------------------------------------------- Button.setCallback(_type: Callback\_Type_, _cb_)[](#Button.setCallback "Link to this definition") Sets the event callback function. UIFLOW2: > ![setCallback.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/button/setCallback.svg) Constants[](#constants "Link to this heading") ------------------------------------------------ Button.CB\_TYPE[](#Button.CB_TYPE "Link to this definition") A Callback\_Type object. class Callback\_Type[](#class-callback-type "Link to this heading") --------------------------------------------------------------------- Constants[](#id1 "Link to this heading") ------------------------------------------ Callback\_Type.WAS\_CLICKED[](#Callback_Type.WAS_CLICKED "Link to this definition") Single click event type. Callback\_Type.WAS\_DOUBLECLICKED[](#Callback_Type.WAS_DOUBLECLICKED "Link to this definition") Double click event type. Callback\_Type.WAS\_HOLD[](#Callback_Type.WAS_HOLD "Link to this definition") Long press event type. Callback\_Type.WAS\_PRESSED[](#Callback_Type.WAS_PRESSED "Link to this definition") Press event type Callback\_Type.WAS\_RELEASED[](#Callback_Type.WAS_RELEASED "Link to this definition") Release event type --- # TCP — UIFlow2 Programming Guide master documentation * [](../index.html) * [Software](index.html) * TCP * [View page source](../_sources/software/tcp.rst.txt) * * * TCP[](#tcp "Link to this heading") ==================================== TCP is a connection-oriented protocol, meaning that a connection must be established before data can be sent. It uses a three-way handshake to establish a connection, which involves the exchange of SYN (synchronize) and ACK (acknowledge) packets between the client and server. Once the connection is established, data can be sent in both directions until either party decides to close the connection. API[](#api "Link to this heading") ------------------------------------ * [TCP Client](tcp.client.html) * [TCP Server](tcp.server.html) --- # ACMeasure Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * ACMeasure Unit * [View page source](../_sources/units/ac_measure.rst.txt) * * * ACMeasure Unit[](#acmeasure-unit "Link to this heading") ========================================================== C Measure Unit is a single-phase AC measurement module with isolation capabilities. It utilizes the STM32+HLW8032 scheme to monitor high-precision current, voltage, power, and other data in real time. The module features a built-in AC isolation chip, B0505ST16-W5, and communicates with the STM32 through the EL357 optocoupler isolation chip. Support the following products: [![ACMeasureUnit](https://static-cdn.m5stack.com/resource/docs/products/unit/AC%20Measure%20Unit/img-28a2411d-d63c-4596-b474-2db9d9b6dcc5.webp)](https://docs.m5stack.com/en/unit/AC%20Measure%20Unit) 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 ACMeasureUnit > 10 > 11 > 12label0 \= None > 13title0 \= None > 14label1 \= None > 15i2c0 \= None > 16ac\_measure\_0 \= None > 17 > 18 > 19def setup(): > 20 global label0, title0, label1, i2c0, ac\_measure\_0 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 label0 \= Widgets.Label("label0", 1, 81, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 title0 \= Widgets.Title( > 26 "ACMeasureUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 27 ) > 28 label1 \= Widgets.Label("label1", 1, 125, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 > 30 i2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) > 31 ac\_measure\_0 \= ACMeasureUnit(i2c0, 0x42) > 32 > 33 > 34def loop(): > 35 global label0, title0, label1, i2c0, ac\_measure\_0 > 36 M5.update() > 37 label0.setText(str((str("Voltage:") + str((ac\_measure\_0.get\_voltage\_str()))))) > 38 label1.setText(str((str("Current:") + str((ac\_measure\_0.get\_current\_str()))))) > 39 M5.update() > 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](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/example.png) [acmeasure\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/ac_measure/acmeasure_cores3_example.m5f2) class ACMeasureUnit[](#class-acmeasureunit "Link to this heading") -------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ACMeasureUnit(_i2c_, _address_)[](#ACMeasureUnit "Link to this definition") Initialize the AC Measure unit by setting the I2C port and the AC Measure slave address. Parameters: * **i2c** – The I2C interface object or PAHUBUnit used for communication. * **address** – The I2C address of the AC Measure unit, default is 0x42. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ACMeasureUnit.init\_i2c\_address(_slave\_addr_)[](#ACMeasureUnit.init_i2c_address "Link to this definition") Initialize the I2C address for the AC Measure unit. Parameters: **slave\_addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the AC Measure unit, should be between 1 and 127. ACMeasureUnit.get\_voltage\_str()[](#ACMeasureUnit.get_voltage_str "Link to this definition") Get the voltage string value from the AC Measure unit. Returns: The voltage value as a string. UIFLOW2: > ![get_voltage_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_voltage_str.png) ACMeasureUnit.get\_current\_str()[](#ACMeasureUnit.get_current_str "Link to this definition") Get the current string value from the AC Measure unit. Returns: The current value as a string. UIFLOW2: > ![get_current_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_current_str.png) ACMeasureUnit.get\_active\_power\_str()[](#ACMeasureUnit.get_active_power_str "Link to this definition") Get the active power string value from the AC Measure unit. Returns: The active power value as a string. UIFLOW2: > ![get_active_power_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_active_power_str.png) ACMeasureUnit.get\_apparent\_power\_str()[](#ACMeasureUnit.get_apparent_power_str "Link to this definition") Get the apparent power string value from the AC Measure unit. Returns: The apparent power value as a string. UIFLOW2: > ![get_apparent_power_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_apparent_power_str.png) ACMeasureUnit.get\_power\_factor\_str()[](#ACMeasureUnit.get_power_factor_str "Link to this definition") Get the power factor string value from the AC Measure unit. Returns: The power factor value as a string. UIFLOW2: > ![get_power_factor_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_power_factor_str.png) ACMeasureUnit.get\_kwh\_str()[](#ACMeasureUnit.get_kwh_str "Link to this definition") Get the kWh string value from the AC Measure unit. Returns: The kWh value as a string. UIFLOW2: > ![get_kwh_str.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_kwh_str.png) ACMeasureUnit.get\_voltage\_byte()[](#ACMeasureUnit.get_voltage_byte "Link to this definition") Get the raw voltage value from the AC Measure unit. Returns: The raw voltage value as an integer. UIFLOW2: > ![get_voltage_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_voltage_byte.png) ACMeasureUnit.get\_current\_byte()[](#ACMeasureUnit.get_current_byte "Link to this definition") Get the raw current value from the AC Measure unit. Returns: The raw current value as an integer. UIFLOW2: > ![get_current_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_current_byte.png) ACMeasureUnit.get\_active\_power\_byte()[](#ACMeasureUnit.get_active_power_byte "Link to this definition") Get the raw active power value from the AC Measure unit. Returns: The raw active power value as an integer. UIFLOW2: > ![get_active_power_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_active_power_byte.png) ACMeasureUnit.get\_apparent\_power\_byte()[](#ACMeasureUnit.get_apparent_power_byte "Link to this definition") Get the raw apparent power value from the AC Measure unit. Returns: The raw apparent power value as an integer. UIFLOW2: > ![get_apparent_power_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_apparent_power_byte.png) ACMeasureUnit.get\_power\_factor\_byte()[](#ACMeasureUnit.get_power_factor_byte "Link to this definition") Get the raw power factor value from the AC Measure unit. Returns: The raw power factor value as an integer. UIFLOW2: > ![get_power_factor_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_power_factor_byte.png) ACMeasureUnit.get\_kwh\_byte()[](#ACMeasureUnit.get_kwh_byte "Link to this definition") Get the raw kWh value from the AC Measure unit. Returns: The raw kWh value as an integer. UIFLOW2: > ![get_kwh_byte.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_kwh_byte.png) ACMeasureUnit.get\_voltage\_coeff()[](#ACMeasureUnit.get_voltage_coeff "Link to this definition") Get the voltage coefficient value from the AC Measure unit. Returns: The voltage coefficient value as an integer. UIFLOW2: > ![get_voltage_coeff.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_voltage_coeff.png) ACMeasureUnit.set\_voltage\_coeff(_value_)[](#ACMeasureUnit.set_voltage_coeff "Link to this definition") Set the voltage coefficient value for the AC Measure unit. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The voltage coefficient value to set, between 0 and 255. UIFLOW2: > ![set_voltage_coeff.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/set_voltage_coeff.png) ACMeasureUnit.get\_current\_coeff()[](#ACMeasureUnit.get_current_coeff "Link to this definition") Get the current coefficient value from the AC Measure unit. Returns: The current coefficient value as an integer. UIFLOW2: > ![get_current_coeff.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_current_coeff.png) ACMeasureUnit.set\_current\_coeff(_value_)[](#ACMeasureUnit.set_current_coeff "Link to this definition") Set the current coefficient value for the AC Measure unit. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The current coefficient value to set, between 0 and 255. UIFLOW2: > ![set_current_coeff.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/set_current_coeff.png) ACMeasureUnit.set\_save\_coeff()[](#ACMeasureUnit.set_save_coeff "Link to this definition") Save the voltage and current coefficient values to flash memory. UIFLOW2: > ![set_save_coeff.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/set_save_coeff.png) ACMeasureUnit.get\_data\_ready()[](#ACMeasureUnit.get_data_ready "Link to this definition") Check if the AC Measure unit data is ready. Returns: True if data is ready, False otherwise. UIFLOW2: > ![get_data_ready.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_data_ready.png) ACMeasureUnit.set\_jump\_bootloader()[](#ACMeasureUnit.set_jump_bootloader "Link to this definition") Set the AC Measure unit to jump to the bootloader. ACMeasureUnit.get\_device\_status(_mode_)[](#ACMeasureUnit.get_device_status "Link to this definition") Get the firmware version or I2C address based on the specified mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The mode to select the desired status (0xFE for firmware version, 0xFF for I2C address). Returns: The requested device status as an integer. UIFLOW2: > ![get_device_status.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/get_device_status.png) ACMeasureUnit.set\_i2c\_address(_addr_)[](#ACMeasureUnit.set_i2c_address "Link to this definition") Set a new I2C address for the AC Measure unit. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address to set, between 0x01 and 0x7F. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/ac_measure/set_i2c_address.png) --- # WLAN STA – control built-in WiFi interfaces — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * WLAN STA – control built-in WiFi interfaces * [View page source](../_sources/system/wlan.sta.rst.txt) * * * WLAN STA – control built-in WiFi interfaces[](#wlan-sta-control-built-in-wifi-interfaces "Link to this heading") ================================================================================================================== This class provides a driver for WiFi STA network processors. 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 image\_plus import ImagePlus > 9 > 10 > 11title0 \= None > 12image\_plus0 \= None > 13 > 14 > 15def setup(): > 16 global title0, image\_plus0 > 17 > 18 M5.begin() > 19 Widgets.fillScreen(0x222222) > 20 title0 \= Widgets.Title("Image+ CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 21 image\_plus0 \= ImagePlus( > 22 "https://static-cdn.m5stack.com/resource/public/assets/aboutus/m5logo2022.png", > 23 43, > 24 51, > 25 True, > 26 3000, > 27 default\_img\="res/img/default.png", > 28 ) > 29 > 30 image\_plus0.setVisible(True) > 31 image\_plus0.set\_update\_period(5000) > 32 image\_plus0.set\_update\_enable(True) > 33 > 34 > 35def loop(): > 36 global title0, image\_plus0 > 37 M5.update() > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/example.png) [wlan\_sta\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/wlan_sta/wlan_sta_cores3_example.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ network.WLAN(_interface\_id_) Create a WLAN network interface object. Supported interfaces are `network.STA_IF` (station aka client, connects to upstream WiFi access points) > UIFLOW2: > > > ![init.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- WLAN.status(\[_param_\]) > Return the current status of the wireless connection. > > When called with no argument the return value describes the network link status. The possible statuses are defined as constants: > > > * `STAT_IDLE` – no connection and no activity, > > > > * `STAT_CONNECTING` – connecting in progress, > > > > * `STAT_WRONG_PASSWORD` – failed due to incorrect password, > > > > * `STAT_NO_AP_FOUND` – failed because no access point replied, > > > > * `STAT_CONNECT_FAIL` – failed due to other problems, > > > > * `STAT_GOT_IP` – connection successful. > > > > When called with one argument _param_ should be a string naming the status parameter to retrieve. > > Supported parameters in WiFI STA mode are: `'rssi'`. > > UIFLOW2: > > > ![get_rssi.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_rssi.png) WLAN.isconnected() > In case of STA mode, returns `True` if connected to a WiFi access point and has a valid IP address. > > UIFLOW2: > > > ![isconnected.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/isconnected.png) WLAN.active(\[_is\_active_\]) > Activate (“up”) or deactivate (“down”) network interface, if boolean argument is passed. Otherwise, query current state if no argument is provided. Most other methods require active interface. > > > ![active.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/active.png) WLAN.connect(_ssid\=None_, _key\=None_, _\*_, _bssid\=None_)[](#network.WLAN.connect "Link to this definition") Connect to the specified wireless network, using the specified key. If _bssid_ is given then the connection will be restricted to the access-point with that MAC address (the _ssid_ must also be specified in this case). > ![connect.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/connect.png) WLAN.disconnect() > Disconnect from the currently connected wireless network. > > > ![disconnect.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/disconnect.png) WLAN.ifconfig(\[_(ip_, _subnet_, _gateway_, _dns)_\]) Get/set IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. When called with no arguments, this method returns a 4-tuple with the above information. To set the above values, pass a 4-tuple with the required information. å > ![get_localip.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_localip.png) > > ![get_subnet.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_subnet.png) > > ![get_gateway.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_gateway.png) > > ![get_dns.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_dns.png) WLAN.config(_'param'_) WLAN.config(_param=value_, _..._) Get or set general network interface parameters. These methods allow to work with additional parameters beyond standard IP configuration (as dealt with by AbstractNIC.ipconfig()). These include network-specific and hardware-specific parameters. For setting parameters, keyword argument syntax should be used, multiple parameters can be set at once. For querying, parameters name should be quoted as a string, and only one parameter can be queried at a time: Following are commonly supported parameters (availability of a specific parameter depends on network technology type, driver, and MicroPython port). | Parameter | Description | | --- | --- | | mac | MAC address (bytes) | | ssid | WiFi access point name (string) | | channel | WiFi channel (integer) | | hidden | Whether SSID is hidden (boolean) | | security | Security protocol supported (enumeration, see module constants) | | key | Access key (string) | | hostname | The hostname that will be sent to DHCP (STA interfaces) and mDNS (if supported, both STA and AP). (Deprecated, use [`network.hostname()`](https://docs.micropython.org/en/v1.22.0/library/network.html#network.hostname "(in MicroPython vv1.22.0)")
instead) | | reconnects | Number of reconnect attempts to make (integer, 0=none, -1=unlimited) | | txpower | Maximum transmit power in dBm (integer or float) | | pm | WiFi Power Management setting (see below for allowed values) | > ![set_dhcp_hostname.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/set_dhcp_hostname.png) > > ![set_reconnects.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/set_reconnects.png) > > ![set_txpower.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/set_txpower.png) > > ![get_dhcp_hostname.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_dhcp_hostname.png) > > ![get_reconnects.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_reconnects.png) > > ![get_txpower.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_txpower.png) > > ![get_mac.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/get_mac.png) WLAN.scan()[](#network.WLAN.scan "Link to this definition") Scan for the available wireless networks. Hidden networks – where the SSID is not broadcast – will also be scanned if the WLAN interface allows it. Scanning is only possible on STA interface. Returns list of tuples with the information about WiFi access points: > (ssid, bssid, channel, RSSI, security, hidden) _bssid_ is hardware address of an access point, in binary form, returned as bytes object. You can use binascii.hexlify() to convert it to ASCII form. There are five values for security: > * 0 – open > > * 1 – WEP > > * 2 – WPA-PSK > > * 3 – WPA2-PSK > > * 4 – WPA/WPA2-PSK > and two for hidden: > * 0 – visible > > * 1 – hidden > > > ![scan.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/scan.png) > > ![scan_get_value.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_sta/scan_get_value.png) --- # CAN — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * CAN * [View page source](../_sources/hardware/can.rst.txt) * * * CAN[](#can "Link to this heading") ==================================== CAN implements support for classic CAN (available on F4, F7 MCUs) and CAN FD (H7 series) controllers. At the physical level CAN bus consists of 2 lines: RX and TX. Note that to connect the pyboard to a CAN bus you must use a CAN transceiver to convert the CAN logic signals from the pyboard to the correct voltage levels on the bus. Example usage for classic CAN controller in Loopback (transceiver-less) mode: from m5can import CAN can \= CAN(1, CAN.LOOPBACK, 1, 2) can.send('message!', 123) \# send a message with id 123 can.recv(0) \# receive message For detailed examples, please refer to: [unit.CANUnit](../units/can.html#unit-canunit) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ CAN(_bus_, _mode_, _tx_, _rx_, _prescaler\=32_, _sjw\=3_, _bs1\=15_, _bs2\=4_, _triple\_sampling\=False_)[](#CAN "Link to this definition") Construct a CAN object on the given bus. _bus_ must be 0. With no additional parameters, the CAN object is created but not initialised (it has the settings from the last initialisation of the bus, if any). If extra arguments are given, the bus is initialised. See [`CAN.init()`](#CAN.init "CAN.init") for parameters of initialisation. UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- CAN.init(_mode_, _tx_, _rx_, _prescaler\=32_, _sjw\=3_, _bs1\=15_, _bs2\=4_, _triple\_sampling\=False_)[](#CAN.init "Link to this definition") Initialise the CAN bus with the given parameters: > * _mode_ is one of: NORMAL, NO\_ACKNOWLEDGE, LISTEN\_ONLY > > * _tx_ is the pin to use for transmitting data > > * _rx_ is the pin to use for receiving data > > * _prescaler_ is the value by which the CAN input clock is divided to generate the nominal bit time quanta. The prescaler can be a value between 1 and 1024 inclusive for classic CAN. > > * _sjw_ is the resynchronisation jump width in units of time quanta for nominal bits; it can be a value between 1 and 4 inclusive for classic CAN. > > * _bs1_ defines the location of the sample point in units of the time quanta for nominal bits; it can be a value between 1 and 16 inclusive for classic CAN. > > * _bs2_ defines the location of the transmit point in units of the time quanta for nominal bits; it can be a value between 1 and 8 inclusive for classic CAN. > > * _triple\_sampling_ is Enables triple sampling when the TWAI controller samples a bit > The time quanta tq is the basic unit of time for the CAN bus. tq is the CAN prescaler value divided by APB\_CLK clock source (typically 80 MHz); A single bit is made up of the synchronisation segment, which is always 1 tq. Then follows bit segment 1, then bit segment 2. The sample point is after bit segment 1 finishes. The transmit point is after bit segment 2 finishes. The baud rate will be 1/bittime, where the bittime is 1 + BS1 + BS2 multiplied by the time quanta tq. For example, with APB\_CLK=80MHz, prescaler=32, sjw=3, bs1=15, bs2=4, the value of tq is 0.4 microseconds. The bittime is 8 microseconds, and the baudrate is 125kHz. See esp32 technical reference manual for more details. CAN.deinit()[](#CAN.deinit "Link to this definition") Turn off the CAN bus. UIFLOW2: > ![deinit.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/deinit.svg) CAN.restart()[](#CAN.restart "Link to this definition") Force a software restart of the CAN controller without resetting its configuration. If the controller enters the bus-off state then it will no longer participate in bus activity. If the controller is not configured to automatically restart (see [`init()`](#CAN.init "CAN.init") ) then this method can be used to trigger a restart, and the controller will follow the CAN protocol to leave the bus-off state and go into the error active state. UIFLOW2: > ![restart.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/restart.svg) CAN.state()[](#CAN.state "Link to this definition") Return the state of the controller. The return value can be one of: * `CAN.STOPPED` – the controller is completely off and reset; * `CAN.RUNNING` – The controller can transmit and receive messages; * `CAN.BUS_OFF` – the controller is on but not participating in bus activity (TEC overflowed beyond 255); * `RECOVERING` – The controller is undergoing bus recovery. UIFLOW2: > ![state.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/get_state.svg) CAN.info(\[_list_\])[](#CAN.info "Link to this definition") Get information about the controller’s error states and TX and RX buffers. If _list_ is provided then it should be a list object with at least 8 entries, which will be filled in with the information. Otherwise a new list will be created and filled in. In both cases the return value of the method is the populated list. The values in the list are: * TEC value * REC value * number of times the controller enterted the Error Warning state(ignored for now, compatible with pyb.CAN) * number of times the controller enterted the Error Passive state(ignored for now, compatible with pyb.CAN) * number of times the controller enterted the Bus Off state(ignored for now, compatible with pyb.CAN) * number of pending TX messages * number of pending RX messages * number of pending RX messages on fifo 1(ignored for now, compatible with pyb.CAN) UIFLOW2: > ![info.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/get_info.svg) CAN.any(_fifo_)[](#CAN.any "Link to this definition") Return `True` if any message waiting on the FIFO, else `False`. UIFLOW2: > ![any.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/any.svg) CAN.recv(_fifo_, _list\=None_, _\*_, _timeout\=5000_)[](#CAN.recv "Link to this definition") Receive data on the bus: > * _fifo_ is an integer, it can be any number and compatible with pyb.CAN > > * _list_ is an optional list object to be used as the return value > > * _timeout_ is the timeout in milliseconds to wait for the receive. > Return value: A tuple containing five values. > * The id of the message. > > * A boolean that indicates if the message ID is standard or extended. > > * A boolean that indicates if the message is an RTR message. > > * The FMI (Filter Match Index) value. > > * An array containing the data. > If _list_ is `None` then a new tuple will be allocated, as well as a new bytes object to contain the data (as the fifth element in the tuple). If _list_ is not `None` then it should be a list object with a least five elements. The fifth element should be a memoryview object which is created from either a bytearray or an array of type ‘B’ or ‘b’, and this array must have enough room for at least 8 bytes. The list object will then be populated with the first four return values above, and the memoryview object will be resized inplace to the size of the data and filled in with that data. The same list and memoryview objects can be reused in subsequent calls to this method, providing a way of receiving data without using the heap. For example: buf \= bytearray(8) lst \= \[0, 0, 0, 0, memoryview(buf)\] \# No heap memory is allocated in the following call can.recv(0, lst) UIFLOW2: > ![recv1.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/recv_message.svg) > > ![recv2.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/recv_message_into.svg) CAN.send(_data_, _id_, _\*_, _timeout\=0_, _rtr\=False_, _extframe\=False_)[](#CAN.send "Link to this definition") Send a message on the bus: > * _data_ is the data to send (an integer to send, or a buffer object). > > * _id_ is the id of the message to be sent. > > * _timeout_ is the timeout in milliseconds to wait for the send. > > * _rtr_ is a boolean that specifies if the message shall be sent as a remote transmission request. If _rtr_ is True then only the length of _data_ is used to fill in the DLC slot of the frame; the actual bytes in _data_ are unused. > > * _extframe_ if True the frame will have an extended identifier (29 bits), otherwise a standard identifier (11 bits) is used. > > > If timeout is 0 the message is placed in a buffer in one of three hardware buffers and the method returns immediately. If all three buffers are in use an exception is thrown. If timeout is not 0, the method waits until the message is transmitted. If the message can’t be transmitted within the specified time an exception is thrown. Return value: `None`. UIFLOW2: > ![send.svg](https://static-cdn.m5stack.com/mpy_docs/hardware/can/send.svg) Constants[](#constants "Link to this heading") ------------------------------------------------ CAN.NORMAL[](#CAN.NORMAL "Link to this definition") CAN.NO\_ACKNOWLEDGE[](#CAN.NO_ACKNOWLEDGE "Link to this definition") CAN.LISTEN\_ONLY[](#CAN.LISTEN_ONLY "Link to this definition") The mode of the CAN bus used in [`init()`](#CAN.init "CAN.init") . CAN.STOPPED[](#CAN.STOPPED "Link to this definition") CAN.RUNNING[](#CAN.RUNNING "Link to this definition") CAN.BUS\_OFF[](#CAN.BUS_OFF "Link to this definition") CAN.RECOVERING[](#CAN.RECOVERING "Link to this definition") Possible states of the CAN controller returned from [`state()`](#CAN.state "CAN.state") . --- # Accel Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * Accel Unit * [View page source](../_sources/units/accel.rst.txt) * * * Accel Unit[](#accel-unit "Link to this heading") ================================================== This is the driver library of Accel Unit, which is used to obtain data from the acceleration sensor and support motion detection. Support the following products: > [![ACCEL](https://static-cdn.m5stack.com/resource/docs/products/unit/accel/accel_01.webp)](https://docs.m5stack.com/en/unit/accel) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### get accel value[](#get-accel-value "Link to this heading") Open the [stickcplus2\_unit\_accel\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/accel/stickcplus2_unit_accel_example.m5f2) project in UiFlow2. This example gets the acceleration value of the Accel Unit and displays it on the screen. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### get accel value[](#id1 "Link to this heading") This example gets the acceleration value of the Accel Unit and displays it on the screen. MicroPython Code Block: > 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 AccelUnit > 10 > 11 > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15title0 \= None > 16label3 \= None > 17label4 \= None > 18label5 \= None > 19i2c0 \= None > 20accel\_0 \= None > 21 > 22 > 23acc \= None > 24 > 25 > 26def setup(): > 27 global label0, label1, label2, title0, label3, label4, label5, i2c0, accel\_0, acc > 28 > 29 M5.begin() > 30 label0 \= Widgets.Label("x:", 4, 48, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 31 label1 \= Widgets.Label("y:", 4, 88, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 32 label2 \= Widgets.Label("z:", 4, 128, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 33 title0 \= Widgets.Title("ACCEL UNIT", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 34 label3 \= Widgets.Label("label3", 24, 48, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 35 label4 \= Widgets.Label("label4", 24, 88, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 36 label5 \= Widgets.Label("label5", 24, 128, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 37 > 38 i2c0 \= I2C(0, scl\=Pin(33), sda\=Pin(32), freq\=100000) > 39 accel\_0 \= AccelUnit(i2c0, 0x53) > 40 > 41 > 42def loop(): > 43 global label0, label1, label2, title0, label3, label4, label5, i2c0, accel\_0, acc > 44 M5.update() > 45 acc \= accel\_0.get\_accel() > 46 label3.setText(str(acc\[0\])) > 47 label4.setText(str(acc\[1\])) > 48 label5.setText(str(acc\[2\])) > 49 > 50 > 51if \_\_name\_\_ \== "\_\_main\_\_": > 52 try: > 53 setup() > 54 while True: > 55 loop() > 56 except (Exception, KeyboardInterrupt) as e: > 57 try: > 58 from utility import print\_error\_msg > 59 > 60 print\_error\_msg(e) > 61 except ImportError: > 62 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### AccelUnit[](#accelunit "Link to this heading") _class_ unit.accel.AccelUnit(_i2c_, _address\=83_)[](#unit.accel.AccelUnit "Link to this definition") Bases: [`ADXL345`](#unit.accel.ADXL345 "driver.adxl34x.ADXL345") Create an AccelUnit object. Parameters: * **i2c** (_I2C_) – The I2C bus the Accel Unit is connected to. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the device. Default is 0x53. UiFlow2 Code Block: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/init.svg) MicroPython Code Block: > from hardware import I2C > from unit import AccelUnit > > acceli2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) > accel\_0 \= AccelUnit(i2c0) disable\_freefall\_detection()[](#unit.accel.AccelUnit.disable_freefall_detection "Link to this definition") Disable freefall detection. UiFlow2 Code Block: > ![disable_freefall_detection.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/disable_freefall_detection.png) MicroPython Code Block: > accel\_0.disable\_freefall\_detection() Return type: None disable\_motion\_detection()[](#unit.accel.AccelUnit.disable_motion_detection "Link to this definition") Disable motion detection. UiFlow2 Code Block: > ![disable_motion_detection.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/disable_motion_detection.png) MicroPython Code Block: > accel\_0.disable\_motion\_detection() Return type: None disable\_tap\_detection()[](#unit.accel.AccelUnit.disable_tap_detection "Link to this definition") Disable tap detection. UiFlow2 Code Block: > ![disable_tap_detection.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/disable_tap_detection.png) MicroPython Code Block: > accel\_0.disable\_tap\_detection() Return type: None enable\_freefall\_detection(_\*_, _threshold\=10_, _time\=25_)[](#unit.accel.AccelUnit.enable_freefall_detection "Link to this definition") Freefall detection parameters: Parameters: * **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value that acceleration on all axes must be under to register as dropped. The scale factor is 62.5 mg/LSB. * **time** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The amount of time that acceleration on all axes must be less than `threshold` to register as dropped. The scale factor is 5 ms/LSB. Values between 100 ms and 350 ms (20 to 70) are recommended. Return type: None If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_freefall\_detection(time\=30) UiFlow2 Code Block: > ![enable_freefall_detection1.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_freefall_detection.png) > > ![enable_freefall_detection2.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_freefall_detection2.png) MicroPython Code Block: > accel\_0.enable\_freefall\_detection() enable\_motion\_detection(_\*_, _threshold\=18_)[](#unit.accel.AccelUnit.enable_motion_detection "Link to this definition") The activity detection parameters. Parameters: **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value that acceleration on any axis must exceed to register as active. The scale factor is 62.5 mg/LSB. Return type: None If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_motion\_detection(threshold\=20) UiFlow2 Code Block: > ![enable_motion_detection1.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_motion_detection.png) > > ![enable_motion_detection2.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_motion_detection1.png) MicroPython Code Block: > accel\_0.enable\_motion\_detection(threshold\=18) enable\_tap\_detection(_\*_, _threshold\=20_, _duration\=50_, _latency\=20_, _window\=255_)[](#unit.accel.AccelUnit.enable_tap_detection "Link to this definition") The tap detection parameters. Parameters: * **tap\_count** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – 1 to detect only single taps, and 2 to detect only double taps. * **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – A threshold for the tap detection. The scale factor is 62.5 mg/LSB The higher the value the less sensitive the detection. * **duration** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – This caps the duration of the impulse above `threshold`. Anything above `duration` won’t register as a tap. The scale factor is 625 µs/LSB. * **latency** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (double tap only) The length of time after the initial impulse falls below `threshold` to start the window looking for a second impulse. The scale factor is 1.25 ms/LSB. * **window** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (double tap only) The length of the window in which to look for a second tap. The scale factor is 1.25 ms/LSB. Return type: None If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_tap\_detection(duration\=30, threshold\=25) UiFlow2 Code Block: > ![enable_tap_detection1.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_tap_detection.png) > > ![enable_tap_detection2.png](https://static-cdn.m5stack.com/mpy_docs/unit/accel/enable_tap_detection2.png) MicroPython Code Block: > accel\_0.enable\_tap\_detection(tap\_count\=1, threshold\=20, duration\=50, latency\=20, window\=255) get\_accel()[](#unit.accel.AccelUnit.get_accel "Link to this definition") The x, y, z acceleration values returned in a 3-tuple in \\(m / s ^ 2\\). Returns: x, y, z acceleration values in \\(m / s ^ 2\\). Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_accel.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/get_accel.svg) MicroPython Code Block: > accel\_0.get\_accel() get\_data\_rate()[](#unit.accel.AccelUnit.get_data_rate "Link to this definition") Get the data rate of the sensor. Returns: The data rate of the sensor. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_data_rate.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/get_data_rate.svg) MicroPython Code Block: > accel\_0.get\_data\_rate() get\_range()[](#unit.accel.AccelUnit.get_range "Link to this definition") Get the measurement range of the sensor. Returns: The measurement range of the sensor. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_range.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/get_range.svg) MicroPython Code Block: > accel\_0.get\_range() is\_freefall()[](#unit.accel.AccelUnit.is_freefall "Link to this definition") Returns True if freefall has been detected. Returns: True if freefall has been detected. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![is_freefall.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/is_freefall.svg) MicroPython Code Block: > accel\_0.is\_freefall() is\_motion()[](#unit.accel.AccelUnit.is_motion "Link to this definition") Returns True if motion has been detected. Returns: True if motion has been detected. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: ![is_motion.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/is_motion.svg) MicroPython Code Block: > accel\_0.is\_motion() is\_tap()[](#unit.accel.AccelUnit.is_tap "Link to this definition") Returns True if a tap has been detected. Returns: True if a tap has been detected. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![is_tap.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/is_tap.svg) MicroPython Code Block: > accel\_0.is\_tap() set\_data\_rate(_rate_)[](#unit.accel.AccelUnit.set_data_rate "Link to this definition") Set the data rate of the sensor. Parameters: **rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The data rate of the sensor. Return type: None UiFlow2 Code Block: > ![set_data_rate.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/set_data_rate.svg) MicroPython Code Block: > accel\_0.set\_data\_rate(accel\_0.RATE\_3200\_HZ) set\_range(_range_)[](#unit.accel.AccelUnit.set_range "Link to this definition") The measurement range of the sensor. Parameters: **range** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The measurement range of the sensor. Return type: None UiFlow2 Code Block: > ![set_range.svg](https://static-cdn.m5stack.com/mpy_docs/unit/accel/set_range.svg) MicroPython Code Block: > accel\_0.set\_range(accel\_0.RANGE\_2\_G) ### ADXL345[](#adxl345 "Link to this heading") _class_ unit.accel.ADXL345(_i2c_, _address\=micropython.const_)[](#unit.accel.ADXL345 "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Driver for the ADXL345 3 axis accelerometer. Parameters: * **i2c** (_I2C_) – The I2C bus the ADXL345 is connected to. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C device address for the sensor. Default is `0x53`. **Quickstart: Importing and using the device** > Here is an example of using the [`ADXL345`](#unit.accel.ADXL345 "unit.accel.ADXL345") > class. First you will need to import the libraries to use the sensor: > > import machine > import adxl34x > > Once this is done you can define your I2C object and define your sensor object: > > i2c \= machine.I2C(0) \# uses board default SDA and SCL pins > accelerometer \= adxl34x.ADXL343(i2c) > > Now you have access to the [`acceleration`](#unit.accel.ADXL345.acceleration "unit.accel.ADXL345.acceleration") > attribute: > > acceleration \= accelerometer.acceleration _property_ acceleration_: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \]_[](#unit.accel.ADXL345.acceleration "Link to this definition") The x, y, z acceleration values returned in a 3-tuple in \\(m / s ^ 2\\). _property_ data\_rate_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#unit.accel.ADXL345.data_rate "Link to this definition") The data rate of the sensor. disable\_freefall\_detection()[](#unit.accel.ADXL345.disable_freefall_detection "Link to this definition") Disable freefall detection. Return type: None disable\_motion\_detection()[](#unit.accel.ADXL345.disable_motion_detection "Link to this definition") Disable motion detection. Return type: None disable\_tap\_detection()[](#unit.accel.ADXL345.disable_tap_detection "Link to this definition") Disable tap detection. Return type: None enable\_freefall\_detection(_\*_, _threshold\=10_, _time\=25_)[](#unit.accel.ADXL345.enable_freefall_detection "Link to this definition") Freefall detection parameters: Parameters: * **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value that acceleration on all axes must be under to register as dropped. The scale factor is 62.5 mg/LSB. * **time** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The amount of time that acceleration on all axes must be less than `threshold` to register as dropped. The scale factor is 5 ms/LSB. Values between 100 ms and 350 ms (20 to 70) are recommended. Return type: None If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_freefall\_detection(time\=30) enable\_motion\_detection(_\*_, _threshold\=18_)[](#unit.accel.ADXL345.enable_motion_detection "Link to this definition") The activity detection parameters. Parameters: **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value that acceleration on any axis must exceed to register as active. The scale factor is 62.5 mg/LSB. If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_motion\_detection(threshold\=20) enable\_tap\_detection(_\*_, _tap\_count\=1_, _threshold\=20_, _duration\=50_, _latency\=20_, _window\=255_)[](#unit.accel.ADXL345.enable_tap_detection "Link to this definition") The tap detection parameters. Parameters: * **tap\_count** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – 1 to detect only single taps, and 2 to detect only double taps. * **threshold** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – A threshold for the tap detection. The scale factor is 62.5 mg/LSB The higher the value the less sensitive the detection. * **duration** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – This caps the duration of the impulse above `threshold`. Anything above `duration` won’t register as a tap. The scale factor is 625 µs/LSB. * **latency** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (double tap only) The length of time after the initial impulse falls below `threshold` to start the window looking for a second impulse. The scale factor is 1.25 ms/LSB. * **window** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – (double tap only) The length of the window in which to look for a second tap. The scale factor is 1.25 ms/LSB. If you wish to set them yourself rather than using the defaults, you must use keyword arguments: accelerometer.enable\_tap\_detection(duration\=30, threshold\=25) _property_ events_: [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") \[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")\ , [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")\ \]_[](#unit.accel.ADXL345.events "Link to this definition") [`events`](#unit.accel.ADXL345.events "unit.accel.ADXL345.events") will return a dictionary with a key for each event type that has been enabled. The possible keys are: | Key | Description | | --- | --- | | `tap` | True if a tap was detected recently. Whether it’s looking for a single or double tap is determined by the tap param of enable\_tap\_detection. | | `motion` | True if the sensor has seen acceleration above the threshold set with enable\_motion\_detection. | | `freefall` | True if the sensor was in freefall. Parameters are set when enabled with enable\_freefall\_detection. | _property_ offset_: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ , [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")\ \]_[](#unit.accel.ADXL345.offset "Link to this definition") The x, y, z offsets as a tuple of raw count values. See offset\_calibration example for usage. _property_ range_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#unit.accel.ADXL345.range "Link to this definition") The measurement range of the sensor. _property_ raw\_x_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#unit.accel.ADXL345.raw_x "Link to this definition") The raw x value. _property_ raw\_y_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#unit.accel.ADXL345.raw_y "Link to this definition") The raw y value. _property_ raw\_z_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#unit.accel.ADXL345.raw_z "Link to this definition") The raw z value. --- # WLAN AP – control built-in WiFi interfaces — UIFlow2 Programming Guide master documentation * [](../index.html) * [System](index.html) * WLAN AP – control built-in WiFi interfaces * [View page source](../_sources/system/wlan.ap.rst.txt) * * * WLAN AP – control built-in WiFi interfaces[](#wlan-ap-control-built-in-wifi-interfaces "Link to this heading") ================================================================================================================ This class provides a driver for WiFi AP network processors. 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 \* > 8import network > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15wlan \= None > 16 > 17 > 18ap\_client \= None > 19 > 20 > 21def setup(): > 22 global title0, label0, label1, label2, wlan > 23 > 24 M5.begin() > 25 Widgets.fillScreen(0x222222) > 26 title0 \= Widgets.Title("WLAN AP CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 27 label0 \= Widgets.Label("label0", 2, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 28 label1 \= Widgets.Label("label1", 2, 111, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label2 \= Widgets.Label("label2", 2, 145, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 > 31 wlan \= network.WLAN(network.AP\_IF) > 32 wlan.config(max\_clients\=4) > 33 wlan.config(essid\="M5CoreS3AP") > 34 wlan.active(True) > 35 > 36 > 37\# Please connect to the AP named M5CoreS3. > 38def loop(): > 39 global title0, label0, label1, label2, wlan > 40 M5.update() > 41 label0.setText(str((str("AP is connected?:") + str((wlan.isconnected()))))) > 42 label1.setText(str((str("SSID:") + str((wlan.config("essid")))))) > 43 for ap\_client in wlan.status("stations"): > 44 label2.setText(str(ap\_client\[0\])) > 45 > 46 > 47if \_\_name\_\_ \== "\_\_main\_\_": > 48 try: > 49 setup() > 50 while True: > 51 loop() > 52 except (Exception, KeyboardInterrupt) as e: > 53 try: > 54 from utility import print\_error\_msg > 55 > 56 print\_error\_msg(e) > 57 except ImportError: > 58 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/example.png) [wlan\_ap\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/system/wlan_ap/wlan_ap_cores3_example.m5f2) Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ network.WLAN(_interface\_id_)[](#network.WLAN "Link to this definition") Create a WLAN network interface object. Supported interfaces are `network.AP_IF` (access point, allows other WiFi clients to connect) > UIFLOW2: > > > ![init.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- WLAN.status(\[_param_\])[](#network.WLAN.status "Link to this definition") Return the current status of the wireless connection. When called with no argument the return value describes the network link status. UIFLOW2: > ![scan.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/scan.png) > > ![scan_get_mac.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/scan_get_mac.png) WLAN.isconnected()[](#network.WLAN.isconnected "Link to this definition") In AP mode returns `True` when a station is connected. Returns `False` otherwise. > ![isconnected.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/isconnected.png) WLAN.active(\[_is\_active_\])[](#network.WLAN.active "Link to this definition") Activate (“up”) or deactivate (“down”) network interface, if boolean argument is passed. Otherwise, query current state if no argument is provided. Most other methods require active interface. > ![active.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/active.png) WLAN.ifconfig(\[_(ip_, _subnet_, _gateway_, _dns)_\])[](#network.WLAN.ifconfig "Link to this definition") Get/set IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. When called with no arguments, this method returns a 4-tuple with the above information. To set the above values, pass a 4-tuple with the required information. > ![get_local_ip.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_local_ip.png) > > ![get_subnet.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_subnet.png) > > ![get_gateway.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_gateway.png) > > ![get_dns.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_dns.png) WLAN.config(_'param'_)[](#network.WLAN.config "Link to this definition") WLAN.config(_param=value_, _..._) Get or set general network interface parameters. These methods allow to work with additional parameters beyond standard IP configuration (as dealt with by AbstractNIC.ipconfig()). These include network-specific and hardware-specific parameters. For setting parameters, keyword argument syntax should be used, multiple parameters can be set at once. For querying, parameters name should be quoted as a string, and only one parameter can be queried at a time: Following are commonly supported parameters (availability of a specific parameter depends on network technology type, driver, and MicroPython port). | Parameter | Description | | --- | --- | | mac | MAC address (bytes) | | ssid | WiFi access point name (string) | | channel | WiFi channel (integer) | | hidden | Whether SSID is hidden (boolean) | | security | Security protocol supported (enumeration, see module constants) | | key | Access key (string) | | hostname | The hostname that will be sent to DHCP (STA interfaces) and mDNS (if supported, both STA and AP). (Deprecated, use [`network.hostname()`](https://docs.micropython.org/en/v1.22.0/library/network.html#network.hostname "(in MicroPython vv1.22.0)")
instead) | | reconnects | Number of reconnect attempts to make (integer, 0=none, -1=unlimited) | | txpower | Maximum transmit power in dBm (integer or float) | | pm | WiFi Power Management setting (see below for allowed values) | > ![set_ssid.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_ssid.png) > > ![set_password.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_password.png) > > ![set_hidden_status.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_hidden_status.png) > > ![set_auth_mode.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_auth_mode.png) > > ![set_channel.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_channel.png) > > ![set_dhcp_hostname.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_dhcp_hostname.png) > > ![set_max_clients.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_max_clients.png) > > ![set_txpower.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/set_txpower.png) > > ![get_ssid.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_ssid.png) > > ![get_password.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_password.png) > > ![get_mac.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_mac.png) > > ![get_hidden_status.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_hidden_status.png) > > ![get_auth_mode.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_auth_mode.png) > > ![get_channel.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_channel.png) > > ![get_dhcp_hostname.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_dhcp_hostname.png) > > ![get_max_clients.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_max_clients.png) > > ![get_txpower.png](https://static-cdn.m5stack.com/mpy_docs/system/wlan_ap/get_txpower.png) Constants[](#constants "Link to this heading") ------------------------------------------------ WLAN.AUTH\_OPEN[](#network.WLAN.AUTH_OPEN "Link to this definition") WLAN.AUTH\_WEP[](#network.WLAN.AUTH_WEP "Link to this definition") WLAN.AUTH\_WPA\_PSK[](#network.WLAN.AUTH_WPA_PSK "Link to this definition") WLAN.AUTH\_WPA2\_PSK[](#network.WLAN.AUTH_WPA2_PSK "Link to this definition") WLAN.AUTH\_WPA\_WPA2\_PSK[](#network.WLAN.AUTH_WPA_WPA2_PSK "Link to this definition") WLAN.AUTH\_WPA2\_ENTERPRISE[](#network.WLAN.AUTH_WPA2_ENTERPRISE "Link to this definition") WLAN.AUTH\_WPA3\_PSK[](#network.WLAN.AUTH_WPA3_PSK "Link to this definition") WLAN.AUTH\_WPA2\_WPA3\_PSK[](#network.WLAN.AUTH_WPA2_WPA3_PSK "Link to this definition") WLAN.AUTH\_WAPI\_PSK[](#network.WLAN.AUTH_WAPI_PSK "Link to this definition") Allowed values for the `WLAN.config(authmode=...)` network interface parameter: > * `AUTH_OPEN`: 0 – open > > * `AUTH_WEP`: 1 – WEP > > * `AUTH_WPA_PSK`: 2 – WPA-PSK > > * `AUTH_WPA2_PSK`: 3 – WPA2-PSK > > * `AUTH_WPA_WPA2_PSK`: 4 – WPA/WPA2-PSK > > * `AUTH_WPA2_ENTERPRISE`: 5 – WPA2-Enterprise > > * `AUTH_WPA3_PSK`: 6 – WPA3-PSK > > * `AUTH_WPA2_WPA3_PSK`: 7 – WPA2/WPA3-PSK > > * `AUTH_WAPI_PSK`: 8 – WAPI-PSK > --- # WDT — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * WDT * [View page source](../_sources/hardware/wdt.rst.txt) * * * WDT[](#wdt "Link to this heading") ==================================== The WDT is used to restart the system when the application crashes and ends up into a non recoverable state. Once started it cannot be stopped or reconfigured in any way. After enabling, the application must “feed” the watchdog periodically to prevent it from expiring and resetting the system. 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 \* > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16wdt \= None > 17 > 18 > 19isTouch \= None > 20 > 21 > 22def setup(): > 23 global title0, label0, label1, label2, label3, wdt, isTouch > 24 > 25 M5.begin() > 26 Widgets.fillScreen(0x222222) > 27 title0 \= Widgets.Title("WDT CoreS3 example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 28 label0 \= Widgets.Label("Touch State:", 2, 92, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label1 \= Widgets.Label("WDT State:", 2, 155, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 label2 \= Widgets.Label( > 31 "pls touch screen to feed the dog", 0, 27, 1.0, 0xFFCF00, 0x222222, Widgets.FONTS.DejaVu18 > 32 ) > 33 label3 \= Widgets.Label("label3", \-117, 96, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 34 > 35 wdt \= WDT(timeout\=2500) > 36 isTouch \= 0 > 37 > 38 > 39def loop(): > 40 global title0, label0, label1, label2, label3, wdt, isTouch > 41 M5.update() > 42 isTouch \= M5.Touch.getCount() > 43 label0.setText(str((str("Touch State:") + str(isTouch)))) > 44 if isTouch: > 45 wdt.feed() > 46 label1.setText(str("WDT State: Feed!")) > 47 else: > 48 label1.setText(str("WDT State: Not Feed! Will crush!")) > 49 > 50 > 51if \_\_name\_\_ \== "\_\_main\_\_": > 52 try: > 53 setup() > 54 while True: > 55 loop() > 56 except (Exception, KeyboardInterrupt) as e: > 57 try: > 58 from utility import print\_error\_msg > 59 > 60 print\_error\_msg(e) > 61 except ImportError: > 62 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/wdt/example.png) [wdt\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/wdt/wdt_cores3_example.m5f2) class WDT – watchdog timer[](#class-wdt-watchdog-timer "Link to this heading") -------------------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ WDT(_id\=0_, _timeout\=5000_)[](#WDT "Link to this definition") Create a WDT object and start it. The timeout must be given in milliseconds. Once it is running the timeout cannot be changed and the WDT cannot be stopped either. Notes: On the esp8266 a timeout cannot be specified, it is determined by the underlying system. On rp2040 devices, the maximum timeout is 8388 ms. > UIFLOW2: > > > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/wdt/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- WDT.feed()[](#WDT.feed "Link to this definition") Feed the WDT to prevent it from resetting the system. The application should place this call in a sensible place ensuring that the WDT is only fed after verifying that everything is functioning correctly. > UIFLOW2: > > > ![feed.png](https://static-cdn.m5stack.com/mpy_docs/hardware/wdt/feed.png) --- # Atom Socket Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atom Socket Base * [View page source](../_sources/base/atom_socket.rst.txt) * * * Atom Socket Base[](#atom-socket-base "Link to this heading") ============================================================== The ATOMSocketBase class is a smart power socket integrated with the M5 ATOM controller. It features a built-in HLW8032 high-precision power measurement IC, enabling it to measure the voltage, current, power, and energy of the load. Additionally, it can function as a smart socket to control the power state of the load, making it suitable for applications in smart homes, industrial control, and energy management. Supports the following products: [![ATOMSocketBase](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_socket/atom_socket_01.webp)](https://docs.m5stack.com/en/atom/atom_socket) 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 base import ATOMSocketBase > 9from hardware import \* > 10 > 11 > 12atomsocket \= None > 13 > 14 > 15as\_voltage \= None > 16as\_current \= None > 17as\_power \= None > 18as\_kwh \= None > 19onoff \= None > 20 > 21 > 22def atom\_socket\_receive\_event(voltage, current, power, kwh): > 23 global atomsocket, as\_voltage, as\_current, as\_power, as\_kwh, onoff > 24 as\_voltage \= voltage > 25 as\_current \= current > 26 as\_power \= power > 27 as\_kwh \= kwh > 28 print("hello M5") > 29 print("hello M5") > 30 > 31 > 32def btnA\_wasClicked\_event(state): \# noqa: N802 > 33 global atomsocket, as\_voltage, as\_current, as\_power, as\_kwh, onoff > 34 onoff \= not onoff > 35 if onoff: > 36 atomsocket.set\_relay(True) > 37 else: > 38 atomsocket.set\_relay(False) > 39 > 40 > 41def setup(): > 42 global atomsocket, as\_voltage, as\_current, as\_power, as\_kwh, onoff > 43 > 44 M5.begin() > 45 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 46 > 47 atomsocket \= ATOMSocketBase(1, port\=(22, 33), relay\=23) > 48 onoff \= False > 49 atomsocket.set\_relay(False) > 50 atomsocket.receive\_none\_block(atom\_socket\_receive\_event) > 51 > 52 > 53def loop(): > 54 global atomsocket, as\_voltage, as\_current, as\_power, as\_kwh, onoff > 55 M5.update() > 56 > 57 > 58if \_\_name\_\_ \== "\_\_main\_\_": > 59 try: > 60 setup() > 61 while True: > 62 loop() > 63 except (Exception, KeyboardInterrupt) as e: > 64 try: > 65 from utility import print\_error\_msg > 66 > 67 print\_error\_msg(e) > 68 except ImportError: > 69 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/example.png) [atomlite\_socket\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/atom_socket/atomlite_socket_example.m5f2) class ATOMSocketBase[](#class-atomsocketbase "Link to this heading") ---------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ATOMSocketBase(_\_id: Literal\[0, 1, 2\]_, _port: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") | [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") _, _relay: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 23_)[](#ATOMSocketBase "Link to this definition") Initializes the ATOM Socket. * `_id`: Serial ID, not actually used by this base. * `port`: UART pin numbers. * `relay`: The relay pin number. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ATOMSocketBase.set\_relay(_state: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ATOMSocketBase.set_relay "Link to this definition") Sets the state of the ATOM Socket’s relay. * `state`: The desired state of the relay, True = ON, False = OFF. UIFLOW2: > ![set_relay.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/set_relay.png) ATOMSocketBase.get\_data(_timeout\=3000_) → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") [](#ATOMSocketBase.get_data "Link to this definition") Retrieves data from the ATOM Socket. * `timeout`: Function timeout period. Returns the ATOM Socket data: Tuple (Voltage (V), Current (A), Power (W), Total Energy (KWh)), or None if timeout occurs. UIFLOW2: > ![get_data.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_data.png) ATOMSocketBase.get\_voltage() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_voltage "Link to this definition") Retrieves the voltage measurement from the ATOM Socket. UIFLOW2: > ![get_voltage.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_voltage.png) ATOMSocketBase.get\_current() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_current "Link to this definition") Retrieves the current measurement from the ATOM Socket. UIFLOW2: > ![get_current.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_current.png) ATOMSocketBase.get\_power() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_power "Link to this definition") Retrieves the power measurement from the ATOM Socket. UIFLOW2: > ![get_power.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_power.png) ATOMSocketBase.get\_pf() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ATOMSocketBase.get_pf "Link to this definition") Retrieves the power factor from the ATOM Socket. UIFLOW2: > ![get_pf.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_pf.png) ATOMSocketBase.get\_inspecting\_power() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_inspecting_power "Link to this definition") Calculates the inspecting power of the ATOM Socket. UIFLOW2: > ![get_inspecting_power.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_inspecting_power.png) ATOMSocketBase.get\_power\_factor() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_power_factor "Link to this definition") Calculates the power factor of the ATOM Socket. UIFLOW2: > ![get_power_factor.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_power_factor.png) ATOMSocketBase.get\_kwh() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#ATOMSocketBase.get_kwh "Link to this definition") Retrieves the accumulated energy measurement in KWh from the ATOM Socket. UIFLOW2: > ![get_kwh.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/get_kwh.png) ATOMSocketBase.stop\_receive\_data() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ATOMSocketBase.stop_receive_data "Link to this definition") Stops receiving data from the ATOM Socket. UIFLOW2: > ![stop_receive_data.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/stop_receive_data.png) ATOMSocketBase.receive\_none\_block(_receive\_callback_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ATOMSocketBase.receive_none_block "Link to this definition") Receives data from the ATOM Socket in non-blocking mode. * `receive_callback`: Callback function to handle the received data. UIFLOW2: > ![receive_none_block.png](https://static-cdn.m5stack.com/mpy_docs/base/atom_socket/receive_none_block.png) --- # UDP — UIFlow2 Programming Guide master documentation * [](../index.html) * [Software](index.html) * UDP * [View page source](../_sources/software/udp.rst.txt) * * * UDP[](#udp "Link to this heading") ==================================== The UDP module provides a simple way to send and receive data over the network using the User Datagram Protocol (UDP). It is designed for low-latency communication and is suitable for applications where speed is more critical than reliability. API[](#api "Link to this heading") ------------------------------------ * [UDP Client](udp.client.html) * [UDP Server](udp.server.html) --- # ADC Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * ADC Unit * [View page source](../_sources/units/adc.rst.txt) * * * ADC Unit[](#adc-unit "Link to this heading") ============================================== Support the following products: > [![ADC](https://static-cdn.m5stack.com/resource/docs/products/unit/adc/adc_01.webp)](https://docs.m5stack.com/en/unit/adc) 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 ADCUnit > 10 > 11 > 12label0 \= None > 13i2c0 \= None > 14adc\_0 \= None > 15 > 16 > 17def setup(): > 18 global label0, i2c0, adc\_0 > 19 > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 label0 \= Widgets.Label("label0", 16, 16, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 23 > 24 i2c0 \= I2C(0, scl\=Pin(22), sda\=Pin(21), freq\=100000) > 25 adc\_0 \= ADCUnit(i2c0) > 26 > 27 > 28def loop(): > 29 global label0, i2c0, adc\_0 > 30 M5.update() > 31 label0.setText(str(adc\_0.get\_voltage())) > 32 > 33 > 34if \_\_name\_\_ \== "\_\_main\_\_": > 35 try: > 36 setup() > 37 while True: > 38 loop() > 39 except (Exception, KeyboardInterrupt) as e: > 40 try: > 41 from utility import print\_error\_msg > 42 > 43 print\_error\_msg(e) > 44 except ImportError: > 45 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/example.png) [adc\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/adc/adc_cores3_example.m5f2) class ADCUnit[](#class-adcunit "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ADCUnit(_i2c0_)[](#ADCUnit "Link to this definition") Create an ADCUnit object. parameters is: * `I2C0` is I2C Port. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ADCUnit.get\_value()[](#ADCUnit.get_value "Link to this definition") Gets the original value read by the adc(16 bit). UIFLOW2: > ![get_value.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/get_value.png) ADCUnit.get\_voltage()[](#ADCUnit.get_voltage "Link to this definition") Get the voltage value. UIFLOW2: > ![get_voltage.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/get_voltage.png) ADCUnit.get\_operating\_mode()[](#ADCUnit.get_operating_mode "Link to this definition") Get working mode. (Single read or continuous read) UIFLOW2: > ![get_operating_mode.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/get_operating_mode.png) ADCUnit.get\_data\_rate()[](#ADCUnit.get_data_rate "Link to this definition") Get the read rate of the data. UIFLOW2: > ![get_data_rate.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/get_data_rate.png) ADCUnit.get\_gain()[](#ADCUnit.get_gain "Link to this definition") Get the gain multiple of the data. UIFLOW2: > ![get_gain.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/get_gain.png) ADCUnit.operating\_mode()[](#ADCUnit.operating_mode "Link to this definition") Set working mode (single read or continuous read) UIFLOW2: > ![set_operating_mode.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/set_operating_mode.png) ADCUnit.data\_rate()[](#ADCUnit.data_rate "Link to this definition") Set the data acquisition rate. UIFLOW2: > ![set_data_rate.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/set_data_rate.png) ADCUnit.gain()[](#ADCUnit.gain "Link to this definition") Set the gain multiple for reading data. UIFLOW2: > ![set_gain.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc/set_gain.png) --- # ACSSR Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * ACSSR Unit * [View page source](../_sources/units/acssr.rst.txt) * * * ACSSR Unit[](#acssr-unit "Link to this heading") ================================================== Support the following products: > [![ACSSR Unit](https://static-cdn.m5stack.com/resource/docs/products/unit/acssr/acssr_01.webp)](https://docs.m5stack.com/en/unit/acssr) Micropython I2C 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 ACSSRUnit > 10 > 11 > 12label0 \= None > 13rect0 \= None > 14label1 \= None > 15title0 \= None > 16label3 \= None > 17i2c0 \= None > 18acssr\_0 \= None > 19 > 20 > 21touch\_x \= None > 22touch\_y \= None > 23x \= None > 24y \= None > 25w \= None > 26h \= None > 27state \= None > 28ret \= None > 29 > 30 > 31\# Describe this function... > 32def is\_touch(touch\_x, touch\_y, x, y, w, h): > 33 global state, ret, label0, rect0, label1, title0, label3, i2c0, acssr\_0 > 34 ret \= False > 35 if touch\_x \>= x and touch\_x <= x + w: > 36 if touch\_y \>= y and touch\_y <= y + h: > 37 ret \= True > 38 return ret > 39 > 40 > 41\# Describe this function... > 42def display\_ui(state): > 43 global touch\_x, touch\_y, x, y, w, h, ret, label0, rect0, label1, title0, label3, i2c0, acssr\_0 > 44 if state: > 45 rect0.setColor(color\=0x00FF00, fill\_c\=0x00FF00) > 46 label3.setColor(0xFFFFFF, 0x00FF00) > 47 label3.setText(str("On")) > 48 acssr\_0.fill\_color(0x00FF00) > 49 else: > 50 rect0.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 51 label3.setColor(0xFFFFFF, 0xFF0000) > 52 label3.setText(str("Off")) > 53 acssr\_0.fill\_color(0xFF0000) > 54 > 55 > 56def setup(): > 57 global \\ > 58 label0, \\ > 59 rect0, \\ > 60 label1, \\ > 61 title0, \\ > 62 label3, \\ > 63 i2c0, \\ > 64 acssr\_0, \\ > 65 ret, \\ > 66 state, \\ > 67 touch\_x, \\ > 68 x, \\ > 69 w, \\ > 70 touch\_y, \\ > 71 y, \\ > 72 h > 73 > 74 M5.begin() > 75 Widgets.fillScreen(0x222222) > 76 label0 \= Widgets.Label("label0", 188, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 77 rect0 \= Widgets.Rectangle(130, 105, 60, 30, 0x00FF00, 0x00FF00) > 78 label1 \= Widgets.Label( > 79 "Firmware Version:", 8, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 80 ) > 81 title0 \= Widgets.Title("ACSSR Unit", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 82 label3 \= Widgets.Label("On", 147, 111, 1.0, 0xFFFFFF, 0x00FF00, Widgets.FONTS.DejaVu18) > 83 > 84 i2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) > 85 print(i2c0.scan()) > 86 acssr\_0 \= ACSSRUnit(i2c0, 0x50) > 87 label0.setText(str(acssr\_0.get\_firmware\_version())) > 88 state \= acssr\_0.value() > 89 display\_ui(state) > 90 > 91 > 92def loop(): > 93 global \\ > 94 label0, \\ > 95 rect0, \\ > 96 label1, \\ > 97 title0, \\ > 98 label3, \\ > 99 i2c0, \\ > 100 acssr\_0, \\ > 101 ret, \\ > 102 state, \\ > 103 touch\_x, \\ > 104 x, \\ > 105 w, \\ > 106 touch\_y, \\ > 107 y, \\ > 108 h > 109 M5.update() > 110 if M5.Touch.getCount(): > 111 if is\_touch( > 112 (M5.Touch.getTouchPointRaw())\[0\], (M5.Touch.getTouchPointRaw())\[1\], 130, 105, 60, 30 > 113 ): > 114 state \= not state > 115 acssr\_0(state) > 116 display\_ui(state) > 117 > 118 > 119if \_\_name\_\_ \== "\_\_main\_\_": > 120 try: > 121 setup() > 122 while True: > 123 loop() > 124 except (Exception, KeyboardInterrupt) as e: > 125 try: > 126 from utility import print\_error\_msg > 127 > 128 print\_error\_msg(e) > 129 except ImportError: > 130 print("please update to latest firmware") Micropython Modbus 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 ACSSRUnit > 10 > 11 > 12label0 \= None > 13rect0 \= None > 14label1 \= None > 15title0 \= None > 16label3 \= None > 17i2c0 \= None > 18acssr\_0 \= None > 19 > 20 > 21touch\_x \= None > 22touch\_y \= None > 23x \= None > 24y \= None > 25w \= None > 26h \= None > 27state \= None > 28ret \= None > 29 > 30 > 31\# Describe this function... > 32def is\_touch(touch\_x, touch\_y, x, y, w, h): > 33 global state, ret, label0, rect0, label1, title0, label3, i2c0, acssr\_0 > 34 ret \= False > 35 if touch\_x \>= x and touch\_x <= x + w: > 36 if touch\_y \>= y and touch\_y <= y + h: > 37 ret \= True > 38 return ret > 39 > 40 > 41\# Describe this function... > 42def display\_ui(state): > 43 global touch\_x, touch\_y, x, y, w, h, ret, label0, rect0, label1, title0, label3, i2c0, acssr\_0 > 44 if state: > 45 rect0.setColor(color\=0x00FF00, fill\_c\=0x00FF00) > 46 label3.setColor(0xFFFFFF, 0x00FF00) > 47 label3.setText(str("On")) > 48 acssr\_0.fill\_color(0x00FF00) > 49 else: > 50 rect0.setColor(color\=0xFF0000, fill\_c\=0xFF0000) > 51 label3.setColor(0xFFFFFF, 0xFF0000) > 52 label3.setText(str("Off")) > 53 acssr\_0.fill\_color(0xFF0000) > 54 > 55 > 56def setup(): > 57 global \\ > 58 label0, \\ > 59 rect0, \\ > 60 label1, \\ > 61 title0, \\ > 62 label3, \\ > 63 i2c0, \\ > 64 acssr\_0, \\ > 65 ret, \\ > 66 state, \\ > 67 touch\_x, \\ > 68 x, \\ > 69 w, \\ > 70 touch\_y, \\ > 71 y, \\ > 72 h > 73 > 74 M5.begin() > 75 Widgets.fillScreen(0x222222) > 76 label0 \= Widgets.Label("label0", 188, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 77 rect0 \= Widgets.Rectangle(130, 105, 60, 30, 0x00FF00, 0x00FF00) > 78 label1 \= Widgets.Label( > 79 "Firmware Version:", 8, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 80 ) > 81 title0 \= Widgets.Title("ACSSR Unit", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 82 label3 \= Widgets.Label("On", 147, 111, 1.0, 0xFFFFFF, 0x00FF00, Widgets.FONTS.DejaVu18) > 83 > 84 i2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) > 85 print(i2c0.scan()) > 86 acssr\_0 \= ACSSRUnit(i2c0, 0x50) > 87 label0.setText(str(acssr\_0.get\_firmware\_version())) > 88 state \= acssr\_0.value() > 89 display\_ui(state) > 90 > 91 > 92def loop(): > 93 global \\ > 94 label0, \\ > 95 rect0, \\ > 96 label1, \\ > 97 title0, \\ > 98 label3, \\ > 99 i2c0, \\ > 100 acssr\_0, \\ > 101 ret, \\ > 102 state, \\ > 103 touch\_x, \\ > 104 x, \\ > 105 w, \\ > 106 touch\_y, \\ > 107 y, \\ > 108 h > 109 M5.update() > 110 if M5.Touch.getCount(): > 111 if is\_touch( > 112 (M5.Touch.getTouchPointRaw())\[0\], (M5.Touch.getTouchPointRaw())\[1\], 130, 105, 60, 30 > 113 ): > 114 state \= not state > 115 acssr\_0(state) > 116 display\_ui(state) > 117 > 118 > 119if \_\_name\_\_ \== "\_\_main\_\_": > 120 try: > 121 setup() > 122 while True: > 123 loop() > 124 except (Exception, KeyboardInterrupt) as e: > 125 try: > 126 from utility import print\_error\_msg > 127 > 128 print\_error\_msg(e) > 129 except ImportError: > 130 print("please update to latest firmware") UIFLOW2 I2C Example: > ![i2c_example.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/i2c_example.png) UIFLOW2 Modbus Example: > ![modbus_example.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/modbus_example.png) [cores3\_acssr\_i2c\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/acssr/cores3_acssr_i2c_example.m5f2) [cores3\_acssr\_modbus\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/acssr/cores3_acssr_modbus_example.m5f2) class ACSSRUnit[](#class-acssrunit "Link to this heading") ------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ACSSRUnit(_bus_, _address\=None_)[](#ACSSRUnit "Link to this definition") Create an ACSSRUnit object. Parameters: * **bus** – I2C bus or Modbus. * **address** – Slave address. Default is 0x50 in I2C mode. Default is 0x04 in Modbus mode. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ACSSRUnit.on() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ACSSRUnit.on "Link to this definition") Turn on the relay. UIFLOW2: > ![on.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/on.png) ACSSRUnit.off() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ACSSRUnit.off "Link to this definition") Turn off the relay. UIFLOW2: > ![off.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/off.png) ACSSRUnit.\_\_call\_\_(\[_x_\])[](#ACSSRUnit.__call__ "Link to this definition") Turn on the relay if x is True, otherwise turn off the relay. Parameters: **x** – True or False. UIFLOW2: > ![call.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_relay.png) ACSSRUnit.value(\[_x_\])[](#ACSSRUnit.value "Link to this definition") Turn on the relay if x is True, otherwise turn off the relay. Parameters: **x** – True or False. UIFLOW2: > ![value.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/value.png) ACSSRUnit.fill\_color(_rgb: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ACSSRUnit.fill_color "Link to this definition") Set the color of the LED. Parameters: **rgb** – RGB color value. Default is 0. UIFLOW2: > ![fill_color.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/fill_color.png) ACSSRUnit.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#ACSSRUnit.get_firmware_version "Link to this definition") Get the firmware version of the unit. Returns: Firmware version. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/get_firmware_version.png) ACSSRUnit.set\_address(_new\_address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#ACSSRUnit.set_address "Link to this definition") Set the I2C address of the unit. Parameters: **new\_address** – New I2C address. The range is 0x01-0x7f. UIFLOW2: > ![set_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_address.png) > > ![set_address1.png](https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_address1.png) --- # Atom DTU LoRaWAN-Series Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atom DTU LoRaWAN-Series Base * [View page source](../_sources/base/dtu_lorawan.rst.txt) * * * Atom DTU LoRaWAN-Series Base[](#atom-dtu-lorawan-series-base "Link to this heading") ====================================================================================== This is the driver library for the Atom DTU LoRaWAN-Series Base to accept and send data from the LoRaWAN module. Support the following products: > | | | | > | --- | --- | --- | > | [![Atom DTU LoRaWAN470](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_dtu_lorawan470/atom_dtu_lorawan470_01.webp)](https://docs.m5stack.com/en/atom/atom_dtu_lorawan470) | [![Atom DTU LoRaWAN868](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_dtu_lorawan868/atom_dtu_lorawan868_01.webp)](https://docs.m5stack.com/en/atom/atom_dtu_lorawan868) | [![Atom DTU LoRaWAN915](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_dtu_lorawan915/atom_dtu_lorawan915_01.webp)](https://docs.m5stack.com/en/atom/atom_dtu_lorawan915) | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### LoRaWAN communication[](#lorawan-communication "Link to this heading") Open the [atoms3r\_dtu\_lorawan\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/dtu_lorawan/atoms3r_dtu_lorawan_example.m5f2) project in UiFlow2. This example shows how to receive and send data using the Atom DTU LoRaWAN Base. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### LoRaWAN communication[](#id1 "Link to this heading") This example shows how to receive and send data using the Atom DTU LoRaWAN Base. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import AtomDTULoRaWANBase > 9 > 10 > 11title0 \= None > 12base\_lorawan470 \= None > 13 > 14 > 15def setup(): > 16 global title0, base\_lorawan470 > 17 > 18 M5.begin() > 19 title0 \= Widgets.Title("LoRaWAN", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 20 > 21 base\_lorawan470 \= AtomDTULoRaWANBase(2, port\=(5, 6)) > 22 base\_lorawan470.set\_join\_mode(0) > 23 base\_lorawan470.config\_otaa("xxxx", "xxxx", "xxxx") > 24 base\_lorawan470.set\_frequency\_band\_mask("0400") > 25 base\_lorawan470.set\_rx\_window\_param(0, 0, 505300000) > 26 base\_lorawan470.set\_class\_mode(2) > 27 base\_lorawan470.set\_uplink\_downlink\_mode(1) > 28 base\_lorawan470.set\_uplink\_app\_port(1) > 29 base\_lorawan470.join(1, 1, 20, 20) > 30 print("LoRaWAN configuration complete") > 31 > 32 > 33def loop(): > 34 global title0, base\_lorawan470 > 35 M5.update() > 36 if BtnA.isPressed(): > 37 print("Send Message") > 38 base\_lorawan470.send\_data("11", 1, 15) > 39 > 40 > 41if \_\_name\_\_ \== "\_\_main\_\_": > 42 try: > 43 setup() > 44 while True: > 45 loop() > 46 except (Exception, KeyboardInterrupt) as e: > 47 try: > 48 from utility import print\_error\_msg > 49 > 50 print\_error\_msg(e) > 51 except ImportError: > 52 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### AtomDTULoRaWANBase[](#atomdtulorawanbase "Link to this heading") _class_ base.dtu\_lorawan.AtomDTULoRaWANBase(_id\=1_, _port\=None_)[](#base.dtu_lorawan.AtomDTULoRaWANBase "Link to this definition") Bases: [`LoRaWAN_470`](#driver.asr650x.LoRaWAN_470 "driver.asr650x.LoRaWAN_470") Create an AtomDTULoRaWANBase object Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART ID to use (0, 1, or 2). Default is 2. * **port** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_ [_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – A list or tuple containing the TX and RX pin numbers. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/init.png) MicroPython Code Block: > from base import AtomDTULoRaWANBase > > dtu\_lorawan \= AtomDTULoRaWANBase(0, (6, 5)) _class_ driver.asr650x.LoRaWAN\_470(_uart_, _debug\=False_)[](#driver.asr650x.LoRaWAN_470 "Link to this definition") Bases: [`LoRaWAN_Asr650x`](#driver.asr650x.LoRaWAN_Asr650x "driver.asr650x.LoRaWAN_Asr650x") Create an LoRaWAN object. Parameters: * **tx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART TX pin number. * **rx** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART RX pin number. * **debug** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to enable debug mode. MicroPython Code Block: > from driver.asr650x import LoRaWAN\_470 > > lora \= LoRaWAN\_470(tx\=17, rx\=16) check\_downlink\_data(_timeout\=10_)[](#driver.asr650x.LoRaWAN_470.check_downlink_data "Link to this definition") Check downlink data, if have downlink data, return the message. Parameters: **timeout** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The timeout time. Returns: False if no downlink data, otherwise return the downlink data. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") | [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![check_downlink_data.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/check_downlink_data.png) MicroPython Code Block: > lora.check\_downlink\_data() check\_join\_status()[](#driver.asr650x.LoRaWAN_470.check_join_status "Link to this definition") Check the LoRaWAN network join status. Returns: The LoRaWAN network join status. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![check_join_status.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/check_join_status.png) MicroPython Code Block: > lora.check\_join\_status() check\_uplink\_status()[](#driver.asr650x.LoRaWAN_470.check_uplink_status "Link to this definition") Check the data uplink status. Returns: The data uplink status. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![check_uplink_status.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/check_uplink_status.png) MicroPython Code Block: > lora.check\_uplink\_status() config\_abp(_devaddr_, _appskey_, _nwkskey_)[](#driver.asr650x.LoRaWAN_470.config_abp "Link to this definition") Config the ABP join mode information. Parameters: * **devaddr** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The device address. * **appskey** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The application session key. * **nwkskey** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The network session key. UiFlow2 Code Block: > ![config_abp.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/config_abp.png) MicroPython Code Block: > lora.config\_abp("0037CAE1FC3542B9", "70B3D57ED003B699", "67FA4ED1075A20573BCDD7594C458698") config\_otaa(_deveui_, _appeui_, _appkey_)[](#driver.asr650x.LoRaWAN_470.config_otaa "Link to this definition") Config the OTAA join mode information. Parameters: * **deveui** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The device EUI. * **appeui** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The application EUI. * **appkey** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The application key. UiFlow2 Code Block: > ![config_otaa.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/config_otaa.png) MicroPython Code Block: > lora.config\_otaa("0037CAE1FC3542B9", "70B3D57ED003B699", "67FA4ED1075A20573BCDD7594C458698") get\_abp\_config()[](#driver.asr650x.LoRaWAN_470.get_abp_config "Link to this definition") Get the ABP join mode information. Returns: The ABP join mode information(devaddr, appskey, newskey). Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") UiFlow2 Code Block: > ![get_abp_config.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/get_abp_config.png) MicroPython Code Block: > lora.get\_abp\_config() get\_otaa\_config()[](#driver.asr650x.LoRaWAN_470.get_otaa_config "Link to this definition") Get the OTAA join mode information. Returns: The OTAA join mode information(deveui, appeui, appkey). Return type: [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") UiFlow2 Code Block: > ![get_otaa_config.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/get_otaa_config.png) MicroPython Code Block: > lora.get\_otaa\_config() _class_ driver.asr650x.LoRaWAN\_Asr650x(_uart_, _debug\=False_)[](#driver.asr650x.LoRaWAN_Asr650x "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an LoRaWAN object. Parameters: * **uart** ([_machine.UART_](https://docs.micropython.org/en/v1.22.0/library/machine.UART.html#machine.UART "(in MicroPython vv1.22.0)") ) – The UART object. * **debug** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to enable debug mode. MicroPython Code Block: > from driver.asr650x import LoRaWAN\_Asr650x > > lora \= LoRaWAN\_Asr650x(uart) set\_join\_mode(_mode_)[](#driver.asr650x.LoRaWAN_Asr650x.set_join_mode "Link to this definition") Set the LoRaWAN join mode. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The LoRaWAN join mode. UiFlow2 Code Block: > ![set_join_mode.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/set_join_mode.png) MicroPython Code Block: > lora.set\_join\_mode(0) set\_frequency\_band\_mask(_mask_)[](#driver.asr650x.LoRaWAN_Asr650x.set_frequency_band_mask "Link to this definition") Set the frequency band mask. Parameters: **mask** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The frequency band mask. MicroPython Code Block: > lora.set\_frequency\_band\_mask("0001") set\_uplink\_downlink\_mode(_mode_)[](#driver.asr650x.LoRaWAN_Asr650x.set_uplink_downlink_mode "Link to this definition") Set the uplink and downlink frequency. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The uplink and downlink frequency. MicroPython Code Block: > lora.set\_uplink\_downlink\_mode(1) set\_class\_mode(_class\_mode_, _branch\=None_, _para1\=None_, _para2\=None_, _para3\=None_, _para4\=None_)[](#driver.asr650x.LoRaWAN_Asr650x.set_class_mode "Link to this definition") Set the class mode, if the class mode is 0, the branch, para1, para2, para3, para4 will be ignored. Parameters: * **class\_mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The class mode. * **branch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The branch selection. * **para1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Set the beacon frequency, unit is Hz. * **para2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Set the beacon data rate. * **para3** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Set ping frequency, unit is Hz. * **para4** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Set ping data rate. MicroPython Code Block: > lora.set\_class\_mode(0, 0, 0, 0, 0, 0) join(_para1_, _para2\=None_, _para3\=None_, _para4\=None_)[](#driver.asr650x.LoRaWAN_Asr650x.join "Link to this definition") Join the LoRaWAN network. Parameters: * **para1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – 0 stop join, 1 start join. * **para2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – 0 close auto join, 1 open auto join. * **para3** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – join interval, unit is second(7~255). * **para4** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – join retry times(1~256). UiFlow2 Code Block: > ![join.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/start_join.png) > > ![join_stop.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/stop_join.png) MicroPython Code Block: > lora.join(1, 1, 8, 1) > > lora.join(0) send\_data(_payload_, _confirm\=None_, _nbtrials\=None_)[](#driver.asr650x.LoRaWAN_Asr650x.send_data "Link to this definition") Send data payload to LoRaWAN gateway. Parameters: * **payload** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – The data to send. * **confirm** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The confirm mode. * **nbtrials** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of trials. UiFlow2 Code Block: > ![send_data.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/send_data.png) MicroPython Code Block: > lora.send\_data("Hello, World!", 1, 1) set\_uplink\_app\_port(_port_)[](#driver.asr650x.LoRaWAN_Asr650x.set_uplink_app_port "Link to this definition") Set the uplink app port. Parameters: **port** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The uplink app port. UiFlow2 Code Block: > ![set_uplink_app_port.png](https://static-cdn.m5stack.com/mpy_docs/base/lorawan470/set_uplink_app_port.png) MicroPython Code Block: > lora.set\_uplink\_app\_port(1) set\_rx\_window\_param(_rx1\_offset_, _rx2\_dr_, _rx2\_freq_)[](#driver.asr650x.LoRaWAN_Asr650x.set_rx_window_param "Link to this definition") Set the receive window parameter. Parameters: * **rx1\_offset** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RX1 offset. * **rx2\_dr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RX2 data rate. * **rx2\_freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RX2 frequency. MicroPython Code Block: > lora.set\_rx\_window\_param(0, 0, 868100000) --- # Display — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * Display * [View page source](../_sources/hardware/display.rst.txt) * * * Display[](#display "Link to this heading") ============================================ A lcd display library Micropython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### draw test[](#draw-test "Link to this heading") import M5 from M5 import Display import random import time M5.begin() print("rotation: ", Display.getRotation()) print("color depth: ", Display.getColorDepth()) print("w: %d, h: %d"%(Display.width(), Display.height())) Display.setRotation(1) Display.clear(0) Display.setTextColor(fgcolor\=0x0000FF, bgcolor\=0) Display.setFont(M5.Lcd.FONTS.EFontCN24) Display.setCursor(220, 3) Display.print("你好",color\=0xFF0000) Display.drawImage("res/img/uiflow.jpg", 0, 0) Display.drawJpg("res/img/default.jpg", 60, 0) Display.drawQR("Hello", 220, 40, 100) Display.drawCircle(30, 80, 20, 0x0000FF) Display.fillCircle(80, 80, 20, 0x0000FF) Display.drawEllipse(60, 140, 50, 30, 0x00FF00) Display.fillEllipse(60, 140, 30, 20, 0xFFFF00) Display.drawLine(x0\=115, y0\=10, x1\=115, y1\=60, color\=0xFF0000) Display.drawRect(125, 10, 40, 30, 0xFF0000) Display.fillRect(125, 50, 40, 30, 0x00FF00) Display.drawRoundRect(120, 90, 50, 40, 10, 0xFF0000) Display.fillRoundRect(125, 95, 40, 30, 10, 0x00FF00) Display.drawTriangle(135, 150, 110, 190, 160, 190, 0x00FF00) Display.fillTriangle(145, 150, 170, 190, 190, 150, 0x0000FF) Display.drawArc(10, 180, 40, 45, 0, 90, 0xFFFF00) Display.fillArc(20, 190, 40, 45, 0, 90, 0x00FFFF) Display.drawEllipseArc(200, 150, 30, 35, 20, 25, 0, 90, 0x00FF0F) Display.fillEllipseArc(200, 170, 30, 35, 20, 25, 0, 90, 0x00FFF0) Functions[](#functions "Link to this heading") ------------------------------------------------ Display.width() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Display.Display.width "Link to this definition") Get the horizontal resolution of the display. Returns An integer representing the horizontal resolution (width) in pixels. Display.height() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Display.Display.height "Link to this definition") Get the vertical resolution of the display. Returns An integer representing the vertical resolution (height) in pixels. Display.getRotation() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Display.Display.getRotation "Link to this definition") Get the current rotation of the display. Returns An integer representing the display’s rotation: * `1`: 0° rotation * `2`: 90° rotation * `3`: 180° rotation * `4`: 270° rotation Display.getColorDepth() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Display.Display.getColorDepth "Link to this definition") Get the color depth of the display. Returns An integer representing the display’s color depth in bits. Display.setRotation(_r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_)[](#Display.Display.setRotation "Link to this definition") Set the rotation of the display. The `r` parameter only accepts the following values: * `1`: 0° rotation * `2`: 90° rotation * `3`: 180° rotation * `4`: 270° rotation Display.setColorDepth(_bpp: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 1_)[](#Display.Display.setColorDepth "Link to this definition") Set the color depth of the display. * `bpp` The desired color depth in bits per pixel. Notes: For CoreS3 devices, the color depth is fixed at 16 bits, and this method has no effect. Display.setFont(_font_)[](#Display.Display.setFont "Link to this definition") Set the font for the display. The `font` parameter only accepts the following values: * M5.Lcd.FONTS.ASCII7 * M5.Lcd.FONTS.DejaVu9 * M5.Lcd.FONTS.DejaVu12 * M5.Lcd.FONTS.DejaVu18 * M5.Lcd.FONTS.DejaVu24 * M5.Lcd.FONTS.DejaVu40 * M5.Lcd.FONTS.DejaVu56 * M5.Lcd.FONTS.DejaVu72 * M5.Lcd.FONTS.EFontCN24 * M5.Lcd.FONTS.EFontJA24 * M5.Lcd.FONTS.EFontKR24 Display.setTextColor(_fgcolor: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _bgcolor: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.setTextColor "Link to this definition") Set the text color and background color. * `fgcolor` The text color in RGB888 format. Default is 0 (black). * `bgcolor` The background color in RGB888 format. Default is 0 (black). Display.setTextScroll(_scroll: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= False_)[](#Display.Display.setTextScroll "Link to this definition") Enable or disable text scrolling. * `scroll` Set to True to enable text scrolling, or False to disable it. Default is False. Display.setTextSize(_size_)[](#Display.Display.setTextSize "Link to this definition") Set the size of the text. * `size` The desired text size. Display.setCursor(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.setCursor "Link to this definition") Set the cursor position. * `x` The horizontal position of the cursor. Default is 0. * `y` The vertical position of the cursor. Default is 0. Display.clear(_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.clear "Link to this definition") Clear the display with a specific color. * `color` The fill color in RGB888 format. Default is 0. Display.fillScreen(_color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillScreen "Link to this definition") Fill the entire screen with a specified color. * `color` The fill color in RGB888 format. Default is 0. Display.drawPixel(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawPixel "Link to this definition") Draw a single pixel on the screen. * `x` The horizontal coordinate of the pixel. Default is -1. * `y` The vertical coordinate of the pixel. Default is -1. * `color` The color of the pixel in RGB888 format. Default is 0. Display.drawCircle(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawCircle "Link to this definition") Draw an outline of a circle. * `x` The x-coordinate of the circle center. Default is -1. * `y` The y-coordinate of the circle center. Default is -1. * `r` The radius of the circle. Default is -1. * `color` The color of the circle in RGB888 format. Default is 0. Display.fillCircle(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillCircle "Link to this definition") Draw a filled circle. * `x` The x-coordinate of the circle center. Default is -1. * `y` The y-coordinate of the circle center. Default is -1. * `r` The radius of the circle. Default is -1. * `color` The fill color in RGB888 format. Default is 0. Display.drawEllipse(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _rx: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _ry: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawEllipse "Link to this definition") Draw an outline of an ellipse. * `x` The x-coordinate of the ellipse center. Default is -1. * `y` The y-coordinate of the ellipse center. Default is -1. * `rx` The horizontal radius of the ellipse. Default is -1. * `ry` The vertical radius of the ellipse. Default is -1. * `color` The color of the ellipse in RGB888 format. Default is 0. Display.fillEllipse(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _rx: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _ry: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillEllipse "Link to this definition") Draw a filled ellipse. * `x` The x-coordinate of the ellipse center. Default is -1. * `y` The y-coordinate of the ellipse center. Default is -1. * `rx` The horizontal radius of the ellipse. Default is -1. * `ry` The vertical radius of the ellipse. Default is -1. * `color` The fill color in RGB888 format. Default is 0. Display.drawLine(_x0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _x1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawLine "Link to this definition") Draw a line. * `x0, y0` Starting point coordinates of the line. Default is -1. * `x1, y1` Ending point coordinates of the line. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.drawRect(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawRect "Link to this definition") Draw a rectangle. * `x, y` Top-left corner coordinates of the rectangle. Default is -1. * `w, h` Width and height of the rectangle. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.fillRect(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillRect "Link to this definition") Draw a filled rectangle. * `x, y` Top-left corner coordinates of the rectangle. Default is -1. * `w, h` Width and height of the rectangle. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.drawRoundRect(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawRoundRect "Link to this definition") Draw a rounded rectangle. * `x, y` Top-left corner coordinates of the rectangle. Default is -1. * `w, h` Width and height of the rectangle. Default is -1. * `r` Radius of the corners. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.fillRoundRect(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillRoundRect "Link to this definition") Draw a filled rounded rectangle. * `x, y` Top-left corner coordinates of the rectangle. Default is -1. * `w, h` Width and height of the rectangle. Default is -1. * `r` Radius of the corners. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.drawTriangle(_x0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _x1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _x2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawTriangle "Link to this definition") Draw a triangle. * `x0, y0` Coordinates of the first vertex. Default is -1. * `x1, y1` Coordinates of the second vertex. Default is -1. * `x2, y2` Coordinates of the third vertex. Default is -1. * `color` Color in RGB888 format. Default is 0. Display.fillTriangle(_x0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _x1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _x2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y2: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillTriangle "Link to this definition") Draw a filled triangle. * `x0, y0` Coordinates of the first vertex. Default is -1. * `x1, y1` Coordinates of the second vertex. Default is -1. * `x2, y2` Coordinates of the third vertex. Default is -1. * `color:` Color in RGB888 format. Default is 0. Display.drawArc(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawArc "Link to this definition") Draw an arc. * `x, y` Center coordinates of the arc. Default is -1. * `r0` Inner radius of the arc. Default is -1. * `r1` Outer radius of the arc. Default is -1. * `angle0` Starting angle of the arc (in degrees). Default is -1. * `angle1` Ending angle of the arc (in degrees). Default is -1. * `color` Color in RGB888 format. Default is 0. Display.fillArc(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillArc "Link to this definition") Draw a filled arc. * `x, y` Center coordinates of the arc. Default is -1. * `r0` Inner radius of the arc. Default is -1. * `r1` Outer radius of the arc. Default is -1. * `angle0` Starting angle of the arc (in degrees). Default is -1. * `angle1` Ending angle of the arc (in degrees). Default is -1. * `color` Color in RGB888 format. Default is 0. Display.drawEllipseArc(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawEllipseArc "Link to this definition") Draw an elliptical arc. * `x, y` Center coordinates of the elliptical arc. Default is -1. * `r0x, r0y` Radii of the inner ellipse (horizontal and vertical). Default is -1. * `r1x, r1y` Radii of the outer ellipse (horizontal and vertical). Default is -1. * `angle0` Starting angle of the arc (in degrees). Default is -1. * `angle1` Ending angle of the arc (in degrees). Default is 0. * `color` Color in RGB888 format. Default is 0. Display.fillEllipseArc(_x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r0y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _r1y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle0: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _angle1: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.fillEllipseArc "Link to this definition") Draw a filled elliptical arc. * `x, y` Center coordinates of the elliptical arc. Default is -1. * `r0x, r0y` Radii of the inner ellipse (horizontal and vertical). Default is -1. * `r1x, r1y` Radii of the outer ellipse (horizontal and vertical). Default is -1. * `angle0` Starting angle of the arc (in degrees). Default is -1. * `angle1` Ending angle of the arc (in degrees). Default is -1. * `color:` Color in RGB888 format. Default is 0. Display.drawQR(_text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") \= None_, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _version: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 1_)[](#Display.Display.drawQR "Link to this definition") Draw a QR code. * `text` QR code content. * `x, y` Starting coordinates for displaying the QR code. * `w:` Width of the QR code. Default is 0. * `version` QR code version. Default is 1. **Example**: Generate and display a QR code with the content “hello”: Display.drawQR("Hello", 0, 0, 200) Display.drawPng(_img: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxW: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxH: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offX: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offY: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _scaleX\=True_, _scaleY\=False_)[](#Display.Display.drawPng "Link to this definition") Draw a PNG image. * `img` Image file path or opened image data. * `x, y` Starting coordinates on the display screen. * `maxW, maxH` Width and height to be drawn. Draws the full image if ≤0. * `offX, offY` Offset in the image to start from. * `scaleX, scaleY` Whether to scale the image horizontally or vertically. **Examples**: Display a PNG image from a specified path: Display.drawPng("res/img/uiflow.png", 0, 0) Display a PNG image from read data: img \= open("res/img/uiflow.png", "b") img.seek(0) Display.drawPng(img.read(), 0, 100) img.close() Display.drawJpg(_img_, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxW: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxH: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offX: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offY: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawJpg "Link to this definition") Draw a JPG image. * `img` Image file path or opened image data. * `x, y` Starting coordinates on the display screen. * `maxW, maxH` Width and height to be drawn. Draws the full image if ≤0. * `offX, offY` Offset in the image to start from. Display.drawBmp(_img: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxW: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxH: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offX: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offY: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawBmp "Link to this definition") Draw a BMP image. * `img` Image file path or opened image data. * `x, y` Starting coordinates on the display screen. * `maxW, maxH` Width and height to be drawn. Draws the full image if ≤0. * `offX, offY` Offset in the image to start from. Display.drawImage(_img: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") _, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxW: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _maxH: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offX: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _offY: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.drawImage "Link to this definition") Draw an image. * `img` Image file path or opened image data. * `x, y` Starting coordinates on the display screen. * `maxW, maxH` Width and height to be drawn. Draws the full image if ≤0. * `offX, offY` Offset in the image to start from. **Example**: Draw an image from the buffer: img \= open(img\_path) img.seek(0) drawImage(img.read()) Display.drawRawBuf(_buf_, _x: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _y: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _len: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _swap: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= False_)[](#Display.Display.drawRawBuf "Link to this definition") Draw an image from raw buffer data. * `buf` Image buffer. * `x, y` Starting coordinates on the display screen. * `w, h` Width and height of the image. * `len` Length of the image data. * `swap` Whether to enable inverted display. Display.print(_text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") \= None_, _color: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_)[](#Display.Display.print "Link to this definition") Display a string (no formatting support). * `text` Text to display. * `color` Color in RGB888 format. Default is 0. Display.printf(_text: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") \= None_)[](#Display.Display.printf "Link to this definition") Display a formatted string. * `text` Text to display with formatting. Display.newCanvas(_w: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _h: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0_, _bpp: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _psram: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") \= False_)[](#Display.Display.newCanvas "Link to this definition") Create a canvas. * `w, h` Width and height of the canvas. * `bpp` Color depth. Default is -1. * `psram` Whether to use PSRAM. Default is False. Returns Created canvas object. **Example**: w1 \= Display.newCanvas(w\=100, h\=100, bpp\=16) w1.drawImage("res/img/uiflow.jpg", 80, 0) w1.push(30, 0) Display.startWrite()[](#Display.Display.startWrite "Link to this definition") Start writing to the display. Display.endWrite()[](#Display.Display.endWrite "Link to this definition") End writing to the display. --- # Get Started — UIFlow2 Programming Guide master documentation * [](../index.html) * [Quick Reference](index.html) * Get Started * [View page source](../_sources/quick-reference/get-started.rst.txt) * * * Get Started[](#get-started "Link to this heading") ==================================================== Preparation[](#preparation "Link to this heading") ---------------------------------------------------- ### Driver Installation[](#driver-installation "Link to this heading") Click the link below to download the driver that matches the operating system. There are currently two driver chip versions (CP210X/CH9102). Please download the corresponding driver compressed package according to the version you are using. After decompressing the compressed package, select the installation package corresponding to the number of operating systems to install. If you are not sure of the USB chip used by your device, you can install both drivers at the same time. Warning During the installation process of CH9102\_VCP\_SER\_MacOS v1.7, an error may occur, but the installation is actually completed, just ignore it. | Driver name | Applicable driver chip | Download link | | --- | --- | --- | | CP210x\_VCP\_Windows | CP2104 | [CP210x\_VCP\_Windows](https://static-cdn.m5stack.com/resource/drivers/CP210x_VCP_Windows.zip) | | CP210x\_VCP\_MacOS | CP2104 | [CP210x\_VCP\_MacOS](https://static-cdn.m5stack.com/resource/drivers/CP210x_VCP_MacOS.zip) | | CP210x\_VCP\_Linux | CP2104 | [CP210x\_VCP\_Linux](https://static-cdn.m5stack.com/resource/drivers/CP210x_VCP_Linux.zip) | | CH9102\_VCP\_SER\_Windows | CH9102 | [CH9102\_VCP\_SER\_Windows](https://static-cdn.m5stack.com/resource/drivers/CH9102_VCP_SER_Windows.exe) | | CH9102\_VCP\_SER\_MacOS v1.7 | CH9102 | [CH9102\_VCP\_MacOS\_v1.7](https://static-cdn.m5stack.com/resource/drivers/CH9102_VCP_MacOS_v1.7.zip) | ### M5Burner[](#m5burner "Link to this heading") Please click the button below to download the corresponding M5Burner firmware burning tool according to your operating system. Open the application after decompression. | Software | Link | | --- | --- | | M5Burner\_Windows | [M5Burner-v3-beta-win-x64](https://m5burner.m5stack.com/app/M5Burner-v3-beta-win-x64.zip) | | M5Burner\_MacOS | [M5Burner-v3-beta-mac-x64](https://m5burner.m5stack.com/app/M5Burner-v3-beta-mac-x64.zip) | | M5Burner\_Linux | [M5Burner-v3-beta-linux-x64](https://m5burner.m5stack.com/app/M5Burner-v3-beta-linux-x64.zip) | Installation UIFLOW2[](#installation-uiflow2 "Link to this heading") ---------------------------------------------------------------------- ### Login M5Burner[](#login-m5burner "Link to this heading") Before using UIFlow2, you need to log in to your M5Stack account first. If you don’t have an account yet, please register an account first. ![login-m5burner.gif](../_images/login-m5burner.gif) ### Firmware Burning[](#firmware-burning "Link to this heading") Before burning firmware, first put the host into download mode. Each device has different ways of entering download mode. For details, please refer to the corresponding host product documentation. Before burning, M5Burner will bind your host and M5Stack account. After binding, you can use your host in UIFlow2. ![burn-firmware.gif](../_images/burn-firmware.gif) Start using UIFLOW2[](#start-using-uiflow2 "Link to this heading") -------------------------------------------------------------------- ### Login UIFlow2[](#login-uiflow2 "Link to this heading") Log in to [https://uiflow2.m5stack.com/](https://uiflow2.m5stack.com/) ![login-uiflow2.gif](../_images/login-uiflow2.gif) --- # IMU — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * IMU * [View page source](../_sources/hardware/imu.rst.txt) * * * IMU[](#imu "Link to this heading") ==================================== IMU is used to control the built-in accelerometer and gyroscope inside the host device. Below is the detailed IMU support for the host: | | MPU6886 | BMI270 | BMM150 | | --- | --- | --- | --- | | AtomS3 | ✔ | | | | AtomS3 Lite | | | | | AtomS3U | | | | | StampS3 | | | | | CoreS3 | | ✔ | ✔ | | Core2 | ✔ | | | | TOUGH | | | | | StickC Plus | ✔ | | | | StickC Plus2 | ✔ | | | 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 \* > 8 > 9 > 10title0 \= None > 11label2 \= None > 12label0 \= None > 13label3 \= None > 14label1 \= None > 15label4 \= None > 16label5 \= None > 17 > 18 > 19def setup(): > 20 global title0, label2, label0, label3, label1, label4, label5 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title("IMU CoreS3 example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 label2 \= Widgets.Label("Acc\_z:", 1, 98, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 label0 \= Widgets.Label("Acc\_x:", 1, 32, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 label3 \= Widgets.Label("Gyro\_x:", 1, 135, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 28 label1 \= Widgets.Label("Acc\_y:", 1, 66, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 29 label4 \= Widgets.Label("Gyro\_y:", 1, 168, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 30 label5 \= Widgets.Label("Gyro\_z:", 1, 198, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 31 > 32 > 33def loop(): > 34 global title0, label2, label0, label3, label1, label4, label5 > 35 M5.update() > 36 label0.setText(str((str("Acc\_x:") + str(((Imu.getAccel())\[0\]))))) > 37 label1.setText(str((str("Acc\_y:") + str(((Imu.getAccel())\[1\]))))) > 38 label2.setText(str((str("Acc\_z:") + str(((Imu.getAccel())\[2\]))))) > 39 label3.setText(str((str("Gyro\_x:") + str(((Imu.getGyro())\[0\]))))) > 40 label4.setText(str((str("Gyro\_y:") + str(((Imu.getGyro())\[1\]))))) > 41 label5.setText(str((str("Gyro\_z:") + str(((Imu.getGyro())\[2\]))))) > 42 > 43 > 44if \_\_name\_\_ \== "\_\_main\_\_": > 45 try: > 46 setup() > 47 while True: > 48 loop() > 49 except (Exception, KeyboardInterrupt) as e: > 50 try: > 51 from utility import print\_error\_msg > 52 > 53 print\_error\_msg(e) > 54 except ImportError: > 55 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/example.png) [imu\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/imu/imu_cores3_example.m5f2) class IMU[](#class-imu "Link to this heading") ------------------------------------------------ Important Methods of the IMU Class heavily rely on `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg) and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg). All calls to methods of IMU objects should be placed after `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg), and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg) should be called in the main loop. Methods[](#methods "Link to this heading") -------------------------------------------- IMU.getAccel() → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \][](#IMU.getAccel "Link to this definition") Get the tuple of x, y, and z values of the accelerometer. UIFLOW2: > ![getAccel.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getAccel.png) > > ![getAccel2.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getAccel2.png) > > ![getAccel3.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getAccel3.png) IMU.getGyro() → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \][](#IMU.getGyro "Link to this definition") Get the tuple of x, y, and z values of the gyroscope. UIFLOW2: > ![getGyro.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getGyro.png) > > ![getGyro2.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getGyro2.png) > > ![getGyro3.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getGyro3.png) IMU.getMag() → [tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") \[[float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ , [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")\ \][](#IMU.getMag "Link to this definition") Get the tuple of x, y, and z values of the magnetometer. UIFLOW2: > ![getMag.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getMag.png) > > ![getMag2.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getMag2.png) > > ![getMag3.png](https://static-cdn.m5stack.com/mpy_docs/hardware/imu/getMag3.png) class IMU\_TYPE[](#class-imu-type "Link to this heading") ----------------------------------------------------------- Constants[](#constants "Link to this heading") ------------------------------------------------ IMU\_TYPE.NULL_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.NULL "Link to this definition") IMU\_TYPE.UNKNOWN_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.UNKNOWN "Link to this definition") IMU\_TYPE.SH200Q_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.SH200Q "Link to this definition") IMU\_TYPE.MPU6050_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.MPU6050 "Link to this definition") IMU\_TYPE.MPU6886_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.MPU6886 "Link to this definition") IMU\_TYPE.MPU9250_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.MPU9250 "Link to this definition") IMU\_TYPE.BMI270_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#IMU_TYPE.BMI270 "Link to this definition") The model of the IMU. --- # Atomic CAN Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic CAN Base * [View page source](../_sources/base/atom_can.rst.txt) * * * Atomic CAN Base[](#atomic-can-base "Link to this heading") ============================================================ This is the driver library for the ATOM CAN Base to accept and send data from the CAN module. Support the following products: > | | | > | --- | --- | > | [![Atom CAN](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_can/atom_can_01.webp)](https://docs.m5stack.com/en/atom/atom_can) | [![Atomic CAN Base](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20CAN%20Base/img-8c8eb3c4-9657-4330-9e1a-a0f5f3290197.webp)](https://docs.m5stack.com/en/atom/Atomic%20CAN%20Base) | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### CAN communication[](#can-communication "Link to this heading") Open the [atoms3\_can\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/can/atoms3_can_example.m5f2) project in UiFlow2. This example shows how to receive and send data using the Atom CAN Base. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/can/example.png) Example output: > Output of received CAN message data via serial port. MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### CAN communication[](#id1 "Link to this heading") This example shows how to receive and send data using the Atom CAN Base. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import ATOMCANBase > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15base\_can \= None > 16 > 17 > 18def setup(): > 19 global title0, label0, label1, base\_can > 20 > 21 M5.begin() > 22 title0 \= Widgets.Title("CAN Base", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 23 label0 \= Widgets.Label("TX:", 1, 38, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 24 label1 \= Widgets.Label("RX:", 1, 68, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 25 > 26 base\_can \= ATOMCANBase(0, (6, 5), ATOMCANBase.NORMAL, baudrate\=1000000) > 27 > 28 > 29def loop(): > 30 global title0, label0, label1, base\_can > 31 M5.update() > 32 if BtnA.isPressed(): > 33 label0.setText(str("TX: Send")) > 34 base\_can.send("uiflow2", 0, timeout\=0, rtr\=False, extframe\=False) > 35 time.sleep(1) > 36 label0.setText(str("TX: Not Send")) > 37 if base\_can.any(0): > 38 label1.setText(str("RX: Rec")) > 39 print(base\_can.recv(0, timeout\=5000)) > 40 time.sleep(1) > 41 label1.setText(str("RX: Not Rec")) > 42 > 43 > 44if \_\_name\_\_ \== "\_\_main\_\_": > 45 try: > 46 setup() > 47 while True: > 48 loop() > 49 except (Exception, KeyboardInterrupt) as e: > 50 try: > 51 from utility import print\_error\_msg > 52 > 53 print\_error\_msg(e) > 54 except ImportError: > 55 print("please update to latest firmware") Example output: > Output of received CAN message data via serial port. **API**[](#api "Link to this heading") ---------------------------------------- ### ATOMCANBase[](#atomcanbase "Link to this heading") _class_ base.atom\_can.ATOMCANBase(_\*args_, _\*\*kwargs_)[](#base.atom_can.ATOMCANBase "Link to this definition") Bases: `CAN` Create an ATOMCANBase object Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The CAN ID to use, Default is 0. * **port** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_ [_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – A list or tuple containing the TX and RX pin numbers. * **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The CAN mode to use(NORMAL, NO\_ACKNOWLEDGE, LISTEN\_ONLY), Default is NORMAL. * **baudrate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The baudrate to use, Default is 1000000. UiFlow2 Code Block: > ![init.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/can/init.png) MicroPython Code Block: > from base import ATOMCANBase > > base\_can \= ATOMCANBase(0, (6, 5), ATOMCANBase.NORMAL, baudrate\=1000000) ATOMCANBase class inherits CAN class, See [hardware.CAN](../hardware/can.html#hardware-can) for more details. --- # ADC V1.1 Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * ADC V1.1 Unit * [View page source](../_sources/units/adc_v11.rst.txt) * * * ADC V1.1 Unit[](#adc-v1-1-unit "Link to this heading") ======================================================== ADC V1.1 Unit is an A/D conversion module that utilizes the ADS1110 chip, a 16-bit self-calibrating analog-to-digital converter. It is designed with an I2C interface, offering convenient connectivity. The module offers conversion speeds of 8, 16, 32, and 128 samples per second (SPS), providing varying levels of accuracy at 16, 15, 14, and 12 bits of resolution respectively. Support the following products: [![ADCV11Unit](https://static-cdn.m5stack.com/resource/docs/products/unit/Unit-ADC_V1.1/img-240867ba-46d2-4cc6-beb9-79ac68af51d5.webp)](https://docs.m5stack.com/en/unit/Unit-ADC_V1.1) 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 ADCV11Unit > 10 > 11 > 12title0 \= None > 13label1 \= None > 14label0 \= None > 15i2c0 \= None > 16adc\_v11\_0 \= None > 17 > 18 > 19def setup(): > 20 global title0, label1, label0, i2c0, adc\_v11\_0 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title( > 25 "ADCV11Unit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 26 ) > 27 label1 \= Widgets.Label( > 28 "ADC 16Bit Value:", 1, 130, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 29 ) > 30 label0 \= Widgets.Label("ADC Value:", 1, 91, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 31 > 32 i2c0 \= I2C(0, scl\=Pin(33), sda\=Pin(32), freq\=100000) > 33 adc\_v11\_0 \= ADCV11Unit(i2c0) > 34 adc\_v11\_0.set\_sample\_rate(0x00) > 35 adc\_v11\_0.set\_mode(0x00) > 36 adc\_v11\_0.start\_single\_conversion() > 37 adc\_v11\_0.set\_gain(0x00) > 38 > 39 > 40def loop(): > 41 global title0, label1, label0, i2c0, adc\_v11\_0 > 42 M5.update() > 43 label0.setText(str((str("ADC Value:") + str((adc\_v11\_0.get\_voltage()))))) > 44 label1.setText(str((str("ADC 16Bit Value:") + str((adc\_v11\_0.get\_adc\_raw\_value()))))) > 45 > 46 > 47if \_\_name\_\_ \== "\_\_main\_\_": > 48 try: > 49 setup() > 50 while True: > 51 loop() > 52 except (Exception, KeyboardInterrupt) as e: > 53 try: > 54 from utility import print\_error\_msg > 55 > 56 print\_error\_msg(e) > 57 except ImportError: > 58 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/example.png) [adcv11\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/adc_v11/adcv11_core2_example.m5f2) class ADCV11Unit[](#class-adcv11unit "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ADCV11Unit(_i2c_)[](#ADCV11Unit "Link to this definition") Initialize the ADCV11Unit with an I2C or PAHUBUnit interface. Parameters: **i2c** – The I2C or PAHUBUnit instance used for communication. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ADCV11Unit.get\_voltage()[](#ADCV11Unit.get_voltage "Link to this definition") Get the measured voltage from the ADC V1.1 Unit. Returns: The measured voltage value, rounded to two decimal places. UIFLOW2: > ![get_voltage.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/get_voltage.png) ADCV11Unit.set\_gain(_gain_)[](#ADCV11Unit.set_gain "Link to this definition") Set the gain configuration for the ADC. Parameters: **gain** – The gain value to configure. UIFLOW2: > ![set_gain.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/set_gain.png) ADCV11Unit.set\_sample\_rate(_rate_)[](#ADCV11Unit.set_sample_rate "Link to this definition") Configure the ADC’s sampling rate. Parameters: **rate** – The sample rate to set. UIFLOW2: > ![set_sample_rate.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/set_sample_rate.png) ADCV11Unit.set\_mode(_mode_)[](#ADCV11Unit.set_mode "Link to this definition") Set the ADC’s operating mode. Parameters: **mode** – The mode to configure, e.g., continuous or single conversion. UIFLOW2: > ![set_mode.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/set_mode.png) ADCV11Unit.set\_config()[](#ADCV11Unit.set_config "Link to this definition") Update the ADC configuration register with the current settings. ADCV11Unit.get\_adc\_raw\_value()[](#ADCV11Unit.get_adc_raw_value "Link to this definition") Read the raw ADC value. UIFLOW2: > ![get_adc_raw_value.png](https://static-cdn.m5stack.com/mpy_docs/unit/adc_v11/get_adc_raw_value.png) --- # Unknown :mod:\`Widgets\` --- A basic UI library ===================================== .. module:: Widgets :synopsis: A basic UI library .. include:: ../refs/widgets.ref Micropython Example: .. literalinclude:: ../../../examples/widgets/screen/cores3\_widgets\_example.py :language: python :linenos: UIFLOW2 Example: |example.png| .. only:: builder\_html |cores3\_widgets\_example.m5f2| Screen functions ---------------- .. function:: Widgets.setBrightness(brightness: int) Set the backlight of the monitor。\`\`brightness\`\` ranges from 0 to 255. UIFLOW2: |setBrightness.png| .. function:: Widgets.fillScreen(color: int) Set the background color of the monitor. \`\`color\`\` accepts the color code of RGB888. UIFLOW2: |fillScreen.png| .. function:: Widgets.setRotation(rotation: int) Set the rotation Angle of the display. The \`\`rotation\`\` parameter only accepts the following values: - \`\`0\`\`: Portrait (0°C) - \`\`1\`\`: Landscape (90°C) - \`\`2\`\`: Inverse Portrait (180°C) - \`\`3\`\`: Inverse Landscape (270°C) UIFLOW2: |setRotation.png| Classes ------- .. toctree:: :maxdepth: 1 circle.rst image.rst image+.rst label.rst --- # IR — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * IR * [View page source](../_sources/hardware/ir.rst.txt) * * * IR[](#ir "Link to this heading") ================================== IR is used to control the infrared receiving/transmitting tube built into the host device. The specific support of the host for IR is as follows: | Controller | IR Transmitter | IR Receiver | | --- | --- | --- | | Atom Lite | ✔ | | | Atom Matrix | ✔ | | | Atom U | ✔ | | | AtomS3 Lite | ✔ | | | AtomS3U | ✔ | | | M5StickC | ✔ | | | M5StickC PLUS | ✔ | | | M5StickC PLUS2 | ✔ | | | Cardputer | ✔ | | | M5Capsule | ✔ | | 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 \* > 9 > 10 > 11ir \= None > 12 > 13 > 14def setup(): > 15 global ir > 16 > 17 M5.begin() > 18 ir \= IR() > 19 > 20 > 21def loop(): > 22 global ir > 23 M5.update() > 24 ir.tx(0x01, 0) > 25 > 26 > 27if \_\_name\_\_ \== "\_\_main\_\_": > 28 try: > 29 setup() > 30 while True: > 31 loop() > 32 except (Exception, KeyboardInterrupt) as e: > 33 try: > 34 from utility import print\_error\_msg > 35 > 36 print\_error\_msg(e) > 37 except ImportError: > 38 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/ir/example.png) [ir\_stickcplus2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/ir/ir_stickcplus2_example.m5f2) class IR[](#class-ir "Link to this heading") ---------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ IR[](#IR "Link to this definition") Initializes the IR unit with the appropriate pins based on the M5Stack board type. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/ir/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- IR.tx(_cmd_, _data_)[](#IR.tx "Link to this definition") Transmits an IR signal with the specified command and data using the NEC protocol. Parameters: * **cmd** – The command code to be transmitted. * **data** – The data associated with the command. UIFLOW2: > ![tx.png](https://static-cdn.m5stack.com/mpy_docs/hardware/ir/tx.png) --- # AIN4-20mA Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * AIN4-20mA Unit * [View page source](../_sources/units/ain4.rst.txt) * * * AIN4-20mA Unit[](#ain4-20ma-unit "Link to this heading") ========================================================== The following products are supported: [![AIN4_20MAUnit](https://static-cdn.m5stack.com/resource/docs/products/unit/AIN4-20mA%20Unit/img-a7fb07ad-7fd6-47f8-b333-2f55250f73a7.webp)](https://docs.m5stack.com/en/unit/AIN4-20mA%20Unit) 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 AIN4\_20MAUnit > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15i2c0 \= None > 16ain4\_20ma\_0 \= None > 17 > 18 > 19def setup(): > 20 global title0, label0, label1, i2c0, ain4\_20ma\_0 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title("AIN 4-20mA Unit Test", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 label0 \= Widgets.Label("CH1 Current:", 1, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 label1 \= Widgets.Label("CH1 ADC:", 1, 96, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 > 28 i2c0 \= I2C(0, scl\=Pin(33), sda\=Pin(32), freq\=100000) > 29 ain4\_20ma\_0 \= AIN4\_20MAUnit(i2c0, 0x55) > 30 ain4\_20ma\_0.set\_cal\_current(20) > 31 > 32 > 33def loop(): > 34 global title0, label0, label1, i2c0, ain4\_20ma\_0 > 35 M5.update() > 36 label0.setText(str((str("CH1 Current:") + str((ain4\_20ma\_0.get\_4\_20ma\_current\_value()))))) > 37 label1.setText(str((str("CH1 ADC:") + str((ain4\_20ma\_0.get\_adc\_raw16\_value()))))) > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/example.png) [ain4\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/ain4/ain4_core2_example.m5f2) class AIN4\_20MAUnit[](#class-ain4-20maunit "Link to this heading") --------------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ AIN4\_20MAUnit(_i2c_, _address_)[](#AIN4_20MAUnit "Link to this definition") Init I2C port & UNIT AIN 4-20mA I2C Address. Parameters: * **i2c** (_I2C_) – I2C port to use. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _|_[_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – I2C address of the Unit AIN4-20mA. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- AIN4\_20MAUnit.get\_adc\_raw\_value() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#AIN4_20MAUnit.get_adc_raw_value "Link to this definition") Retrieves the raw ADC value from the channel. Returns: Raw ADC value as a 12-bit integer. UIFLOW2: > ![get_adc_raw16_value.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/get_adc_raw16_value.png) AIN4\_20MAUnit.get\_current\_value() → [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") [](#AIN4_20MAUnit.get_current_value "Link to this definition") Retrieves the current value (in mA) from the channel. Returns: Current value in milliamperes (mA). UIFLOW2: > ![get_4_20ma_current_value.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/get_4_20ma_current_value.png) AIN4\_20MAUnit.set\_cal\_current(_val_)[](#AIN4_20MAUnit.set_cal_current "Link to this definition") Sets the calibration current for the specified channel. Parameters: **val** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The calibration current value, ranging from 4 to 20 mA. UIFLOW2: > ![set_cal_current.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/set_cal_current.png) AIN4\_20MAUnit.get\_firmware\_version() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#AIN4_20MAUnit.get_firmware_version "Link to this definition") Retrieves the firmware version of the AIN 4-20mA unit. Returns: Firmware version. UIFLOW2: > ![get_firmware_version.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/get_firmware_version.png) AIN4\_20MAUnit.get\_i2c\_address() → [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") [](#AIN4_20MAUnit.get_i2c_address "Link to this definition") Retrieves the current I2C address of the AIN 4-20mA unit. Returns: I2C address as a string in hexadecimal format. UIFLOW2: > ![get_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/get_i2c_address.png) AIN4\_20MAUnit.set\_i2c\_address(_addr_)[](#AIN4_20MAUnit.set_i2c_address "Link to this definition") Sets a new I2C address for the AIN 4-20mA unit. Parameters: **addr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address, must be between 0x08 and 0x77. UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/ain4_20ma/set_i2c_address.png) --- # Atomic GPS Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic GPS Base * [View page source](../_sources/base/atom_gps.rst.txt) * * * Atomic GPS Base[](#atomic-gps-base "Link to this heading") ============================================================ This is the driver library of ATOM GPS Base, which is used to obtain data from the GPS module. Support the following products: > | | | > | --- | --- | > | [![ATOM GPS](https://static-cdn.m5stack.com/resource/docs/products/atom/atomicgps/atomicgps_01.webp)](https://docs.m5stack.com/en/atom/atomicgps) | [![ATOM GPS Base](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20GPS%20Base/img-3f6d1129-0dde-4b67-adc6-69535a8d1052.webp)](https://docs.m5stack.com/en/atom/Atomic%20GPS%20Base) | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### get gps data[](#get-gps-data "Link to this heading") Open the [atoms3\_gps\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/gps/atoms3_gps_example.m5f2) project in UiFlow2. This example gets the GPS data of the ATOM GPS Base and displays it on the serial monitor. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/gps/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### get gps data[](#id1 "Link to this heading") This example gets the GPS data of the ATOM GPS Base and displays it on the serial monitor. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import ATOMGPSBase > 9import time > 10 > 11 > 12title0 \= None > 13base\_gps \= None > 14 > 15 > 16def setup(): > 17 global title0, base\_gps > 18 > 19 M5.begin() > 20 title0 \= Widgets.Title("GPS Base", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 21 > 22 base\_gps \= ATOMGPSBase(2, port\=(5, 6)) > 23 base\_gps.set\_time\_zone(0) > 24 > 25 > 26def loop(): > 27 global title0, base\_gps > 28 M5.update() > 29 print(base\_gps.get\_gps\_time()) > 30 print(base\_gps.get\_gps\_date()) > 31 print(base\_gps.get\_gps\_date\_time()) > 32 print(base\_gps.get\_timestamp()) > 33 print(base\_gps.get\_latitude()) > 34 print(base\_gps.get\_longitude()) > 35 print(base\_gps.get\_altitude()) > 36 print(base\_gps.get\_satellite\_num()) > 37 print(base\_gps.get\_pos\_quality()) > 38 print(base\_gps.get\_corse\_over\_ground()) > 39 print(base\_gps.get\_speed\_over\_ground()) > 40 time.sleep(1) > 41 > 42 > 43if \_\_name\_\_ \== "\_\_main\_\_": > 44 try: > 45 setup() > 46 while True: > 47 loop() > 48 except (Exception, KeyboardInterrupt) as e: > 49 try: > 50 from utility import print\_error\_msg > 51 > 52 print\_error\_msg(e) > 53 except ImportError: > 54 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### ATOMGPSBase[](#atomgpsbase "Link to this heading") _class_ base.atom\_gps.ATOMGPSBase(_id\=1_, _port\=None_, _debug\=False_)[](#base.atom_gps.ATOMGPSBase "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an ATOMGPSBase object. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The UART ID to use (0, 1, or 2). Default is 2. * **port** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_ [_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – A list or tuple containing the TX and RX pin numbers. * **debug** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Whether to enable debug mode. Default is False. UiFlow2 Code Block: > ![init.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/init.png) MicroPython Code Block: > from machine import UART > from base import ATOMGPSBase > > gps \= ATOMGPSBase(id\=1, port\=(16, 17)) deinit()[](#base.atom_gps.ATOMGPSBase.deinit "Link to this definition") Deinitialize the GPS unit, stopping any running tasks and releasing resources. UiFlow2 Code Block: > ![deinit.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/deinit.png) MicroPython Code Block: > gps.deinit() Return type: None get\_altitude()[](#base.atom_gps.ATOMGPSBase.get_altitude "Link to this definition") Get the current altitude. Returns: The current altitude. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_altitude.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_altitude.png) MicroPython Code Block: > gps.get\_altitude() get\_antenna\_state()[](#base.atom_gps.ATOMGPSBase.get_antenna_state "Link to this definition") Get the state of the antenna. Returns: The current antenna state. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_antenna_state.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_antenna_state.png) MicroPython Code Block: > gps.get\_antenna\_state() get\_corse\_over\_ground()[](#base.atom_gps.ATOMGPSBase.get_corse_over_ground "Link to this definition") Get the course over ground (COG). Returns: The course over ground in degrees. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_corse_over_ground.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_corse_over_ground.png) MicroPython Code Block: > gps.get\_corse\_over\_ground() get\_gps\_date()[](#base.atom_gps.ATOMGPSBase.get_gps_date "Link to this definition") Get the current GPS date. Returns: The GPS date as a list of strings \[day, month, year\]. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") \[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_gps_date.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_gps_date.png) MicroPython Code Block: > gps.get\_gps\_date() get\_gps\_date\_time()[](#base.atom_gps.ATOMGPSBase.get_gps_date_time "Link to this definition") Get the current GPS date and time combined. Returns: The GPS date and time as a list of strings \[year, month, day, hour, minute, second\]. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") \[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_gps_date_time.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_gps_date_time.png) MicroPython Code Block: > gps.get\_gps\_date\_time() get\_gps\_time()[](#base.atom_gps.ATOMGPSBase.get_gps_time "Link to this definition") Get the current GPS time. Returns: The GPS time as a list of strings \[hour, minute, second\]. Return type: [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") \[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")\ \] UiFlow2 Code Block: > ![get_gps_time.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_gps_time.png) MicroPython Code Block: > gps.get\_gps\_time() get\_latitude()[](#base.atom_gps.ATOMGPSBase.get_latitude "Link to this definition") Get the current latitude. Returns: The current latitude. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_latitude.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_latitude.png) MicroPython Code Block: > gps.get\_latitude() get\_longitude()[](#base.atom_gps.ATOMGPSBase.get_longitude "Link to this definition") Get the current longitude. Returns: The current longitude. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_longitude.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_longitude.png) MicroPython Code Block: > gps.get\_longitude() get\_pos\_quality()[](#base.atom_gps.ATOMGPSBase.get_pos_quality "Link to this definition") Get the quality of the GPS position. Returns: The position quality indicator. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_pos_quality.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_pos_quality.png) MicroPython Code Block: > gps.get\_pos\_quality() get\_satellite\_num()[](#base.atom_gps.ATOMGPSBase.get_satellite_num "Link to this definition") Get the number of satellites used for positioning. Returns: The number of satellites. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_satellite_num.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_satellite_num.png) MicroPython Code Block: > gps.get\_satellite\_num() get\_speed\_over\_ground()[](#base.atom_gps.ATOMGPSBase.get_speed_over_ground "Link to this definition") Get the speed over ground (SOG). Returns: The speed over ground in knots. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_speed_over_ground.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_speed_over_ground.png) MicroPython Code Block: > gps.get\_speed\_over\_ground() get\_time\_zone()[](#base.atom_gps.ATOMGPSBase.get_time_zone "Link to this definition") Get the current time zone offset. Returns: The current time zone offset. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_time_zone.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_time_zone.png) MicroPython Code Block: > gps.get\_time\_zone() get\_timestamp()[](#base.atom_gps.ATOMGPSBase.get_timestamp "Link to this definition") Get the timestamp of the current GPS time. Returns: The timestamp representing the current GPS time. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_timestamp.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/get_timestamp.png) MicroPython Code Block: > gps.get\_timestamp() set\_time\_zone(_value_)[](#base.atom_gps.ATOMGPSBase.set_time_zone "Link to this definition") Set the time zone offset for the GPS time. Parameters: **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The time zone offset value to set. Return type: None UiFlow2 Code Block: > ![set_time_zone.png](https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/base/gps/set_time_zone.png) MicroPython Code Block: > gps.set\_time\_zone(8) --- # Unknown Quick Reference =============== .. toctree:: :maxdepth: 1 get-started.rst usb-mode.rst --- # Angle Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * Angle Unit * [View page source](../_sources/units/angle.rst.txt) * * * Angle Unit[](#angle-unit "Link to this heading") ================================================== The following products are supported: > [![Angle](https://static-cdn.m5stack.com/resource/docs/products/unit/angle/angle_01.webp)](https://docs.m5stack.com/en/unit/angle) Micropython Example: import M5 from M5 import \* from unit import \* M5.begin() angle\_0 \= Angle((8,9)) while True: print(angle\_0.get\_voltage()) print(angle\_0.get\_value()) UIFLOW2 Example: > ![example.svg](https://static-cdn.m5stack.com/mpy_docs/unit/angle/example.svg) [angle\_core\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/angle/angle_core.m5f2) class Angle[](#class-angle "Link to this heading") ---------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Angle(_port_)[](#Angle "Link to this definition") Create an Angle object. parameter is: * `port` is the pins number of the port UIFLOW2: > ![init.svg](https://static-cdn.m5stack.com/mpy_docs/unit/angle/init.svg) Methods[](#methods "Link to this heading") -------------------------------------------- Angle.get\_value()[](#Angle.get_value "Link to this definition") This method allows reading the Angle’s rotation value and returning an integer value. The range is 0-65535. UIFLOW2: > ![get_value.svg](https://static-cdn.m5stack.com/mpy_docs/unit/angle/get_value.svg) Angle.get\_voltage()[](#Angle.get_voltage "Link to this definition") This method allows reading the voltage value of Angle, and the return value is a floating point value. UIFLOW2: > ![get_voltage.svg](https://static-cdn.m5stack.com/mpy_docs/unit/angle/get_voltage.svg) --- # Mic — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * Mic * [View page source](../_sources/hardware/mic.rst.txt) * * * Mic[](#mic "Link to this heading") ==================================== Mic is used to control the built-in microphone inside the host device. Below is the detailed Mic support for the host: | Controller | SPM1423 | ES7210 | | --- | --- | --- | | AtomS3 | | | | AtomS3 Lite | | | | AtomS3U | ✔ | | | StampS3 | | | | CoreS3 | | ✔ | | Core2 | ✔ | | | TOUGH | | | 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 \* > 8import time > 9 > 10 > 11label0 \= None > 12 > 13 > 14rec\_data \= None > 15 > 16 > 17def setup(): > 18 global label0, rec\_data > 19 > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 label0 \= Widgets.Label("label0", 123, 58, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 23 > 24 Speaker.begin() > 25 Speaker.setVolumePercentage(1) > 26 Speaker.end() > 27 Mic.begin() > 28 rec\_data \= bytearray(8000 \* 5) > 29 label0.setText(str("rec...")) > 30 Mic.record(rec\_data, 8000, False) > 31 while Mic.isRecording(): > 32 time.sleep\_ms(500) > 33 Mic.end() > 34 Speaker.begin() > 35 label0.setText(str("play...")) > 36 Speaker.playRaw(rec\_data, 8000) > 37 while Speaker.isPlaying(): > 38 time.sleep\_ms(500) > 39 label0.setText(str("done")) > 40 > 41 > 42def loop(): > 43 global label0, rec\_data > 44 M5.update() > 45 > 46 > 47if \_\_name\_\_ \== "\_\_main\_\_": > 48 try: > 49 setup() > 50 while True: > 51 loop() > 52 except (Exception, KeyboardInterrupt) as e: > 53 try: > 54 from utility import print\_error\_msg > 55 > 56 print\_error\_msg(e) > 57 except ImportError: > 58 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/example.png) [cores3\_mic\_example.m5f2](https://uiflow2.m5stack.com/?pkey=e1d3556776dd425a9dd8b46ec5984bea) class Mic[](#class-mic "Link to this heading") ------------------------------------------------ Important Methods of the Mic Class heavily rely on `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg) and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg). All calls to methods of Mic objects should be placed after `M5.begin()` ![M5.begin.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/begin.svg), and `M5.update()` ![M5.update.svg](https://static-cdn.m5stack.com/mpy_docs/system/system/update.svg) should be called in the main loop. Methods[](#methods "Link to this heading") -------------------------------------------- Mic.config(\[_cfg:mic\_config\_t_\])[](#Mic.config "Link to this definition") Mic.config(_'param'_) Mic.config(_param\=value_) Get or set the parameters of the Mic object. When no parameters are passed, it returns an object of `mic_config_t`. When a `mic_config_t` object is passed, Mic sets all supported parameters of the Mic. When passing parameters from the table below, Mic will get or set the passed parameters. The following parameters are supported: > | Parameter | Type | Description | > | --- | --- | --- | > | pin\_data\_in | (integer) | Serial data line of I2S, representing audio data in binary complement. | > | pin\_bck | (integer) | Serial clock line of I2S, corresponding to each bit of digital audio data. | > | pin\_mck | (integer) | Master clock line of I2S. Generally, to better synchronize between systems, increase the MCLK signal, MCLK frequency = 256 \* sampling frequency. | > | pin\_ws | (integer) | Frame clock of I2S, used to switch left and right channel data. | > | sample\_rate | (integer) | Target sampling rate of input audio. | > | stereo | (boolean) | Use stereo output. | > | over\_sampling | (integer) | Number of times to average the sampling. | > | magnification | (integer) | Multiplier of the input value. | > | noise\_filter\_level | (integer) | Coefficient of the previous value used for noise filtering. | > | use\_adc | (boolean) | Use analog input microphone (only pin\_data\_in is needed). | > | dma\_buf\_len | (integer) | DMA buffer length of I2S. | > | dma\_buf\_count | (integer) | Number of DMA buffers of I2S. | > | task\_priority | (integer) | Priority of background tasks. | > | task\_pinned\_core | (integer) | CPU used by background tasks. | > | i2s\_port | (integer) | I2S port. | UIFLOW2: > Read property: > > > Python: > > > > Mic.config("pin\_data\_in") > > > > ![get_config_boolean.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/get_config_boolean.png) > > > > ![get_config_int.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/get_config_int.png) > > Set property: > > > Python: > > > > Mic.config(pin\_data\_in\=1) > > > > ![set_config_int.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/set_config_int.png) > > > > ![set_config_boolean.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/set_config_boolean.png) Mic.begin() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Mic.begin "Link to this definition") Start the Mic function. Returns True if successful. UIFLOW2: > ![begin.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/begin.png) Mic.end() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Mic.end "Link to this definition") Stop the Mic function. Returns True if successful. UIFLOW2: > ![end.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/end.png) Mic.isRunning() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Mic.isRunning "Link to this definition") Check if Mic is running. Returns a boolean value. UIFLOW2: > ![isRunning.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/isRunning.png) Mic.isEnabled() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Mic.isEnabled "Link to this definition") Check if Mic is enabled. Returns a boolean value. UIFLOW2: > ![isEnabled.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/isEnabled.png) Mic.isRecording() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Mic.isRecording "Link to this definition") Check if Mic is recording. Returns an integer value. Return values: > * 0=not recording > > * 1=recording (There’s room in the queue) > > * 2=recording (There’s no room in the queue.) > UIFLOW2: > ![isRecording.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/isRecording.png) Mic.setSampleRate(_sample\_rate_) → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Mic.setSampleRate "Link to this definition") Set the sampling rate. The parameter sample\_rate generally includes 8000, 11025, 22050, 32000, 44100. UIFLOW2: > ![setSampleRate.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/setSampleRate.png) Mic.record(_rec\_data_\[, _rate_\[, _stereo_\]\]) → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Mic.record "Link to this definition") Record audio data. The parameter rec\_data requires passing a buffer. The parameter rate generally includes 8000, 11025, 22050, 32000, 44100, with a default of 8000. The parameter stereo is passed as True or False. UIFLOW2: > ![record.png](https://static-cdn.m5stack.com/mpy_docs/hardware/microphone/record.png) class mic\_config\_t[](#class-mic-config-t "Link to this heading") -------------------------------------------------------------------- mic\_config\_t.pin\_data\_in_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.pin_data_in "Link to this definition") Serial data line of I2S, representing audio data in binary complement. mic\_config\_t.pin\_bck_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.pin_bck "Link to this definition") Serial clock line of I2S, corresponding to each bit of digital audio data. mic\_config\_t.pin\_mck_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.pin_mck "Link to this definition") Master clock line of I2S. Generally, to better synchronize between systems, increase the MCLK signal, MCLK frequency = 256 \* sampling frequency. mic\_config\_t.pin\_ws_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.pin_ws "Link to this definition") Frame clock of I2S, used to switch left and right channel data. mic\_config\_t.sample\_rate_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.sample_rate "Link to this definition") Target sampling rate of input audio. mic\_config\_t.stereo_: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _[](#mic_config_t.stereo "Link to this definition") Use stereo output. mic\_config\_t.over\_sampling_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.over_sampling "Link to this definition") Number of times to average the sampling. mic\_config\_t.magnification_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.magnification "Link to this definition") Multiplier of the input value. mic\_config\_t.noise\_filter\_level_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.noise_filter_level "Link to this definition") Coefficient of the previous value used for noise filtering. mic\_config\_t.use\_adc_: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") _[](#mic_config_t.use_adc "Link to this definition") Use analog input microphone (only pin\_data\_in is needed). mic\_config\_t.dma\_buf\_len_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.dma_buf_len "Link to this definition") DMA buffer length of I2S. mic\_config\_t.dma\_buf\_count_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.dma_buf_count "Link to this definition") Number of DMA buffers of I2S. mic\_config\_t.task\_priority_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.task_priority "Link to this definition") Priority of background tasks. mic\_config\_t.task\_pinned\_core_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.task_pinned_core "Link to this definition") CPU used by background tasks. mic\_config\_t.i2s\_port_: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") _[](#mic_config_t.i2s_port "Link to this definition") I2S port. --- # Pin — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * Pin * [View page source](../_sources/hardware/pin.rst.txt) * * * Pin[](#pin "Link to this heading") ==================================== The Pin class is used to manage GPIO operations. Below is the detailed support for the Pin class: 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 \* > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15pin6 \= None > 16pin7 \= None > 17 > 18 > 19def setup(): > 20 global title0, label0, label1, pin6, pin7 > 21 > 22 M5.begin() > 23 Widgets.fillScreen(0x222222) > 24 title0 \= Widgets.Title("Pin example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 label0 \= Widgets.Label("Pin 6 State:", 1, 83, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 26 label1 \= Widgets.Label("Pin 7 State:", 1, 132, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 27 > 28 pin6 \= Pin(6, mode\=Pin.OUT) > 29 pin7 \= Pin(7, mode\=Pin.IN) > 30 > 31 > 32def loop(): > 33 global title0, label0, label1, pin6, pin7 > 34 M5.update() > 35 pin6.value(1) > 36 label0.setText(str((str("Pin 6 State:") + str((pin6.value()))))) > 37 time.sleep(1) > 38 pin6.value(0) > 39 label0.setText(str((str("Pin 6 State:") + str((pin6.value()))))) > 40 time.sleep(1) > 41 label1.setText(str((str("Pin 7 State:") + str((pin7.value()))))) > 42 > 43 > 44if \_\_name\_\_ \== "\_\_main\_\_": > 45 try: > 46 setup() > 47 while True: > 48 loop() > 49 except (Exception, KeyboardInterrupt) as e: > 50 try: > 51 from utility import print\_error\_msg > 52 > 53 print\_error\_msg(e) > 54 except ImportError: > 55 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/example.png) [pin\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/pin/pin_cores3_example.m5f2) class Pin[](#class-pin "Link to this heading") ------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Pin(_id_, _mode\=\-1_, _pull\=\-1_)[](#Pin "Link to this definition") Access the pin peripheral (GPIO pin) associated with the given `id`. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – is mandatory and can be an arbitrary object. * **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – specifies the pin mode. * `Pin.IN` - Pin is configured for input. If viewed as an output the pin is in high-impedance state. * `Pin.OUT` - Pin is configured for (normal) output. * **pull** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – specifies if the pin has a (weak) pull resistor attached. * `None` - No pull up or down resistor. * `Pin.PULL_UP` - Pull up resistor enabled. * `Pin.PULL_DOWN` - Pull down resistor enabled. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Pin.value(\[_value_\])[](#Pin.value "Link to this definition") Set the value of the pin. The argument `value` can be anything that converts to a boolean. If it converts to `True`, the pin is set to state ‘1’, otherwise it is set to state ‘0’. The behaviour of this method depends on the mode of the pin: > > * `Pin.IN` - The value is stored in the output buffer for the pin. The pin state does not change, it remains in the high-impedance state. The stored value will become active on the pin as soon as it is changed to `Pin.OUT` mode. > > > > * `Pin.OUT` - The output buffer is set to the given value immediately. > > > > UIFLOW2: > > > ![set_value.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/set_value.png) > > > > ![set_value1.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/set_value1.png) > > > > ![get_value.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/get_value.png) Pin.off() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Pin.off "Link to this definition") Sets the pin to low level. UIFLOW2: > ![off.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/off.png) Pin.on() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Pin.on "Link to this definition") Sets the pin to high level. UIFLOW2: > ![on.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pin/on.png) Constants[](#constants "Link to this heading") ------------------------------------------------ Pin.IN[](#Pin.IN "Link to this definition") Input mode Pin.OUT[](#Pin.OUT "Link to this definition") Output mode Pin.PULL\_UP[](#Pin.PULL_UP "Link to this definition") Pull-up resistor Pin.PULL\_DOWN[](#Pin.PULL_DOWN "Link to this definition") Pull-down resistor --- # Atomic Display Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic Display Base * [View page source](../_sources/base/display.rst.txt) * * * Atomic Display Base[](#atomic-display-base "Link to this heading") ==================================================================== The is the class of the Atomic Display Base, which is used to display images and text on the screen. Support the following products: > | | | | > | --- | --- | --- | > | [![Atomic Display Base](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/atom/Atomic%20Display%20Base/4.webp)](https://docs.m5stack.com/en/atom/Atomic%20Display%20Base) | [![Atom Display](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_display/atom_display_01.webp)](https://docs.m5stack.com/en/atom/atom_display) | [![Atom Display-Lite](https://static-cdn.m5stack.com/resource/docs/products/atom/atom_display_lite/atom_display_lite_01.webp)](https://docs.m5stack.com/en/atom/atom_display_lite) | Below is the detailed support for Atomic Display Base on the host: | Controller | Status | | --- | --- | | Atom Echo | ⭕ | | Atom Lite | ✅ | | Atom Matrix | ✅ | | AtomS3 | ✅ | | AtomS3 Lite | ✅ | | AtomS3R | ✅ | | AtomS3R-CAM | ✅ | | AtomS3R-Ext | ✅ | * ✅: Supported. * ⭕: Optional, It conflicts with some internal resource of the host. UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Draw Text[](#draw-text "Link to this heading") Open the [atoms3\_draw\_text\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/display/atoms3_draw_text_example.m5f2) project in UiFlow2. This example displays the text “M5Stack” on the screen. UiFlow2 Code Block: > ![example_draw_text.png](https://static-cdn.m5stack.com/mpy_docs/base/display/example_draw_text.png) Example output: > None ### Draw Image[](#draw-image "Link to this heading") Open the [atoms3\_draw\_text\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/display/atoms3_draw_text_example.m5f2) project in UiFlow2. This example displays the image on the screen. UiFlow2 Code Block: > ![example_draw_image.png](https://static-cdn.m5stack.com/mpy_docs/base/display/example_draw_image.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Draw Text[](#id1 "Link to this heading") This example displays the text “M5Stack” on the screen. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import AtomicDisplayBase > 9 > 10 > 11label0 \= None > 12label1 \= None > 13base\_display \= None > 14 > 15 > 16def setup(): > 17 global label0, label1, base\_display > 18 > 19 M5.begin() > 20 label1 \= Widgets.Label("M5Stack", 23, 53, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 21 > 22 base\_display \= AtomicDisplayBase( > 23 width\=1280, > 24 height\=720, > 25 refresh\_rate\=60, > 26 output\_width\=1280, > 27 output\_height\=720, > 28 scale\_w\=1, > 29 scale\_h\=1, > 30 pixel\_clock\=74250000, > 31 ) > 32 label0 \= Widgets.Label( > 33 "M5STACK", 466, 318, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu72, base\_display > 34 ) > 35 > 36 > 37def loop(): > 38 global label0, label1, base\_display > 39 M5.update() > 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") Example output: > None ### Draw Image[](#id2 "Link to this heading") This example displays the image on the screen. MicroPython Code Block: > \# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > # > \# SPDX-License-Identifier: MIT > > import os, sys, io > import M5 > from M5 import \* > from base import AtomicDisplayBase > > image0 \= None > image1 \= None > base\_display \= None > > def setup(): > global image0, image1, base\_display > > M5.begin() > image0 \= Widgets.Image("res/img/default.jpg", 51, 51, scale\_x\=1, scale\_y\=1) > > base\_display \= AtomicDisplayBase( > width\=1280, > height\=720, > refresh\_rate\=60, > output\_width\=1280, > output\_height\=720, > scale\_w\=1, > scale\_h\=1, > pixel\_clock\=74250000, > ) > image1 \= Widgets.Image( > "res/img/default.jpg", 443, 213, scale\_x\=10, scale\_y\=10, parent\=base\_display > ) > image0.setImage("res/img/default.jpg") > image1.setImage("res/img/default.jpg") > > def loop(): > global image0, image1, base\_display > M5.update() > > if \_\_name\_\_ \== "\_\_main\_\_": > try: > setup() > while True: > loop() > except (Exception, KeyboardInterrupt) as e: > try: > from utility import print\_error\_msg > > print\_error\_msg(e) > except ImportError: > print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### AtomicDisplayBase[](#atomicdisplaybase "Link to this heading") _class_ base.display.AtomicDisplayBase(_width\=1280_, _height\=720_, _refresh\_rate\=60_, _output\_width\=1280_, _output\_height\=720_, _scale\_w\=1_, _scale\_h\=1_, _pixel\_clock\=74250000_)[](#base.display.AtomicDisplayBase "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Initialize the Atomic Display Base. Parameters: * **width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The logical width of the Atomic Display Base. Default is 1280px. * **height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The logical height of the Atomic Display Base. Default is 720px. * **refresh\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The refresh rate of the Atomic Display Base. Default is 60Hz. * **output\_width** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The width of the output of the Atomic Display Base. Default is 1280px. * **output\_height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The height of the output of the Atomic Display Base. Default is 720px. * **scale\_w** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The scale width of the Atomic Display Base. Default is 1. * **scale\_h** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The scale height of the Atomic Display Base. Default is 1. * **pixel\_clock** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The pixel clock of the Atomic Display Base. Default is 74250000. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/display/init.png) MicroPython Code Block: > from base import AtomicDisplayBase > atom\_display \= AtomicDisplayBase(1280, 720, 60, 1280, 720, 1, 1, 74250000) --- # Unknown Software ========= .. include:: ../refs/software.ref .. toctree:: :maxdepth: 1 modbus.rst requests2.rst umqtt.rst tcp.rst udp.rst --- # Atomic Echo Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic Echo Base * [View page source](../_sources/base/echo.rst.txt) * * * Atomic Echo Base[](#atomic-echo-base "Link to this heading") ============================================================== The following products are supported: > [![Atomic Echo Base](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/atom/Atomic%20Echo%20Base/4.webp)](https://docs.m5stack.com/en/atom/Atomic%20Echo%20Base) Below is the detailed support for Speaker on the host: | Controller | Atomic Echo Base | | --- | --- | | Atom Echo | ⭕ | | Atom Lite | ✅ | | Atom Matrix | ✅ | | AtomS3 | ✅ | | AtomS3 Lite | ✅ | | AtomS3R | ✅ | | AtomS3R-CAM | ✅ | | AtomS3R-Ext | ✅ | 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 base import ATOMEchoBase > 11 > 12 > 13i2c1 \= None > 14base\_echo \= None > 15 > 16 > 17def setup(): > 18 global i2c1, base\_echo > 19 > 20 M5.begin() > 21 i2c1 \= I2C(1, scl\=Pin(39), sda\=Pin(38), freq\=100000) > 22 base\_echo \= ATOMEchoBase(i2c1, 0x18, 1, 44100, 8, 6, 7, 5) > 23 base\_echo.speaker.playWavFile("/flash/res/audio/66.wav") > 24 > 25 > 26def loop(): > 27 global i2c1, base\_echo > 28 M5.update() > 29 > 30 > 31if \_\_name\_\_ \== "\_\_main\_\_": > 32 try: > 33 setup() > 34 while True: > 35 loop() > 36 except (Exception, KeyboardInterrupt) as e: > 37 try: > 38 from utility import print\_error\_msg > 39 > 40 print\_error\_msg(e) > 41 except ImportError: > 42 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/echo/example.png) [atoms3\_echo\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/echo/atoms3_echo_example.m5f2) class ATOMEchoBase[](#class-atomechobase "Link to this heading") ------------------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ATOMEchoBase(_i2c_, _address: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 0x18_, _i2s\_port: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 1_, _sample\_rate: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= 44100_, _i2s\_sck: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _i2s\_ws: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _i2s\_di: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_, _i2s\_do: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") \= \-1_)[](#ATOMEchoBase "Link to this definition") Create an ATOMEchoBase object. Parameters: * **i2c** (_I2C_) – I2C object * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the ES8311. Default is 0x18. * **i2s\_port** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2S port number. Default is 1. * **sample\_rate** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The sample rate of the audio. Default is 44100. * **i2s\_sck** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2S SCK pin. Default is -1. * **i2s\_ws** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2S WS pin. Default is -1. * **i2s\_di** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2S DI pin. Default is -1. * **i2s\_do** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2S DO pin. Default is -1. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/echo/init.png) Micropython: from hardware import I2C from hardware import Pin from base import ATOMEchoBase \# atom echo i2c1 \= I2C(1, scl\=Pin(21), sda\=Pin(25), freq\=100000) echo \= ATOMEchoBase(i2c1, address\=0x18, i2s\_port\=1, sample\_rate\=44100, i2s\_sck\=33, i2s\_ws\=19, i2s\_di\=23, i2s\_do\=22) \# atom lite i2c1 \= I2C(1, scl\=Pin(21), sda\=Pin(25), freq\=100000) echo \= ATOMEchoBase(i2c1, address\=0x18, i2s\_port\=1, sample\_rate\=44100, i2s\_sck\=33, i2s\_ws\=19, i2s\_di\=23, i2s\_do\=22) \# atom matrix i2c1 \= I2C(1, scl\=Pin(21), sda\=Pin(25), freq\=100000) echo \= ATOMEchoBase(i2c1, address\=0x18, i2s\_port\=1, sample\_rate\=44100, i2s\_sck\=33, i2s\_ws\=19, i2s\_di\=23, i2s\_do\=22) \# atoms3 / atoms3 lite i2c1 \= I2C(1, scl\=Pin(39), sda\=Pin(38), freq\=100000) echo \= ATOMEchoBase(i2c1, address\=0x18, i2s\_port\=1, sample\_rate\=44100, i2s\_sck\=8, i2s\_ws\=6, i2s\_di\=7, i2s\_do\=5) \# atoms3r / atoms3r-cam / atoms3-ext i2c1 \= I2C(1, scl\=Pin(39), sda\=Pin(38), freq\=100000) echo \= ATOMEchoBase(i2c1, address\=0x18, i2s\_port\=1, sample\_rate\=44100, i2s\_sck\=8, i2s\_ws\=6, i2s\_di\=7, i2s\_do\=5) echo.speaker.tone(2000, 1000) echo.speaker.playWavFile('res/audio/66.wav') Attributes[](#attributes "Link to this heading") -------------------------------------------------- ATOMEchoBase.speaker[](#ATOMEchoBase.speaker "Link to this definition") Objects of the Speaker class. See [hardware.Speaker.Methods](../hardware/speaker.html#hardware-speaker-methods) for more details on how to use the ATOMEchoBase.speaker properties. ATOMEchoBase.microphone[](#ATOMEchoBase.microphone "Link to this definition") Objects of the Microphone class. See [hardware.Mic.Methods](../hardware/mic.html#hardware-mic-methods) for more details on how to use the ATOMEchoBase.microphone properties. Note Microphone is not quite ready yet. --- # Unknown System ====== .. include:: ../refs/system.ref .. toctree:: :maxdepth: 1 audio.rst bleuart.rst m5ble.rst power.rst time.rst m5espnow.rst wlan.sta.rst wlan.ap.rst --- # Angle8 Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * Angle8 Unit * [View page source](../_sources/units/angle8.rst.txt) * * * Angle8 Unit[](#angle8-unit "Link to this heading") ==================================================== UNIT 8Angle is an input unit integrating 8 adjustable potentiometers, internal STM32F030 microcomputer as acquisition and communication processor, and the host computer adopts I2C communication interface, each adjustable potentiometer corresponds to 1 RGB LED light, and there is also a physical toggle switch and its corresponding RGB LED light, containing 5V->3V3 DCDC circuit. Support the following products: [![Angle8Unit](https://static-cdn.m5stack.com/resource/docs/products/unit/8Angle/img-b698604d-29dd-4506-b662-4752e1f03a28.webp)](https://docs.m5stack.com/en/unit/8Angle) 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 Angle8Unit > 10import m5utils > 11import time > 12 > 13 > 14title0 \= None > 15label0 \= None > 16label1 \= None > 17label2 \= None > 18i2c0 \= None > 19angle8\_0 \= None > 20 > 21 > 22import math > 23 > 24map\_value \= None > 25 > 26 > 27def setup(): > 28 global title0, label0, label1, label2, i2c0, angle8\_0, map\_value > 29 > 30 M5.begin() > 31 Widgets.fillScreen(0x222222) > 32 title0 \= Widgets.Title( > 33 "8AngleUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 34 ) > 35 label0 \= Widgets.Label("label0", 0, 58, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 36 label1 \= Widgets.Label("label1", 0, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 37 label2 \= Widgets.Label("label2", 0, 160, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 38 > 39 i2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) > 40 angle8\_0 \= Angle8Unit(i2c0, 0x43) > 41 angle8\_0.set\_led\_rgb\_from(1, 9, 0x33FF33, 100, 0) > 42 map\_value \= 0 > 43 > 44 > 45def loop(): > 46 global title0, label0, label1, label2, i2c0, angle8\_0, map\_value > 47 M5.update() > 48 map\_value \= round(m5utils.remap(angle8\_0.get\_adc8\_raw(8), 0, 255, 0, 100)) > 49 label0.setText(str((str("Switch:") + str((angle8\_0.get\_switch\_status()))))) > 50 label1.setText(str((str("CH1 8bit:") + str((angle8\_0.get\_adc8\_raw(1)))))) > 51 label2.setText(str((str("CH8 map value:") + str(map\_value)))) > 52 angle8\_0.set\_led\_rgb\_from(1, 9, 0x33FF33, map\_value, 0) > 53 time.sleep(1) > 54 > 55 > 56if \_\_name\_\_ \== "\_\_main\_\_": > 57 try: > 58 setup() > 59 while True: > 60 loop() > 61 except (Exception, KeyboardInterrupt) as e: > 62 try: > 63 from utility import print\_error\_msg > 64 > 65 print\_error\_msg(e) > 66 except ImportError: > 67 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/example.png) [angle8unit\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/angle8unit/angle8unit_cores3_example.m5f2) class Angle8Unit[](#class-angle8unit "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Angle8Unit(_i2c_, _address_)[](#Angle8Unit "Link to this definition") Initialize the Angle8Unit with the specified I2C interface and address. Parameters: * **i2c** – The I2C or PAHUBUnit instance for communication. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The I2C address of the device (default is ANGLE8\_ADDR). UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Angle8Unit.available()[](#Angle8Unit.available "Link to this definition") Check if the device is available on the I2C bus. Angle8Unit.get\_adc12\_raw(_channel_)[](#Angle8Unit.get_adc12_raw "Link to this definition") Get the raw 12-bit ADC value from the specified channel. Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel number (1 to 8). UIFLOW2: > ![get_adc12_raw.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/get_adc12_raw.png) Angle8Unit.get\_adc8\_raw(_channel_)[](#Angle8Unit.get_adc8_raw "Link to this definition") Get the raw 8-bit ADC value from the specified channel. Parameters: **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The channel number (1 to 8). UIFLOW2: > ![get_adc8_raw.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/get_adc8_raw.png) Angle8Unit.get\_switch\_status()[](#Angle8Unit.get_switch_status "Link to this definition") Get the status of the switch button. UIFLOW2: > ![get_switch_status.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/get_switch_status.png) Angle8Unit.set\_led\_rgb(_channel_, _rgb_, _bright_)[](#Angle8Unit.set_led_rgb "Link to this definition") Set the RGB color and brightness of the specified LED channel. Parameters: * **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The LED channel number (0 to 8). * **rgb** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RGB color value (0x00 to 0xFFFFFF). * **bright** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The brightness level (0 to 100, default is 50). UIFLOW2: > ![set_led_rgb.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/set_led_rgb.png) Angle8Unit.set\_led\_rgb\_from(_begin_, _end_, _rgb_, _bright_, _per\_delay_)[](#Angle8Unit.set_led_rgb_from "Link to this definition") Set the RGB color and brightness for a range of LED channels. Parameters: * **begin** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The starting LED channel (0 to 8). * **end** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The ending LED channel (0 to 8). * **rgb** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RGB color value (0x00 to 0xFFFFFF). * **bright** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The brightness level (0 to 100, default is 50). * **per\_delay** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The delay in milliseconds between setting each channel (default is 0). UIFLOW2: > ![set_led_rgb_from.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/set_led_rgb_from.png) Angle8Unit.set\_angle\_sync\_bright(_channel_, _rgb_)[](#Angle8Unit.set_angle_sync_bright "Link to this definition") Set the LED brightness synchronized with the angle value. Parameters: * **channel** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The LED channel number (0 to 8). * **rgb** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The RGB color value (0x00 to 0xFFFFFF). UIFLOW2: > ![set_angle_sync_bright.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/set_angle_sync_bright.png) Angle8Unit.get\_device\_spec(_mode_)[](#Angle8Unit.get_device_spec "Link to this definition") Get device specifications such as firmware version or I2C address. Parameters: **mode** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The register to read (FW\_VER\_REG or I2C\_ADDR\_REG). UIFLOW2: > ![get_device_spec.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/get_device_spec.png) Angle8Unit.set\_i2c\_address(_address_)[](#Angle8Unit.set_i2c_address "Link to this definition") Set a new I2C address for the device. Parameters: **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The new I2C address (1 to 127). UIFLOW2: > ![set_i2c_address.png](https://static-cdn.m5stack.com/mpy_docs/unit/8angle/set_i2c_address.png) Angle8Unit.readfrommem(_reg_, _num_)[](#Angle8Unit.readfrommem "Link to this definition") Read a specified number of bytes from a device register. Parameters: * **reg** – The register address to read from. * **num** – The number of bytes to read. --- # PLC I/O — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * PLC I/O * [View page source](../_sources/hardware/plcio.rst.txt) * * * PLC I/O[](#plc-i-o "Link to this heading") ============================================ PLC I/O is used to control the Input/Output (I/O) Capabilities of host devices. The following are the host’s support for PLC I/O functions: | Controller | Digital Input | Relay | | --- | --- | --- | | StampPLC | ✔ | ✔ | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Digital input control relay[](#digital-input-control-relay "Link to this heading") Open the [stamplc\_plcio\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/plcio/stamplc_plcio_example.m5f2) project in UiFlow2. This example shows how to control a relay using a digital input. UiFlow2 Code Block: > ![stamplc_plcio_example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/plcio/stamplc_plcio_example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Digital input control relay[](#id1 "Link to this heading") This example shows how to control a relay using a digital input. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from hardware import DigitalInput > 9from hardware import Relay > 10 > 11 > 12label0 \= None > 13digitalinput\_0 \= None > 14digitalinput\_1 \= None > 15digitalinput\_2 \= None > 16digitalinput\_3 \= None > 17relay\_0 \= None > 18relay\_1 \= None > 19relay\_2 \= None > 20relay\_3 \= None > 21 > 22 > 23def digitalinput\_0\_falling\_event(args): > 24 global \\ > 25 label0, \\ > 26 digitalinput\_0, \\ > 27 digitalinput\_1, \\ > 28 digitalinput\_2, \\ > 29 digitalinput\_3, \\ > 30 relay\_0, \\ > 31 relay\_1, \\ > 32 relay\_2, \\ > 33 relay\_3 > 34 relay\_0.on() > 35 > 36 > 37def digitalinput\_0\_rising\_event(args): > 38 global \\ > 39 label0, \\ > 40 digitalinput\_0, \\ > 41 digitalinput\_1, \\ > 42 digitalinput\_2, \\ > 43 digitalinput\_3, \\ > 44 relay\_0, \\ > 45 relay\_1, \\ > 46 relay\_2, \\ > 47 relay\_3 > 48 relay\_0.off() > 49 > 50 > 51def digitalinput\_1\_falling\_event(args): > 52 global \\ > 53 label0, \\ > 54 digitalinput\_0, \\ > 55 digitalinput\_1, \\ > 56 digitalinput\_2, \\ > 57 digitalinput\_3, \\ > 58 relay\_0, \\ > 59 relay\_1, \\ > 60 relay\_2, \\ > 61 relay\_3 > 62 relay\_1.on() > 63 > 64 > 65def digitalinput\_1\_rising\_event(args): > 66 global \\ > 67 label0, \\ > 68 digitalinput\_0, \\ > 69 digitalinput\_1, \\ > 70 digitalinput\_2, \\ > 71 digitalinput\_3, \\ > 72 relay\_0, \\ > 73 relay\_1, \\ > 74 relay\_2, \\ > 75 relay\_3 > 76 relay\_1.off() > 77 > 78 > 79def digitalinput\_2\_falling\_event(args): > 80 global \\ > 81 label0, \\ > 82 digitalinput\_0, \\ > 83 digitalinput\_1, \\ > 84 digitalinput\_2, \\ > 85 digitalinput\_3, \\ > 86 relay\_0, \\ > 87 relay\_1, \\ > 88 relay\_2, \\ > 89 relay\_3 > 90 relay\_2.on() > 91 > 92 > 93def digitalinput\_2\_rising\_event(args): > 94 global \\ > 95 label0, \\ > 96 digitalinput\_0, \\ > 97 digitalinput\_1, \\ > 98 digitalinput\_2, \\ > 99 digitalinput\_3, \\ > 100 relay\_0, \\ > 101 relay\_1, \\ > 102 relay\_2, \\ > 103 relay\_3 > 104 relay\_2.off() > 105 > 106 > 107def digitalinput\_3\_falling\_event(args): > 108 global \\ > 109 label0, \\ > 110 digitalinput\_0, \\ > 111 digitalinput\_1, \\ > 112 digitalinput\_2, \\ > 113 digitalinput\_3, \\ > 114 relay\_0, \\ > 115 relay\_1, \\ > 116 relay\_2, \\ > 117 relay\_3 > 118 relay\_3.on() > 119 > 120 > 121def digitalinput\_3\_rising\_event(args): > 122 global \\ > 123 label0, \\ > 124 digitalinput\_0, \\ > 125 digitalinput\_1, \\ > 126 digitalinput\_2, \\ > 127 digitalinput\_3, \\ > 128 relay\_0, \\ > 129 relay\_1, \\ > 130 relay\_2, \\ > 131 relay\_3 > 132 relay\_3.off() > 133 > 134 > 135def setup(): > 136 global \\ > 137 label0, \\ > 138 digitalinput\_0, \\ > 139 digitalinput\_1, \\ > 140 digitalinput\_2, \\ > 141 digitalinput\_3, \\ > 142 relay\_0, \\ > 143 relay\_1, \\ > 144 relay\_2, \\ > 145 relay\_3 > 146 > 147 M5.begin() > 148 label0 \= Widgets.Label("label0", 20, 2, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 149 > 150 digitalinput\_0 \= DigitalInput(1) > 151 digitalinput\_0.irq(digitalinput\_0\_falling\_event, digitalinput\_0.IRQ\_FALLING) > 152 digitalinput\_0.irq(digitalinput\_0\_rising\_event, digitalinput\_0.IRQ\_RISING) > 153 digitalinput\_1 \= DigitalInput(2) > 154 digitalinput\_1.irq(digitalinput\_1\_falling\_event, digitalinput\_1.IRQ\_FALLING) > 155 digitalinput\_1.irq(digitalinput\_1\_rising\_event, digitalinput\_1.IRQ\_RISING) > 156 digitalinput\_2 \= DigitalInput(3) > 157 digitalinput\_2.irq(digitalinput\_2\_falling\_event, digitalinput\_2.IRQ\_FALLING) > 158 digitalinput\_2.irq(digitalinput\_2\_rising\_event, digitalinput\_2.IRQ\_RISING) > 159 digitalinput\_3 \= DigitalInput(4) > 160 digitalinput\_3.irq(digitalinput\_3\_falling\_event, digitalinput\_3.IRQ\_FALLING) > 161 digitalinput\_3.irq(digitalinput\_3\_rising\_event, digitalinput\_3.IRQ\_RISING) > 162 relay\_0 \= Relay(1) > 163 relay\_1 \= Relay(2) > 164 relay\_2 \= Relay(3) > 165 relay\_3 \= Relay(4) > 166 > 167 > 168def loop(): > 169 global \\ > 170 label0, \\ > 171 digitalinput\_0, \\ > 172 digitalinput\_1, \\ > 173 digitalinput\_2, \\ > 174 digitalinput\_3, \\ > 175 relay\_0, \\ > 176 relay\_1, \\ > 177 relay\_2, \\ > 178 relay\_3 > 179 M5.update() > 180 > 181 > 182if \_\_name\_\_ \== "\_\_main\_\_": > 183 try: > 184 setup() > 185 while True: > 186 loop() > 187 except (Exception, KeyboardInterrupt) as e: > 188 try: > 189 from utility import print\_error\_msg > 190 > 191 print\_error\_msg(e) > 192 except ImportError: > 193 print("please update to latest firmware") Example output: > None API[](#api "Link to this heading") ------------------------------------ * [Digital Input](plcio.digitalinput.html) * [Relay](plcio.relay.html) --- # Atomic HDriver Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic HDriver Base * [View page source](../_sources/base/hdriver.rst.txt) * * * Atomic HDriver Base[](#atomic-hdriver-base "Link to this heading") ==================================================================== Support the following products: > [![Atomic HDriver Base](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20H-Driver%20Base/img-ee0353ff-f8a5-40c0-929e-455844999d21.webp)](https://docs.m5stack.com/zh_CN/atom/Atomic%20H-Driver%20Base) UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### Motor speed control[](#motor-speed-control "Link to this heading") Open the [atoms3r\_hdriver\_base\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/hdriver/atoms3r_hdriver_base_example.m5f2) project in UiFlow2. The example demonstrates the motor speed changing from low to high, high to low, and then reversing, changing from low to high and high to low. UiFlow2 Code Block: > ![atoms3r_hdriver_base_example.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### Motor speed control[](#id1 "Link to this heading") The example demonstrates the motor speed changing from low to high, high to low, and then reversing, changing from low to high and high to low. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import AtomicHDriverBase > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15label\_vol \= None > 16label\_speed \= None > 17base\_hdriver \= None > 18i \= None > 19speed \= None > 20 > 21 > 22def setup(): > 23 global title0, label0, label1, label\_vol, label\_speed, base\_hdriver, speed, i > 24 M5.begin() > 25 title0 \= Widgets.Title("Speed Ctrl", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 26 label0 \= Widgets.Label("speed:", 5, 65, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 27 label1 \= Widgets.Label("vol:", 5, 35, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 28 label\_vol \= Widgets.Label("12.0V", 45, 35, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 29 label\_speed \= Widgets.Label("0", 70, 65, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 30 base\_hdriver \= AtomicHDriverBase(6, 7, 5, 8, 1000) > 31 label\_vol.setText(str((str((base\_hdriver.get\_voltage())) + str("V")))) > 32 speed \= 0 > 33 > 34 > 35def loop(): > 36 global title0, label0, label1, label\_vol, label\_speed, base\_hdriver, speed, i > 37 M5.update() > 38 for i in range(50): > 39 speed \= i > 40 base\_hdriver.set\_speed(speed) > 41 label\_speed.setText(str(speed)) > 42 time.sleep\_ms(40) > 43 for i in range(50): > 44 speed \= 50 \- i > 45 base\_hdriver.set\_speed(speed) > 46 label\_speed.setText(str(speed)) > 47 time.sleep\_ms(40) > 48 for i in range(50): > 49 speed \= 1 \- i > 50 base\_hdriver.set\_speed(speed) > 51 label\_speed.setText(str(speed)) > 52 time.sleep\_ms(40) > 53 for i in range(50): > 54 speed \= i \- 50 > 55 base\_hdriver.set\_speed(speed) > 56 label\_speed.setText(str(speed)) > 57 time.sleep\_ms(40) > 58 > 59 > 60if \_\_name\_\_ \== "\_\_main\_\_": > 61 try: > 62 setup() > 63 while True: > 64 loop() > 65 except (Exception, KeyboardInterrupt) as e: > 66 try: > 67 from utility import print\_error\_msg > 68 > 69 print\_error\_msg(e) > 70 except ImportError: > 71 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### AtomicHDriverBase[](#atomichdriverbase "Link to this heading") _class_ base.hdriver.AtomicHDriverBase(_in1\=6_, _in2\=7_, _fault\=5_, _vin\=8_, _freq\=1000_)[](#base.hdriver.AtomicHDriverBase "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an AtomicHDriverBase object. Parameters: * **in1** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – PWM control pin1. * **in2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – PWM control pin2. * **fault** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – driver status. * **vin** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – driver input voltage detect. * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/init.png) MicroPython Code Block: > from base import AtomicHDriverBase > > base\_hdriver \= AtomicHDriverBase(in1 \= 6, in2 \= 7, fault \= 5, vin \= 8, freq \= 1000) get\_freq()[](#base.hdriver.AtomicHDriverBase.get_freq "Link to this definition") Get PWM frequency. Returns: PWM frequency. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_freq.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/get_freq.png) MicroPython Code Block: > base\_hdriver.get\_freq() get\_status()[](#base.hdriver.AtomicHDriverBase.get_status "Link to this definition") Get driver status. Returns: The driver status. Returns True if the driver is operating normally, or False if a fault is detected. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![get_status.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/get_status.png) MicroPython Code Block: > base\_hdriver.get\_status() get\_voltage()[](#base.hdriver.AtomicHDriverBase.get_voltage "Link to this definition") Get voltage. Returns: The driver input voltage. unit: V Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") UiFlow2 Code Block: > ![get_voltage.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/get_voltage.png) MicroPython Code Block: > base\_hdriver.get\_voltage() set\_freq(_freq\=1000_)[](#base.hdriver.AtomicHDriverBase.set_freq "Link to this definition") Set PWM frequency. Parameters: **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency. Default is 1000. Return type: None UiFlow2 Code Block: > ![set_freq.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/set_freq.png) MicroPython Code Block: > base\_hdriver.set\_freq() set\_speed(_speed\=0_)[](#base.hdriver.AtomicHDriverBase.set_speed "Link to this definition") Set motor speed. Parameters: **speed** ([_float_](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") ) – The motor speed. Range -100~100. Default is 0. Return type: None UiFlow2 Code Block: > ![set_speed.png](https://static-cdn.m5stack.com/mpy_docs/base/hdriver/set_speed.png) MicroPython Code Block: > base\_hdriver.set\_speed() --- # ASR Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * ASR Unit * [View page source](../_sources/units/asr.rst.txt) * * * ASR Unit[](#asr-unit "Link to this heading") ============================================== **Unit ASR** is an **AI** offline speech recognition unit, featuring the built-in AI smart offline speech module **CI-03T**. This unit offers powerful functions such as speech recognition, voiceprint recognition, speech enhancement, and speech detection. It supports AEC (Acoustic Echo Cancellation) to effectively eliminate echoes and noise interference, improving the accuracy of speech recognition. Additionally, it supports mid-speech interruption, allowing for flexible interruption during the recognition process and quick response to new commands. The product is pre-configured with wake-up words and feedback commands at the factory. The device uses **UART** serial communication for data transmission and also supports waking up the device via UART or voice keywords. This unit supports user customization of the **wake-up** recognition word and can recognize up to 300 command words. It is equipped with a **microphone** for clear audio capture and includes a **speaker** for high-quality audio feedback. This product is widely used in AI assistants, smart homes, security monitoring, automotive systems, robotics, smart hardware, healthcare, and other fields, making it an ideal choice for realizing smart voice interactions. Support the following products: [![ASRUnit](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/635/U914_01.webp)](https://docs.m5stack.com/en/unit/asr) UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### ASR Example[](#asr-example "Link to this heading") Open the [asr\_cores3\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/asr/asr_cores3_example.m5f2) project in UiFlow2. This example shows how to use Unit ASR to get the current command word, command number, and trigger an event when you say hello to do something you want to do. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/example.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### ASR Example[](#id1 "Link to this heading") This example shows how to use Unit ASR to get the current command word, command number, and trigger an event when you say hello to do something you want to do. MicroPython Code Block: > 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 unit import ASRUnit > 9 > 10 > 11title0 \= None > 12label0 \= None > 13label1 \= None > 14label2 \= None > 15label3 \= None > 16asr\_0 \= None > 17 > 18 > 19def asr\_0\_hello\_event(args): > 20 global title0, label0, label1, label2, label3, asr\_0 > 21 print("Rec Hello") > 22 > 23 > 24def setup(): > 25 global title0, label0, label1, label2, label3, asr\_0 > 26 > 27 M5.begin() > 28 Widgets.fillScreen(0x222222) > 29 title0 \= Widgets.Title( > 30 "UnitASR M5CoreSe Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 31 ) > 32 label0 \= Widgets.Label("msg:", 0, 51, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 33 label1 \= Widgets.Label("rec cmd num:", 0, 93, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 34 label2 \= Widgets.Label( > 35 "rec cmd word:", 0, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 36 ) > 37 label3 \= Widgets.Label( > 38 "rec cmd handler state:", 0, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 39 ) > 40 > 41 asr\_0 \= ASRUnit(2, port\=(1, 2)) > 42 print(asr\_0.search\_command\_num("hello")) > 43 print(asr\_0.search\_command\_word(0x32)) > 44 asr\_0.add\_command\_word(0x32, "hello", asr\_0\_hello\_event) > 45 > 46 > 47def loop(): > 48 global title0, label0, label1, label2, label3, asr\_0 > 49 M5.update() > 50 if asr\_0.get\_received\_status(): > 51 label0.setText(str((str("msg:") + str((asr\_0.get\_current\_raw\_message()))))) > 52 label1.setText(str((str("rec cmd num:") + str((asr\_0.get\_current\_command\_num()))))) > 53 label2.setText(str((str("rec cmd word:") + str((asr\_0.get\_current\_command\_word()))))) > 54 label3.setText(str((str("rec cmd handler state:") + str((asr\_0.get\_command\_handler()))))) > 55 > 56 > 57if \_\_name\_\_ \== "\_\_main\_\_": > 58 try: > 59 setup() > 60 while True: > 61 loop() > 62 except (Exception, KeyboardInterrupt) as e: > 63 try: > 64 from utility import print\_error\_msg > 65 > 66 print\_error\_msg(e) > 67 except ImportError: > 68 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### ASRUnit[](#asrunit "Link to this heading") _class_ unit.asr.ASRUnit(_id\=1_, _port\=None_, _verbose\=False_)[](#unit.asr.ASRUnit "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Voice recognition hardware module. Parameters: * **id** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – UART port ID for communication. Default is 1. * **port** ([_list_](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)") _|_[_tuple_](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)") ) – Tuple containing TX and RX pin numbers. * **verbose** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/init.png) MicroPython Code Block: > from unit import ASRUnit > > \# Initialize with UART1, TX on pin 2, RX on pin 1 > asr \= ASRUnit(id\=1, port\=(1, 2)) get\_received\_status()[](#unit.asr.ASRUnit.get_received_status "Link to this definition") Get message reception status. Returns: True if a message is received, False otherwise. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![get_received_status.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_received_status.png) MicroPython Code Block: > asr.get\_received\_status() send\_message(_command\_num_)[](#unit.asr.ASRUnit.send_message "Link to this definition") Send command via UART. Parameters: **command\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Command number to send (0-255) Return type: None UiFlow2 Code Block: > ![send_message.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/send_message.png) MicroPython Code Block: > asr.send\_message(0x30) get\_current\_raw\_message()[](#unit.asr.ASRUnit.get_current_raw_message "Link to this definition") Get the raw message received in hexadecimal format. Returns: The raw message as a string in hexadecimal format. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_current_raw_message.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_current_raw_message.png) MicroPython Code Block: > asr.get\_current\_raw\_message() get\_current\_command\_word()[](#unit.asr.ASRUnit.get_current_command_word "Link to this definition") Get the command word corresponding to the current command number. Returns: The command word as a string. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_current_command_word.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_current_command_word.png) MicroPython Code Block: > asr.get\_current\_command\_word() get\_current\_command\_num()[](#unit.asr.ASRUnit.get_current_command_num "Link to this definition") Get the current command number. Returns: The current command number as a string. Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![get_current_command_num.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_current_command_num.png) MicroPython Code Block: > asr.get\_current\_command\_num() get\_command\_handler()[](#unit.asr.ASRUnit.get_command_handler "Link to this definition") Check if the current command has an associated handler. Returns: True if the command has an associated handler, False otherwise. Return type: [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") UiFlow2 Code Block: > ![get_command_handler.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_command_handler.png) MicroPython Code Block: > asr.get\_command\_handler() add\_command\_word(_command\_num_, _command\_word_, _event\_handler\=None_)[](#unit.asr.ASRUnit.add_command_word "Link to this definition") Register custom command and handler. Parameters: * **command\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Command number (0-255) * **command\_word** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Voice command text * **event\_handler** (_callable_) – Handler function Return type: None UiFlow2 Code Block: > ![add_command_word.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/add_command_word.png) MicroPython Code Block: > def custom\_handler(unit): > print("Custom command detected!") > > asr.add\_command\_word(0x50, "custom command", custom\_handler) remove\_command\_word(_command\_word_)[](#unit.asr.ASRUnit.remove_command_word "Link to this definition") Remove a command word from the command list by its word. Parameters: **command\_word** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Command word to remove Return type: None UiFlow2 Code Block: > ![remove_command_word.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/remove_command_word.png) MicroPython Code Block: > asr.remove\_command\_word("custom command") search\_command\_num(_command\_word_)[](#unit.asr.ASRUnit.search_command_num "Link to this definition") Search for the command number associated with a command word. Parameters: **command\_word** ([_str_](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") ) – Command word to search for Returns: The command number if found, otherwise -1 Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![search_command_num.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/search_command_num.png) MicroPython Code Block: > asr.search\_command\_num("custom command") search\_command\_word(_command\_num_)[](#unit.asr.ASRUnit.search_command_word "Link to this definition") Search for the command word associated with a command number. Parameters: **command\_num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – Command number to search for Returns: The command word if found, otherwise “Unknown command word” Return type: [str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") UiFlow2 Code Block: > ![search_command_word.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/search_command_word.png) MicroPython Code Block: > asr.search\_command\_word(0x50) get\_command\_list()[](#unit.asr.ASRUnit.get_command_list "Link to this definition") Get the list of all commands and their associated handlers. Returns: A dictionary of command numbers and their corresponding command words and handlers. Return type: [dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)") UiFlow2 Code Block: > ![get_command_list.png](https://static-cdn.m5stack.com/mpy_docs/unit/asr/get_command_list.png) MicroPython Code Block: > asr.get\_command\_list() check\_tick\_callback()[](#unit.asr.ASRUnit.check_tick_callback "Link to this definition") Check if a handler is defined for the current command and schedule its execution. Returns: The handler if defined, otherwise None Return type: None MicroPython Code Block: > asr.check\_tick\_callback() --- # PWR485 — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * PWR485 * [View page source](../_sources/hardware/pwr485.rst.txt) * * * PWR485[](#pwr485 "Link to this heading") ========================================== The PWR485 is a RS485 interface that can be used to communicate with other devices. The following are the host’s support for PWR485: | Controller | Status | | --- | --- | | StampPLC | ✔ | UiFlow2 Example[](#uiflow2-example "Link to this heading") ------------------------------------------------------------ ### Echo[](#echo "Link to this heading") Open the [stamplc\_ehco\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/pwr485/stamplc_ehco_example.m5f2) project in UiFlow2. This example demonstrates how to utilize PWR485 interfaces by echoing back to the sender any data received on configured PWR485. By pressing different keys, different characters are sent. UiFlow2 Code Block: > ![stamplc_ehco_example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pwr485/example_echo.png) Example output: > None MicroPython Example[](#micropython-example "Link to this heading") -------------------------------------------------------------------- ### Echo[](#id1 "Link to this heading") This example demonstrates how to utilize PWR485 interfaces by echoing back to the sender any data received on configured PWR485. By pressing different keys, different characters are sent. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from hardware import PWR485 > 9from unit import ISO485Unit > 10 > 11 > 12label0 \= None > 13pwr485\_0 \= None > 14iso485\_0 \= None > 15 > 16 > 17def btnA\_wasClicked\_event(state): \# noqa: N802 > 18 global label0, pwr485\_0, iso485\_0 > 19 pwr485\_0.write("A") > 20 > 21 > 22def btnB\_wasClicked\_event(state): \# noqa: N802 > 23 global label0, pwr485\_0, iso485\_0 > 24 pwr485\_0.write("B") > 25 > 26 > 27def btnC\_wasClicked\_event(state): \# noqa: N802 > 28 global label0, pwr485\_0, iso485\_0 > 29 pwr485\_0.write("C") > 30 > 31 > 32def setup(): > 33 global label0, pwr485\_0, iso485\_0 > 34 > 35 M5.begin() > 36 label0 \= Widgets.Label("label0", 69, 61, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) > 37 > 38 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 39 BtnB.setCallback(type\=BtnB.CB\_TYPE.WAS\_CLICKED, cb\=btnB\_wasClicked\_event) > 40 BtnC.setCallback(type\=BtnC.CB\_TYPE.WAS\_CLICKED, cb\=btnC\_wasClicked\_event) > 41 > 42 pwr485\_0 \= PWR485( > 43 2, > 44 baudrate\=115200, > 45 bits\=8, > 46 parity\=None, > 47 stop\=1, > 48 tx\=0, > 49 rx\=39, > 50 rts\=46, > 51 mode\=PWR485.MODE\_RS485\_HALF\_DUPLEX, > 52 ) > 53 iso485\_0 \= ISO485Unit( > 54 1, > 55 port\=(4, 5), > 56 baudrate\=115200, > 57 bits\=8, > 58 parity\=None, > 59 stop\=1, > 60 txbuf\=256, > 61 rxbuf\=256, > 62 timeout\=0, > 63 timeout\_char\=0, > 64 invert\=0, > 65 flow\=0, > 66 ) > 67 > 68 > 69def loop(): > 70 global label0, pwr485\_0, iso485\_0 > 71 M5.update() > 72 if iso485\_0.any(): > 73 label0.setText(str(iso485\_0.read())) > 74 > 75 > 76if \_\_name\_\_ \== "\_\_main\_\_": > 77 try: > 78 setup() > 79 while True: > 80 loop() > 81 except (Exception, KeyboardInterrupt) as e: > 82 try: > 83 from utility import print\_error\_msg > 84 > 85 print\_error\_msg(e) > 86 except ImportError: > 87 print("please update to latest firmware") Example output: > None MicroPython Example[](#id2 "Link to this heading") ---------------------------------------------------- **API**[](#api "Link to this heading") ---------------------------------------- ### class PWR485[](#class-pwr485 "Link to this heading") _class_ hardware.pwr485.PWR485(_id_, _\*\*kwargs_)[](#hardware.pwr485.PWR485 "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Construct a PWR485 object of the given id. PWR485 class inherits UART class, See [hardware.UART](uart.html#hardware-uart) for more details. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/pwr485/init.png) MicroPython Code Block: > from hadrware import PWR485 > > pwr485\_0 \= PWR485(2, baudrate\=115200, bits\=8, parity\=None, stop\=1, tx\=0, rx\=39, rts\=46, mode\=PWR485.MODE\_RS485\_HALF\_DUPLEX) --- # BPS Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * BPS Unit * [View page source](../_sources/units/bps.rst.txt) * * * BPS Unit[](#bps-unit "Link to this heading") ============================================== The Barometric Pressure Sensor(BPS) `BPS Unit` is a barometer unit that uses Bosch BMP280 pressure sensor(BPS) or QMP6988 barometric pressure sensor(BPS V1.1) to measure atmospheric pressure, temperature and altitude estimation. Support the following products: > | | | > | --- | --- | > | [![BPSUnit](https://static-cdn.m5stack.com/resource/docs/products/unit/bps/bps_01.webp)](https://docs.m5stack.com/en/unit/bps) | [![BPSUnit_V11](https://static-cdn.m5stack.com/resource/docs/products/unit/BPS(QMP6988)/img-61abcaeb-6126-4445-ba9c-10599ee0411c.webp)](https://docs.m5stack.com/en/unit/BPS(QMP6988)) | Micropython Example: import os, sys, io import M5 from M5 import \* from hardware import \* from unit import BPSUnit import time i2c0 \= I2C(0, scl\=Pin(1), sda\=Pin(2), freq\=100000) bps\_0 \= BPSUnit(i2c0) while True: print((str('Temperature: ') + str((bps\_0.get\_temperature())))) print((str('Pressure: ') + str((bps\_0.get\_pressure())))) print((str('Altitude: ') + str((bps\_0.get\_altitude())))) time.sleep(0.5) UIFLOW2 Example: > ![unit-bps-demo.png](https://static-cdn.m5stack.com/mpy_docs/unit/bps/example.png) [unit-bps-demo.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/bps/unit-bps-demo.m5f2) class BPSUnit[](#class-bpsunit "Link to this heading") -------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ BPSUnit(_i2c_)[](#BPSUnit "Link to this definition") Create a BPSUnit object Parameters: **i2c** – the I2C object. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/bps/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- BPSUnit.get\_temperature()[](#BPSUnit.get_temperature "Link to this definition") Get the temperature value in degrees celsius from the BMP280 or QMP6988 sensor. * Return: `float`: -40 ~ +85 °C UIFLOW2: > ![get_temperature.png](https://static-cdn.m5stack.com/mpy_docs/unit/bps/get_temperature.png) BPSUnit.get\_pressure()[](#BPSUnit.get_pressure "Link to this definition") Get the pressure value in pascals from the BMP280 or QMP6988 sensor. * Return: `float`: 300 ~ 1100 hPa UIFLOW2: > ![get_pressure.png](https://static-cdn.m5stack.com/mpy_docs/unit/bps/get_pressure.png) BPSUnit.get\_altitude()[](#BPSUnit.get_altitude "Link to this definition") Get the altitude can be estimated using the pressure. which approximates the altitude relative to the pressure difference. The standard sea-level pressure is 1013.25 hPa. * Return: `float`: altitude in meters UIFLOW2: > ![get_altitude.png](https://static-cdn.m5stack.com/mpy_docs/unit/bps/get_altitude.png) --- # Atomic Motion Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic Motion Base * [View page source](../_sources/base/motion.rst.txt) * * * Atomic Motion Base[](#atomic-motion-base "Link to this heading") ================================================================== Atomic Motion Base is a servo and DC motor driver designed specifically for the ATOM series controllers. It integrates an STM32 control chip internally and uses I2C communication for control. Atomic Motion Base provides 4 servo channels and 2 DC motor interfaces, offering convenience for scenarios that require control of multiple servos or motor drivers, such as multi-axis servo robotic arms or small car motor control. Atomic Motion Base v1.1 adds INA226 to implement current and voltage detection. Support the following products: > | | | > | --- | --- | > | [![Motion](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20Motion%20Base/img-40a0d2ba-04b3-4aa3-8417-0624762b3cc3.webp)](https://docs.m5stack.com/en/atom/Atomic%20Motion%20Base) | [![Motion Base v1.1](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1124/A090-V11_01.webp)](https://docs.m5stack.com/en/atom/Atomic%20Motion%20Base%20v1.1) | UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### Motion Base[](#motion-base "Link to this heading") Open the [atoms3\_lite\_motion\_base\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/motion/atoms3_lite_motion_base_example.m5f2) project in UiFlow2. This example controls the servo to rotate to a specified angle and sets the motor to rotate. UiFlow2 Code Block: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/example.png) Example output: > None ### Motion Base v1.1[](#motion-base-v1-1 "Link to this heading") Open the [atoms3\_motion\_base\_v1.1\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/motion/atoms3_motion_base_v1.1_example.m5f2) project in UiFlow2. The example program switches the motor’s running speed when the screen button is pressed, and the screen displays the current, voltage, and power. UiFlow2 Code Block: > ![motion_base_v1.1_example.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/motion_base_v1.1_example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### Motion Base[](#id1 "Link to this heading") This example controls the servo to rotate to a specified angle and sets the motor to rotate. MicroPython Code Block: > 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 base import Motion > 10 > 11 > 12i2c0 \= None > 13motion \= None > 14 > 15 > 16def setup(): > 17 global i2c0, motion > 18 > 19 M5.begin() > 20 i2c0 \= I2C(0, scl\=Pin(39), sda\=Pin(38), freq\=100000) > 21 motion \= Motion(i2c0, 0x38) > 22 motion.set\_servo\_angle(1, 70) > 23 motion.set\_motor\_speed(1, 46) > 24 print(motion.get\_servo\_angle(1)) > 25 > 26 > 27def loop(): > 28 global i2c0, motion > 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") Example output: > None ### Motion Base v1.1[](#id2 "Link to this heading") The example program switches the motor’s running speed when the screen button is pressed, and the screen displays the current, voltage, and power. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 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 base import Motion > 11import time > 12 > 13 > 14label\_speed \= None > 15title\_e \= None > 16label\_vol \= None > 17label\_cur \= None > 18label\_pow \= None > 19i2c0 \= None > 20motion \= None > 21speed \= None > 22voltage \= None > 23curent \= None > 24last\_time \= None > 25power \= None > 26 > 27 > 28def btnA\_wasClicked\_event(state): > 29 global \\ > 30 label\_speed, \\ > 31 title\_e, \\ > 32 label\_vol, \\ > 33 label\_cur, \\ > 34 label\_pow, \\ > 35 i2c0, \\ > 36 motion, \\ > 37 speed, \\ > 38 voltage, \\ > 39 curent, \\ > 40 last\_time, \\ > 41 power > 42 speed \= speed + 20 > 43 if speed \> 120: > 44 speed \= 0 > 45 motion.set\_motor\_speed(1, speed) > 46 label\_speed.setText(str((str("speed: ") + str(speed)))) > 47 > 48 > 49def setup(): > 50 global \\ > 51 label\_speed, \\ > 52 title\_e, \\ > 53 label\_vol, \\ > 54 label\_cur, \\ > 55 label\_pow, \\ > 56 i2c0, \\ > 57 motion, \\ > 58 speed, \\ > 59 voltage, \\ > 60 curent, \\ > 61 last\_time, \\ > 62 power > 63 M5.begin() > 64 label\_speed \= Widgets.Label("speed:", 5, 27, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 65 title\_e \= Widgets.Title("Motor Ctrl", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 66 label\_vol \= Widgets.Label("vol:", 5, 55, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 67 label\_cur \= Widgets.Label("cur:", 5, 75, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 68 label\_pow \= Widgets.Label("pow:", 5, 95, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 69 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 70 i2c0 \= I2C(0, scl\=Pin(39), sda\=Pin(38), freq\=100000) > 71 motion \= Motion(i2c0, 0x38) > 72 last\_time \= time.ticks\_us() > 73 speed \= 0 > 74 label\_speed.setText(str((str("speed: ") + str(speed)))) > 75 > 76 > 77def loop(): > 78 global \\ > 79 label\_speed, \\ > 80 title\_e, \\ > 81 label\_vol, \\ > 82 label\_cur, \\ > 83 label\_pow, \\ > 84 i2c0, \\ > 85 motion, \\ > 86 speed, \\ > 87 voltage, \\ > 88 curent, \\ > 89 last\_time, \\ > 90 power > 91 M5.update() > 92 voltage \= motion.read\_voltage() > 93 curent \= motion.read\_current() > 94 power \= motion.read\_power() > 95 label\_vol.setText(str((str("vol: ") + str(voltage)))) > 96 label\_cur.setText(str((str("cur: ") + str(curent)))) > 97 label\_pow.setText(str((str("pow: ") + str(power)))) > 98 > 99 > 100if \_\_name\_\_ \== "\_\_main\_\_": > 101 try: > 102 setup() > 103 while True: > 104 loop() > 105 except (Exception, KeyboardInterrupt) as e: > 106 try: > 107 from utility import print\_error\_msg > 108 > 109 print\_error\_msg(e) > 110 except ImportError: > 111 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### Motion[](#motion "Link to this heading") _class_ base.motion.Motion(_i2c_, _address\=0x38_)[](#base.motion.Motion "Link to this definition") Create an Motion object. Parameters: * **i2c** (_I2C_) – The I2C port to use. * **address** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The device address. Default is 0x38. UiFlow2 Code Block: > ![__init__.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/init.png) MicroPython Code Block: > from base import Motion > from machine import I2C > > i2c0 \= I2C(0, scl\=Pin(39), sda\=Pin(38), freq\=100000) > motion \= Motion(i2c0, 0x38) get\_servo\_angle(_ch_)[](#base.motion.Motion.get_servo_angle "Link to this definition") Get the angle of the servo. Parameters: **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo channel. Range: 1~4. Returns: Specify the servo angle for the specified channel. Range: 0~180. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_servo_angle.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/get_servo_angle.png) MicroPython Code Block: > motion.get\_servo\_angle() set\_servo\_angle(_ch_, _angle_)[](#base.motion.Motion.set_servo_angle "Link to this definition") Set the angle of the servo. Parameters: * **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo channel. Range: 1~4. * **angle** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo angle. Range: 0~180. UiFlow2 Code Block: > ![set_servo_angle.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/set_servo_angle.png) MicroPython Code Block: > motion.set\_servo\_angle() get\_servo\_pulse(_ch_)[](#base.motion.Motion.get_servo_pulse "Link to this definition") Get the pulse of the servo. Parameters: **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo channel. Range: 1~4. Returns: Specify the servo pulse for the specified channel. Range: 500~2500. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_servo_pulse.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/get_servo_pulse.png) MicroPython Code Block: > motion.get\_servo\_pulse() write\_servo\_pulse(_ch_, _pulse_)[](#base.motion.Motion.write_servo_pulse "Link to this definition") Write the pulse of the servo. Parameters: * **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo channel. Range: 1~4. * **pulse** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The servo pulse. Range: 500~2500. UiFlow2 Code Block: > ![write_servo_pulse.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/write_servo_pulse.png) MicroPython Code Block: > motion.write\_servo\_pulse() get\_motor\_speed(_ch_)[](#base.motion.Motion.get_motor_speed "Link to this definition") Get the speed of the motor. Parameters: **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor channel. Range: 1~2. Returns: Specify the speed for the specified channel. Range: -127~127. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_motor_speed.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/get_motor_speed.png) MicroPython Code Block: > motion.get\_motor\_speed() set\_motor\_speed(_ch_, _speed_)[](#base.motion.Motion.set_motor_speed "Link to this definition") Set motor speed. Parameters: * **ch** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor channel. Range: 1~2. * **speed** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The motor speed. Range: -127~127. UiFlow2 Code Block: > ![set_motor_speed.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/set_motor_speed.png) MicroPython Code Block: > motion.set\_motor\_speed() read\_voltage()[](#base.motion.Motion.read_voltage "Link to this definition") Read voltage (unit: V). Returns: The voltage value in volts. Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") Note This method is supported only on Motion Base v1.1 and later versions. UiFlow2 Code Block: > ![read_voltage.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/read_voltage.png) MicroPython Code Block: > motion.read\_voltage() read\_current()[](#base.motion.Motion.read_current "Link to this definition") Read current (unit: A). Returns: The current value in amperes. Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") Note This method is supported only on Motion Base v1.1 and later versions. UiFlow2 Code Block: > ![read_current.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/read_current.png) MicroPython Code Block: > motion.read\_current() read\_power()[](#base.motion.Motion.read_power "Link to this definition") Read power (unit: W). Returns: The power value in watts. Return type: [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") Note This method is supported only on Motion Base v1.1 and later versions. UiFlow2 Code Block: > ![read_power.png](https://static-cdn.m5stack.com/mpy_docs/base/motion/read_power.png) MicroPython Code Block: > motion.read\_power() --- # Atomic PWM Base — UIFlow2 Programming Guide master documentation * [](../index.html) * [Base](index.html) * Atomic PWM Base * [View page source](../_sources/base/pwm.rst.txt) * * * Atomic PWM Base[](#atomic-pwm-base "Link to this heading") ============================================================ Support the following products: > [![Atomic PWM Base](https://static-cdn.m5stack.com/resource/docs/products/atom/Atomic%20PWM%20Base/img-44bfbe9c-c370-4bfd-b439-8cfd0bf3fd6d.webp)](https://docs.m5stack.com/zh_CN/atom/Atomic%20PWM%20Base) UiFlow2 Example:[](#uiflow2-example "Link to this heading") ------------------------------------------------------------- ### PWM output control[](#pwm-output-control "Link to this heading") Open the [atoms3r\_pwm\_base\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/base/pwm/atoms3r_pwm_base_example.m5f2) project in UiFlow2. The example demonstrates controlling the PWM signal’s duty cycle to fluctuate between low to high and high to low. UiFlow2 Code Block: > ![atoms3r_pwm_base_example.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/example.png) Example output: > None MicroPython Example:[](#micropython-example "Link to this heading") --------------------------------------------------------------------- ### PWM output control[](#id1 "Link to this heading") The example demonstrates controlling the PWM signal’s duty cycle to fluctuate between low to high and high to low. MicroPython Code Block: > 1\# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD > 2# > 3\# SPDX-License-Identifier: MIT > 4 > 5import os, sys, io > 6import M5 > 7from M5 import \* > 8from base import AtomicPWMBase > 9import time > 10 > 11 > 12title0 \= None > 13label0 \= None > 14label1 \= None > 15label\_freq \= None > 16label\_duty \= None > 17base\_pwm \= None > 18i \= None > 19 > 20 > 21def setup(): > 22 global title0, label0, label1, label\_freq, label\_duty, base\_pwm, i > 23 M5.begin() > 24 title0 \= Widgets.Title("PWM Control", 0, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) > 25 label0 \= Widgets.Label("freq:", 1, 35, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 26 label1 \= Widgets.Label("duty:", 2, 65, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 27 label\_freq \= Widgets.Label("1000Hz", 47, 35, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 28 label\_duty \= Widgets.Label("0", 55, 65, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18) > 29 base\_pwm \= AtomicPWMBase(5, 1000) > 30 label\_freq.setText(str((str((base\_pwm.get\_freq())) + str("Hz")))) > 31 > 32 > 33def loop(): > 34 global title0, label0, label1, label\_freq, label\_duty, base\_pwm, i > 35 M5.update() > 36 for i in range(100): > 37 base\_pwm.set\_duty\_u16(i \* 150) > 38 label\_duty.setText(str(base\_pwm.get\_duty\_u16())) > 39 time.sleep\_ms(40) > 40 for i in range(100): > 41 base\_pwm.set\_duty\_u16(15000 \- i \* 150) > 42 label\_duty.setText(str(base\_pwm.get\_duty\_u16())) > 43 time.sleep\_ms(40) > 44 > 45 > 46if \_\_name\_\_ \== "\_\_main\_\_": > 47 try: > 48 setup() > 49 while True: > 50 loop() > 51 except (Exception, KeyboardInterrupt) as e: > 52 try: > 53 from utility import print\_error\_msg > 54 > 55 print\_error\_msg(e) > 56 except ImportError: > 57 print("please update to latest firmware") Example output: > None **API**[](#api "Link to this heading") ---------------------------------------- ### PWM[](#pwm "Link to this heading") _class_ base.pwm.AtomicPWMBase(_out\_pin\=5_, _freq\=1000_)[](#base.pwm.AtomicPWMBase "Link to this definition") Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)") Create an AtomicPWMBase object. Parameters: * **out\_pin** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM output pin. Default is 5. * **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency. Default is 1000. UiFlow2 Code Block: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/init.png) MicroPython Code Block: > from base import AtomicPWMBase > > base\_pwm \= AtomicPWMBase(out\_pin\=5, freq\=1000) get\_duty\_u16()[](#base.pwm.AtomicPWMBase.get_duty_u16 "Link to this definition") Get PWM duty cycle. Returns: PWM duty cycle. Range: 0~65535. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_duty_u16.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/get_duty_u16.png) MicroPython Code Block: > base\_pwm.get\_duty\_u16() get\_freq()[](#base.pwm.AtomicPWMBase.get_freq "Link to this definition") Get PWM frequency. Returns: PWM frequency. Return type: [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") UiFlow2 Code Block: > ![get_freq.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/get_freq.png) MicroPython Code Block: > base\_pwm.get\_freq() set\_duty\_u16(_duty\=0_)[](#base.pwm.AtomicPWMBase.set_duty_u16 "Link to this definition") Set PWM duty cycle. set the current duty cycle of the PWM output, as an unsigned 16-bit value in the range 0 to 65535 inclusive. Parameters: **duty** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM duty cycle. Range: 0 ~ 65535. Default is 0. UiFlow2 Code Block: > ![set_duty_u16.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/set_duty_u16.png) MicroPython Code Block: > base\_pwm.set\_duty\_u16() set\_freq(_freq\=1000_)[](#base.pwm.AtomicPWMBase.set_freq "Link to this definition") Set PWM frequency. Parameters: **freq** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The PWM frequency. Default is 1000. Return type: None UiFlow2 Code Block: > ![set_freq.png](https://static-cdn.m5stack.com/mpy_docs/base/pwm/set_freq.png) MicroPython Code Block: > base\_pwm.set\_freq() --- # Rotary — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * Rotary * [View page source](../_sources/hardware/rotary.rst.txt) * * * Rotary[](#rotary "Link to this heading") ========================================== Rotary is used to control the rotary encoder integrated inside the host. Below is the detailed Rotary support for the host: | Controller | Rotary | | --- | --- | | Dial | ✔ | | DinMeter | ✔ | 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 \* > 9 > 10 > 11label0 \= None > 12rotary \= None > 13 > 14 > 15def btnA\_wasClicked\_event(state): \# noqa: N802 > 16 global label0, rotary > 17 rotary.reset\_rotary\_value() > 18 label0.setText(str(rotary.get\_rotary\_value())) > 19 > 20 > 21def setup(): > 22 global label0, rotary > 23 > 24 M5.begin() > 25 Widgets.fillScreen(0x222222) > 26 label0 \= Widgets.Label("0", 96, 80, 1.0, 0xFFA000, 0x222222, Widgets.FONTS.DejaVu72) > 27 > 28 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 29 > 30 rotary \= Rotary() > 31 > 32 > 33def loop(): > 34 global label0, rotary > 35 M5.update() > 36 if rotary.get\_rotary\_status(): > 37 label0.setText(str(rotary.get\_rotary\_value())) > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/example.png) [dial\_rotary\_example.m5f2](https://uiflow2.m5stack.com/?pkey=7a1c8a20e6ef4a51acce65d794a7681c) class Rotary[](#class-rotary "Link to this heading") ------------------------------------------------------ Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ Rotary[](#Rotary "Link to this definition") Creates a Rotary object. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- Rotary.get\_rotary\_status() → [bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") [](#Rotary.get_rotary_status "Link to this definition") Gets the rotation status of the Rotary object. UIFLOW2: > ![get_rotary_status.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/get_rotary_status.png) Rotary.get\_rotary\_value() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Rotary.get_rotary_value "Link to this definition") Note Cannot be used simultaneously with [`Rotary.get_rotary_increments()`](#Rotary.get_rotary_increments "Rotary.get_rotary_increments") . Gets the rotation value of the Rotary object. UIFLOW2: > ![get_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/get_rotary_value.png) Rotary.get\_rotary\_increments() → [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") [](#Rotary.get_rotary_increments "Link to this definition") Note Cannot be used simultaneously with [`Rotary.get_rotary_increments()`](#Rotary.get_rotary_increments "Rotary.get_rotary_increments") . Gets the rotation increment of the Rotary object. Can be used to determine the direction of rotation. UIFLOW2: > ![get_rotary_increments.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/get_rotary_increments.png) Rotary.reset\_rotary\_value() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Rotary.reset_rotary_value "Link to this definition") Resets the rotation value of the Rotary object. UIFLOW2: > ![reset_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/reset_rotary_value.png) Rotary.set\_rotary\_value() → [None](https://docs.python.org/3/library/constants.html#None "(in Python v3.13)") [](#Rotary.set_rotary_value "Link to this definition") Sets the rotation value of the Rotary object. UIFLOW2: > ![set_rotary_value.png](https://static-cdn.m5stack.com/mpy_docs/hardware/rotary/set_rotary_value.png) --- # Button Unit — UIFlow2 Programming Guide master documentation * [](../index.html) * [Unit](index.html) * Button Unit * [View page source](../_sources/units/button.rst.txt) * * * Button Unit[](#button-unit "Link to this heading") ==================================================== BUTTON is a single button Unit. The button status can be detected by the input pin by simply capturing the high/low electrical level. If the button is pressed, the signal level will be _high_ if the button is released, the signal level will be _low_. Support the following products: [![ButtonUnit](https://static-cdn.m5stack.com/resource/docs/products/unit/button/button_01.webp)](https://docs.m5stack.com/en/unit/button) 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 unit import ButtonUnit > 9 > 10 > 11title0 \= None > 12label1 \= None > 13label0 \= None > 14button\_0 \= None > 15 > 16 > 17def setup(): > 18 global title0, label1, label0, button\_0 > 19 > 20 M5.begin() > 21 Widgets.fillScreen(0x222222) > 22 title0 \= Widgets.Title( > 23 "ButtonUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 > 24 ) > 25 label1 \= Widgets.Label( > 26 "Button State:", 395, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 27 ) > 28 label0 \= Widgets.Label( > 29 "Button Counter Value:", 1, 102, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 > 30 ) > 31 > 32 button\_0 \= ButtonUnit((33, 32), True, type\=2) > 33 > 34 > 35def loop(): > 36 global title0, label1, label0, button\_0 > 37 M5.update() > 38 label0.setText(str((str("Button Counter Value:") + str((button\_0.count\_value))))) > 39 > 40 > 41if \_\_name\_\_ \== "\_\_main\_\_": > 42 try: > 43 setup() > 44 while True: > 45 loop() > 46 except (Exception, KeyboardInterrupt) as e: > 47 try: > 48 from utility import print\_error\_msg > 49 > 50 print\_error\_msg(e) > 51 except ImportError: > 52 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/example.png) [button\_core2\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/button/button_core2_example.m5f2) class ButtonUnit[](#class-buttonunit "Link to this heading") -------------------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ ButtonUnit(_pin\_num_, _active\_low_, _pullup\_active_)[](#ButtonUnit "Link to this definition") Initialize a Button instance with the specified pin, active-low configuration, and pull-up resistor state. Parameters: * **pin\_num** – The GPIO pin number connected to the button. * **active\_low** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Determines whether the button signal is active-low. Default is True. * **pullup\_active** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Specifies whether the internal pull-up resistor is enabled. Default is True. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- ButtonUnit.count\_reset()[](#ButtonUnit.count_reset "Link to this definition") Reset the count value to zero. UIFLOW2: > ![count_reset.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/count_reset.png) ButtonUnit.isHolding()[](#ButtonUnit.isHolding "Link to this definition") Check if the button is currently being held. UIFLOW2: > ![isHolding.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/get_status.png) ButtonUnit.setCallback(_type_, _cb_)[](#ButtonUnit.setCallback "Link to this definition") Set a callback function for a specified button event type. Parameters: * **type** – The event type (e.g., WAS\_CLICKED, WAS\_DOUBLECLICKED). * **cb** – The callback function to be executed for the event. UIFLOW2: > ![setCallback.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/callback.png) ButtonUnit.tick(_pin_)[](#ButtonUnit.tick "Link to this definition") Monitor the state transitions of a button based on its pin state and trigger appropriate handlers. UIFLOW2: > ![tick.png](https://static-cdn.m5stack.com/mpy_docs/unit/button/tick.png) --- # SCD40 — UIFlow2 Programming Guide master documentation * [](../index.html) * [Hardware](index.html) * SCD40 * [View page source](../_sources/hardware/scd40.rst.txt) * * * SCD40[](#scd40 "Link to this heading") ======================================== The SCD4x is Sensirion’s next generation miniature CO2 sensor. On-chip signal compensation is realized with the build-in SHT4x humidity and temperature sensor. The specific support of the host for SCD40 is as follows: | Controller | SCD40 | | --- | --- | | AirQ | ✔ | 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 \* > 9 > 10 > 11label0 \= None > 12rotary \= None > 13 > 14 > 15def btnA\_wasClicked\_event(state): \# noqa: N802 > 16 global label0, rotary > 17 rotary.reset\_rotary\_value() > 18 label0.setText(str(rotary.get\_rotary\_value())) > 19 > 20 > 21def setup(): > 22 global label0, rotary > 23 > 24 M5.begin() > 25 Widgets.fillScreen(0x222222) > 26 label0 \= Widgets.Label("0", 96, 80, 1.0, 0xFFA000, 0x222222, Widgets.FONTS.DejaVu72) > 27 > 28 BtnA.setCallback(type\=BtnA.CB\_TYPE.WAS\_CLICKED, cb\=btnA\_wasClicked\_event) > 29 > 30 rotary \= Rotary() > 31 > 32 > 33def loop(): > 34 global label0, rotary > 35 M5.update() > 36 if rotary.get\_rotary\_status(): > 37 label0.setText(str(rotary.get\_rotary\_value())) > 38 > 39 > 40if \_\_name\_\_ \== "\_\_main\_\_": > 41 try: > 42 setup() > 43 while True: > 44 loop() > 45 except (Exception, KeyboardInterrupt) as e: > 46 try: > 47 from utility import print\_error\_msg > 48 > 49 print\_error\_msg(e) > 50 except ImportError: > 51 print("please update to latest firmware") UIFLOW2 Example: > ![example.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/example.png) [airq\_scd40\_example.m5f2](https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/hardware/scd40/airq_scd40_example.m5f2) class SCD40[](#class-scd40 "Link to this heading") ---------------------------------------------------- Constructors[](#constructors "Link to this heading") ------------------------------------------------------ _class_ SCD40[](#SCD40 "Link to this definition") Initialize the SCD40 with the I2C interface and address. UIFLOW2: > ![init.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/init.png) Methods[](#methods "Link to this heading") -------------------------------------------- SCD40.available()[](#SCD40.available "Link to this definition") Check if the SCD40 sensor is available on the I2C bus. SCD40.set\_start\_periodic\_measurement()[](#SCD40.set_start_periodic_measurement "Link to this definition") Set the sensor into working mode, which takes about 5 seconds per measurement. UIFLOW2: > ![set_start_periodic_measurement.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_start_periodic_measurement.png) SCD40.set\_stop\_periodic\_measurement()[](#SCD40.set_stop_periodic_measurement "Link to this definition") Stop the measurement mode for the sensor. UIFLOW2: > ![set_stop_periodic_measurement.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_stop_periodic_measurement.png) SCD40.get\_sensor\_measurement()[](#SCD40.get_sensor_measurement "Link to this definition") Get temperature, humidity, and CO2 concentration from the sensor. SCD40.is\_data\_ready()[](#SCD40.is_data_ready "Link to this definition") Check if the data (temperature, humidity, CO2) is ready from the sensor. UIFLOW2: > ![is_data_ready.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/is_data_ready.png) SCD40.get\_temperature\_offset()[](#SCD40.get_temperature_offset "Link to this definition") Get the temperature offset to be added to the reported measurements. UIFLOW2: > ![get_temperature_offset.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/get_temperature_offset.png) SCD40.set\_temperature\_offset(_offset_)[](#SCD40.set_temperature_offset "Link to this definition") Set the maximum value of 374°C temperature offset. Parameters: **offset** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The temperature offset to set, default is 0. UIFLOW2: > ![set_temperature_offset.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_temperature_offset.png) SCD40.get\_sensor\_altitude()[](#SCD40.get_sensor_altitude "Link to this definition") Get the altitude value of the measurement location in meters above sea level. UIFLOW2: > ![get_sensor_altitude.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/get_sensor_altitude.png) SCD40.set\_sensor\_altitude(_height_)[](#SCD40.set_sensor_altitude "Link to this definition") Set the altitude value of the measurement location in meters above sea level. Parameters: **height** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The altitude in meters to set. Must be between 0 and 65535 meters. UIFLOW2: > ![set_sensor_altitude.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_sensor_altitude.png) SCD40.set\_ambient\_pressure(_ambient\_pressure_)[](#SCD40.set_ambient_pressure "Link to this definition") Set the ambient pressure in hPa at any time to adjust CO2 calculations. Parameters: **ambient\_pressure** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The ambient pressure in hPa, constrained to the range \[0, 65535\]. UIFLOW2: > ![set_ambient_pressure.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_ambient_pressure.png) SCD40.set\_force\_calibration(_target\_co2_)[](#SCD40.set_force_calibration "Link to this definition") Force the sensor to recalibrate with a given current CO2 level. Parameters: **target\_co2** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The current CO2 concentration to be used for recalibration. UIFLOW2: > ![set_force_calibration.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_force_calibration.png) SCD40.get\_calibration\_enabled()[](#SCD40.get_calibration_enabled "Link to this definition") Get whether automatic self-calibration (ASC) is enabled or disabled. UIFLOW2: > ![get_calibration_enabled.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/get_calibration_enabled.png) SCD40.set\_calibration\_enabled(_enabled_)[](#SCD40.set_calibration_enabled "Link to this definition") Enable or disable automatic self-calibration (ASC). Parameters: **enabled** ([_bool_](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)") ) – Set to True to enable ASC, or False to disable it. UIFLOW2: > ![set_calibration_enabled.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_calibration_enabled.png) SCD40.set\_start\_low\_periodic\_measurement()[](#SCD40.set_start_low_periodic_measurement "Link to this definition") Set the sensor into low power working mode, with about 30 seconds per measurement. UIFLOW2: > ![set_start_low_periodic_measurement.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_start_low_periodic_measurement.png) SCD40.data\_isready()[](#SCD40.data_isready "Link to this definition") Check if new data is available from the sensor. SCD40.save\_to\_eeprom()[](#SCD40.save_to_eeprom "Link to this definition") Save temperature offset, altitude offset, and self-calibration enable settings to EEPROM. UIFLOW2: > ![save_to_eeprom.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/save_to_eeprom.png) SCD40.get\_serial\_number()[](#SCD40.get_serial_number "Link to this definition") Get a unique serial number for this sensor. UIFLOW2: > ![get_serial_number.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/get_serial_number.png) SCD40.set\_self\_test()[](#SCD40.set_self_test "Link to this definition") Perform a self-test, which can take up to 10 seconds. UIFLOW2: > ![set_self_test.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_self_test.png) SCD40.set\_factory\_reset()[](#SCD40.set_factory_reset "Link to this definition") Reset all configuration settings stored in the EEPROM and erase the FRC and ASC algorithm history. UIFLOW2: > ![set_factory_reset.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/set_factory_reset.png) SCD40.reinit()[](#SCD40.reinit "Link to this definition") Reinitialize the sensor by reloading user settings from EEPROM. UIFLOW2: > ![reinit.png](https://static-cdn.m5stack.com/mpy_docs/hardware/scd40/reinit.png) SCD40.set\_single\_shot\_measurement\_all()[](#SCD40.set_single_shot_measurement_all "Link to this definition") Set the sensor to perform a single-shot measurement for CO2, humidity, and temperature. SCD40.set\_single\_shot\_measurement\_ht()[](#SCD40.set_single_shot_measurement_ht "Link to this definition") Set the sensor to perform a single-shot measurement for humidity and temperature. SCD40.set\_sleep\_mode()[](#SCD40.set_sleep_mode "Link to this definition") Put the sensor into sleep mode to reduce current consumption. SCD40.set\_wake\_up()[](#SCD40.set_wake_up "Link to this definition") Wake up the sensor from sleep mode into idle mode. SCD40.write\_cmd(_cmd\_wr_, _value_)[](#SCD40.write_cmd "Link to this definition") Write a command to the sensor. Parameters: * **cmd\_wr** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The command to write to the sensor. * **value** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The value to send with the command, if any. SCD40.read\_response(_num_)[](#SCD40.read_response "Link to this definition") Read the sensor’s response. Parameters: **num** ([_int_](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") ) – The number of bytes to read from the sensor. SCD40.check\_crc(_buf_)[](#SCD40.check_crc "Link to this definition") Check the CRC of the received data to ensure it is correct. Parameters: **buf** ([_bytearray_](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.13)") ) – The buffer of bytes to check the CRC. SCD40.crc8(_buffer_)[](#SCD40.crc8 "Link to this definition") Calculate the CRC-8 checksum for a given buffer. Parameters: **buffer** ([_bytearray_](https://docs.python.org/3/library/stdtypes.html#bytearray "(in Python v3.13)") ) – The buffer of bytes to calculate the CRC for. ---