### USB Driver Installation Guide Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/quick-reference/get-started.rst Instructions for installing USB drivers required for M5Stack devices. It details the different driver versions (CP210X and CH9102) and provides links for Windows, macOS, and Linux. ```text Driver name Applicable driver chip Download link ========================= ======================= ========================= CP210x_VCP_Windows CP2104 |CP210x_VCP_Windows|_ ------------------------- ----------------------- ------------------------- CP210x_VCP_MacOS CP2104 |CP210x_VCP_MacOS|_ ------------------------- ----------------------- ------------------------- CP210x_VCP_Linux CP2104 |CP210x_VCP_Linux|_ ------------------------- ----------------------- ------------------------- CH9102_VCP_SER_Windows CH9102 |CH9102_VCP_SER_Windows|_ ------------------------- ----------------------- ------------------------- CH9102_VCP_SER_MacOS v1.7 CH9102 |CH9102_VCP_MacOS_v1.7|_ ========================= ``` -------------------------------- ### RDM GET and SET Request Examples Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Demonstrates how to send RDM GET and SET requests for device information and DMX start address. It shows the usage of `rdm_send_get_device_info` and `rdm_send_set_dmx_start_address`, including how to handle the response using `rdm_ack_t` and print UIDs with `UIDSTR` and `UID2STR`. ```c rdm_uid_t dest_uid = {0x05e0, 0x44c06fbf}; // The destination UID rdm_sub_device_t sub_device = RDM_SUB_DEVICE_ROOT; rdm_ack_t ack; // Stores response information rdm_device_info_t device_info; // Stores the response parameter data. if (rdm_send_get_device_info(DMX_NUM_1, &dest_uid, sub_device, &device_info, &ack)) { printf("Successfully received device info from " UIDSTR "!\n", UID2STR(ack.src_uid)); } const uint16_t new_address = 123; // The new RDM_PID_DMX_START_ADDRESS to send. if (rdm_send_set_dmx_start_address(DMX_NUM_1, &dest_uid, sub_device, new_address, &ack)) { printf("Device " UIDSTR " has been set to DMX address %i.\n", UID2STR(dest_uid), new_address); } ``` -------------------------------- ### UiFlow2 UDP Client Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/software/udp.client.rst This snippet describes the UiFlow2 project setup for a UDP client. It involves opening a pre-defined project and configuring it to send data to a server. ```text Open the |cores3_udp_client_example.m5f2| project in UiFlow2. This example creates a UDP client that sends data to a server. ``` -------------------------------- ### M5Burner Software Download Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/quick-reference/get-started.rst Links to download the M5Burner firmware burning tool for various operating systems. Users should select the version corresponding to their OS. ```text Software Link ================ ============================= M5Burner_Windows |M5Burner-v3-beta-win-x64|_ ---------------- ----------------------------- M5Burner_MacOS |M5Burner-v3-beta-mac-x64|_ ---------------- ----------------------------- M5Burner_Linux |M5Burner-v3-beta-linux-x64|_ ================= ``` -------------------------------- ### DigiClock Unit Micropython Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/digi_clock.rst This Micropython example demonstrates how to use the DigiClock Unit to display information. It shows the basic setup and usage of the unit with the M5Stack CoreS3. ```python from machine import I2C from unit import DigiClockUnit import time i2c = I2C(0, scl=21, sda=22, freq=100000) digi_clock = DigiClockUnit(i2c) while True: current_time = time.localtime() hour = current_time[3] minute = current_time[4] second = current_time[5] time_str = "{:02d}{:02d}".format(hour, minute) # Set the time on the display digi_clock.set_string(time_str) # Toggle colon dots every second # digi_clock.set_raw(0b10000000, 2) # Turn on colon time.sleep(0.5) # digi_clock.set_raw(0, 2) # Turn off colon time.sleep(0.5) ``` -------------------------------- ### Micropython Setup and Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/unit/adc.rst This snippet shows how to set up and use the ADC Unit in Micropython. It includes importing necessary libraries, initializing the ADC, and a basic example of reading the voltage. ```micropython import os, sys, io import M5 from M5 import * import time from unit import * adc_0 = None def setup(): global adc_0 print(adc_0.get_voltage()) time.sleep(1) ``` -------------------------------- ### PlatformIO Library Installation Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Instructions for installing and using the esp_dmx library with the PlatformIO IDE. Includes notes on project structure for performance. ```platformio #include "esp_dmx.h" ``` -------------------------------- ### Install Environment Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/README.md Installs the necessary dependencies for building the documentation by installing from the requirements.txt file. ```shell pip3 install -r requirements.txt ``` -------------------------------- ### M5 BLE Server Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/hardware/m5ble.rst Demonstrates how to use the M5BLE library as a BLE server. It sets up services and characteristics, starts the server, and handles incoming data from clients. ```micropython import M5BLE import time import gc # server 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 ``` -------------------------------- ### DMX Driver Installation and Pin Configuration Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Initializes the DMX driver with default configuration and sets the communication pins (TX, RX, RTS). This is typically done in the setup or main function of your project. ```c const dmx_port_t dmx_num = DMX_NUM_1; // First, use the default DMX configuration... dmx_config_t config = DMX_CONFIG_DEFAULT; // ...declare the driver's DMX personalities... const int personality_count = 1; dmx_personality_t personalities[] = { {1, "Default Personality"} }; // ...install the DMX driver... dmx_driver_install(dmx_num, &config, personalities, personality_count); // ...and then set the communication pins! const int tx_pin = 17; const int rx_pin = 16; const int rts_pin = 21; dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin); ``` -------------------------------- ### Micropython KeyUnit Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/key.rst Example code demonstrating the usage of the KeyUnit in Micropython. This snippet shows how to initialize the unit and interact with its features. ```python from m5 import from unit import KeyUnit key = KeyUnit(port=(1, 1)) while True: if key.wasPressed(): key.set_color(0xff0000) elif key.wasReleased(): key.set_color(0x00ff00) if key.isHolding(): key.set_brightness(50) else: key.set_brightness(100) ``` -------------------------------- ### Class Documentation Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/contribute/template.rst Illustrates how to document a class, its constructor, methods, and properties, with placeholders for UIFlow and MicroPython code examples. ```APIDOC .. class:: Class1(arg1:int) Constructor. :param arg1: Parameter 1. :type arg1: int .. Please note that the type of the parameter needs to be specified .. method:: Class1.method1(arg1:int, arg2:int) -> int Method 1, please write a detailed description of the method. :param arg1: Parameter 1. :type arg1: int :param int arg2: Parameter 2. :type arg2: int :return: Return value. :rtype: int .. Please note that the return value type of the method needs to be specified. UiFlow2 Code Block: .. Please place the Blockly image of the function and delete this line when you are done. MicroPython Code Block: .. code-block:: python pass # Please put the MicroPython code of the function, and delete this line when you are done. .. property:: Class1.property1 :type: int Property 1, please write a detailed description of the property. .. Please note that the type of the property needs to be specified. UiFlow2 Code Block: .. Please place the Blockly image of the function and delete this line when you are done. MicroPython Code Block: .. code-block:: python pass # Please put the MicroPython code of the function, and delete this line when you are done .. staticmethod:: Class1.staticmethod1(arg1:int, arg2:int) -> int Static method 1, please write a detailed description of the static method. :param arg1: Parameter 1. :type arg1: int :param int arg2: Parameter 2. :type arg2: int ``` -------------------------------- ### LlmModule API Documentation Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/module/llm.rst Provides detailed API documentation for the LlmModule class, covering its constructors, methods for system control, LLM operations, audio setup, TTS setup, and KWS setup. Each method includes parameter descriptions, return types, and usage context. ```APIDOC class LlmModule: __init__() Initialize LlmModule and set up UART communication based on board type. update() -> None Update ModuleLLM, receive response message. check_connection() -> bool Check if the module connection is working properly. :return: True if module connection is OK, False otherwise. :rtype: bool get_response_msg_list() -> list Get the list of module's response messages. :return: List of response messages as dictionaries. :rtype: list clear_response_msg_list() -> None Clear the module's response message list. sys_ping() -> int Send a ping to the system and get the response code. sys_reset(wait_reset_finish=True) -> int Reset the system. :param bool wait_reset_finish: Whether to wait for reset completion. :return: Result of the reset command. :rtype: int sys_reboot() -> int Reboot the system. :return: Result of the reboot command. :rtype: int 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 Set up the LLM module. :param str prompt: The prompt text. :param str model: The model name. :param str response_format: The response format. :param str input: The input format. :param bool enoutput: Enable output. :param bool enkws: Enable keyword spotting. :param int max_token_len: Maximum token length. :param str request_id: Request ID. :return: Result of the setup command. :rtype: str llm_inference(work_id, input_data, request_id='llm_inference') -> str Perform inference with the LLM module. :param work_id: The work ID. :param input_data: The input data. :param str request_id: Request ID. :return: Result of the inference command. :rtype: str audio_setup(capcard=0, capdevice=0, cap_volume=0.5, playcard=0, playdevice=1, play_volume=0.15, request_id='audio_setup') -> str Set up the audio module. :param int capcard: Capture card index. :param int capdevice: Capture device index. :param float cap_volume: Capture volume. :param int playcard: Playback card index. :param int playdevice: Playback device index. :param float play_volume: Playback volume. :param str request_id: Request ID. :return: Result of the setup command. :rtype: str 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 Set up the TTS module. :param str model: TTS model name. :param str response_format: The response format. :param str input: The input format. :param bool enoutput: Enable output. :param bool enkws: Enable keyword spotting. :param str request_id: Request ID. :return: Result of the setup command. :rtype: str 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 Set up the KWS module. :param str kws: Keyword to detect. :param str model: KWS model name. :param str response_format: The response format. :param str input: The input format. :param bool enoutput: Enable output. :param str request_id: Request ID. :return: Result of the setup command. :rtype: str ``` -------------------------------- ### Micropython DMX512 Send Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/dmx.rst Example code demonstrating how to send DMX512 data using the M5Stack DMX512 Unit in MicroPython. This snippet covers the basic setup and data transmission. ```python from m5stack import * from m5stack_ui import * from uiflow import * import DMX512Unit app = App.create() dmx = DMX512Unit.DMX512Unit(id=0, port=speaker.PORT_A) dmx.dmx_init(mode=DMX512Unit.DMX_MASTER) # Set channel 1 to value 255 dmx.write_data(channel=1, data=255) # Set channel 2 to value 128 dmx.write_data(channel=2, data=128) # Set channel 3 to value 0 dmx.write_data(channel=3, data=0) while True: # Your code here time.sleep_ms(100) pass ``` -------------------------------- ### Micropython Example for Light Unit Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/unit/light.rst This example demonstrates how to initialize and use the Light Unit in Micropython. It sets up the Light Unit and prints its analog value. ```micropython import os, sys, io import M5 from M5 import * from unit import * light_0 = None def setup(): global light_0 light_0 = Light((8,9)) M5.begin() Widgets.fillScreen(0x222222) print(light_0.get_analog_value()) ``` -------------------------------- ### Take Photo Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/advanced/jpg.rst This example demonstrates how to take a photo using the JPG module. It includes instructions to click the screen to start a countdown and capture the image. This functionality is available in both Micropython and UIFlow 2.0. ```python from m5stack import * from m5stack_ui import * from uiflow import * import jpg import image app = App() label = Label("Click to take photo", color=0x000000, x=100, y=100) def button_pressed(): label.setText("Taking photo...") try: # Take a photo img = jpg.capture() # Encode the image to JPG jpg_img = jpg.encode(img, quality=80) # Save the JPG image (optional) # jpg_img.save("photo.jpg") label.setText("Photo taken successfully!") except Exception as e: label.setText(f"Error: {e}") button = Button(x=100, y=150, text="Take Photo", color=0xFFFFFF) button.onEvent(lambda btn, event: button_pressed() if event == 'press' else None) app.run() ``` -------------------------------- ### MicroPython Basic Keyboard Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/m5ui/keyboard.rst Demonstrates the creation and usage of a virtual keyboard in a MicroPython environment. This example focuses on connecting the keyboard to a text input area. ```python import lv # Assuming keyboard_0 and textarea_0 are already initialized # keyboard_0.set_textarea(textarea_0) def keyboard_0_value_changed_event(event_struct): print("Key pressed") def keyboard_0_ready_event(event_struct): print("Ready") def keyboard_0_event_handler(event_struct): event = event_struct.code if event == lv.EVENT.VALUE_CHANGED: keyboard_0_value_changed_event(event_struct) elif event == lv.EVENT.READY: keyboard_0_ready_event(event_struct) return keyboard_0.add_event_cb(keyboard_0_event_handler, lv.EVENT.ALL, None) # Example of setting a flag keyboard_0.set_flag(lv.obj.FLAG.HIDDEN, True) # Example of toggling a flag keyboard_0.toggle_flag(lv.obj.FLAG.HIDDEN) # Example of setting a state keyboard_0.set_state(lv.STATE.PRESSED, True) # Example of toggling a state keyboard_0.toggle_state(lv.STATE.PRESSED) # Example of getting the connected textarea ta = keyboard_0.get_textarea() ``` -------------------------------- ### ESP-IDF Library Installation Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Instructions for installing the esp_dmx library within the ESP-IDF framework. Requires ESP-IDF version 4.4.1 or newer. ```esp-idf #include "esp_dmx.h" ``` -------------------------------- ### Micropython DLight Setup and Usage Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/unit/dlight.rst This example demonstrates how to initialize the I2C port and the DLight unit, then print the detected light intensity (lux). It requires the M5, hardware, and unit libraries. ```micropython import os, sys, io import M5 from M5 import * from hardware import * from unit import * i2c0 = None dlight_0 = None def setup(): global i2c0, dlight_0 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) dlight_0 = DLight(i2c0) print(dlight_0.get_lux()) M5.begin() Widgets.fillScreen(0x222222) ``` -------------------------------- ### RDM Parameter Getters and Setters Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Demonstrates how to get and set DMX start addresses using the driver's RDM parameter functions. It shows error checking for both getter and setter operations. ```c uint16_t dmx_start_address; if (rdm_get_dmx_start_address(DMX_NUM_1, &dmx_start_address) == 0) { printf("An error occurred getting the DMX start address.\n"); } dmx_start_address = 123; if (!rdm_set_dmx_start_address(DMX_NUM_1, dmx_start_address)) { printf("An error occurred setting the DMX start address.\n"); } ``` -------------------------------- ### TMOS Unit Micropython Setup and Event Handling Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/tmos.rst This example demonstrates how to initialize the TMOS Unit, set up event callbacks for presence and motion detection, and display the sensor status on the M5Stack display. It includes functions for handling detection and non-detection events. ```micropython import os, sys, io import M5 from M5 import * from unit import TMOSUnit from hardware import * title0 = None label0 = None title1 = None title2 = None TMOSTest = None label1 = None label2 = None label3 = None i2c0 = None tmos_0 = None def tmos_0_presence_detect_event(arg): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 label1.setText(str((str("Prescence Flag:") + str((tmos_0.get_presence_state()))))) label0.setText(str((str("Prescence:") + str((tmos_0.get_presence_value()))))) def tmos_0_motion_detect_event(arg): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 label3.setText(str((str("Motion Flag:") + str((tmos_0.get_motion_state()))))) label2.setText(str((str("Motion:") + str((tmos_0.get_motion_value()))))) def tmos_0_presence_not_detected_event(arg): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 label1.setText(str((str("Prescence Flag:") + str((tmos_0.get_presence_state()))))) def tmos_0_motion_not_detected_event(arg): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 label3.setText(str((str("Motion Flag:") + str((tmos_0.get_motion_state()))))) def setup(): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 M5.begin() Widgets.fillScreen(0x222222) title0 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) label0 = Widgets.Label("Prescence:", 2, 65, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) title1 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) title2 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) TMOSTest = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) label1 = Widgets.Label( "Prescence Flag", 2, 98, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 ) label2 = Widgets.Label("Motion:", 2, 130, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) label3 = Widgets.Label("Motion Flag:", 2, 160, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) title0.setText("TMOS Test") tmos_0 = TMOSUnit(i2c0, 0x5A) tmos_0.set_callback(tmos_0_presence_detect_event, tmos_0.PRESENCE_DETECT) tmos_0.set_callback(tmos_0_motion_detect_event, tmos_0.MOTION_DETECT) tmos_0.set_callback(tmos_0_presence_not_detected_event, tmos_0.PRESENCE_NOT_DETECTED) tmos_0.set_callback(tmos_0_motion_not_detected_event, tmos_0.MOTION_NOT_DETECTED) label0.setText(str("Prescence:")) label1.setText(str("Prescence Flag:")) label2.setText(str("Motion:")) label3.setText(str("Motion Flag:")) print(tmos_0.get_gain_mode()) def loop(): global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0 M5.update() tmos_0.tick_callback() 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") ``` -------------------------------- ### Install DMX Driver Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Installs the DMX driver, allocating necessary resources and setting default timing. Requires specifying the DMX port, configuration, personalities, and personality count. ```c dmx_config_t config = DMX_CONFIG_DEFAULT; dmx_personality_t personalities[] = { {1, "Single-channel Mode"}, // Single-address DMX personality {3, "RGB"}, // Three-address RGB mode {4, "RGBW"}, // Four-address RGBW personality {7, "RGBW with Macros"} // RGBW with three additional macro parameters }; const int personality_count = 4; dmx_driver_install(DMX_NUM_1, &config, personalities, personality_count); ``` -------------------------------- ### Micropython Example for ENVPRO Unit Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/envpro.rst This snippet demonstrates how to use the ENVPRO Unit with Micropython. It covers initialization and basic sensor readings. Ensure the necessary libraries are installed. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit app = App() i2c = I2C(freq=100000, scl=Pin.GPIO21, sda=Pin.GPIO22) envpro = unit.get(unit.ENVPRO, i2c, 0x77) while True: temperature = envpro.get_temperature() humidity = envpro.get_humidity() pressure = envpro.get_pressure() gas_resistance = envpro.get_gas_resistance() altitude = envpro.get_altitude() print(f"Temperature: {temperature}°C") print(f"Humidity: {humidity}%") print(f"Pressure: {pressure}hPa") print(f"Gas Resistance: {gas_resistance} Ohms") print(f"Altitude: {altitude}m") time.sleep_ms(1000) ``` -------------------------------- ### MicroPython Example for CO2L Unit Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/co2l.rst This snippet demonstrates how to use the CO2LUnit in MicroPython to read CO2 concentration, temperature, and humidity. It includes initialization and periodic measurement setup. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit app = App.create() co2l_0 = unit.get(unit.CO2L, unit.PORTA) @app.route('/') def index(): label_temp = Label("Temp: N/A", color=0x000000, x=10, y=10, size=24) label_hum = Label("Hum: N/A", color=0x000000, x=10, y=40, size=24) label_co2 = Label("CO2: N/A", color=0x000000, x=10, y=70, size=24) while True: if co2l_0.is_data_ready(): temperature, humidity, co2 = co2l_0.get_sensor_measurement() label_temp.setText("Temp: {:.1f} C".format(temperature)) label_hum.setText("Hum: {:.1f} %".format(humidity)) label_co2.setText("CO2: {} ppm".format(co2)) wait_ms(1000) app.run() ``` -------------------------------- ### Arduino Library Installation Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/README.md Instructions for installing the esp_dmx library within the Arduino IDE framework. Requires Arduino-ESP32 framework version 2.0.3 or newer. ```arduino #include "esp_dmx.h" ``` -------------------------------- ### RDM DMX Setup Functions Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/keywords.txt Functions for configuring DMX settings on RDM devices, specifically for getting and setting the DMX start address. This allows remote configuration of DMX parameters. ```c rdm_send_get_dmx_start_address(dmx_port_t dmx_num, rdm_uid_t uid) rdm_send_set_dmx_start_address(dmx_port_t dmx_num, rdm_uid_t uid, int start_address) ``` -------------------------------- ### MicroPython MQTTPoE Unit Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/mqttpoe.rst Example code demonstrating how to initialize and use the MQTTPoEUnit for MQTT communication in MicroPython. It covers setting up the client, subscribing to a topic, and checking for messages. ```micropython import os, sys, io import M5 from M5 import * from unit import MQTTPoEUnit import time def mqtt_0_SubTopic_event(data): global mqttpoe_0 print(data[0]) print(data[1]) mqttpoe_0 = MQTTPoEUnit(port=(18, 17)) mqttpoe_0.set_client('m5-mqtt-2024', 'mqtt.m5stack.com', 1883, '', '', 120) mqttpoe_0.set_subscribe('SubTopic', mqtt_0_SubTopic_event, 0) mqttpoe_0.set_connect() while True: mqttpoe_0.check_msg() time.sleep_ms(50) ``` -------------------------------- ### HTTP GET Request Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/software/requests2.rst Demonstrates how to perform an HTTP GET request using the requests2 module in MicroPython. This example showcases basic usage for fetching data from a URL. ```python import requests2 url = "http://example.com/data" response = requests2.get(url) if response.status_code == 200: print("Data received:", response.text) else: print("Error fetching data:", response.status_code) ``` -------------------------------- ### MicroPython Display Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/module/display.rst This MicroPython code snippet demonstrates how to display text on the screen using the Display Module. It utilizes the DisplayModule class and assumes the necessary setup is done. ```python from module import display display_module = display.DisplayModule() # Example: Display text on the screen display_module.text("Display", 10, 10, 0xFFFFFF, 1, 1, False, False) # Note: Actual display update might require a specific function call depending on the library implementation. ``` -------------------------------- ### Micropython DAC Core Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/dac.rst Example code demonstrating the core functionality of the DAC Unit in Micropython. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit app = App() # DAC Unit Example dac_0 = unit.get(unit.DAC, unit.PORTA) app.add_button(text='Set DAC Value', x=50, y=50, w=200, h=50, color=0xFFFFFF, callback=lambda: dac_0.set_value(2048)) # Set DAC to mid-range (0-4095) app.add_button(text='Get DAC Value', x=50, y=120, w=200, h=50, color=0xFFFFFF, callback=lambda: print('DAC Value:', dac_0.get_value())) app.add_button(text='Set DAC Voltage', x=50, y=190, w=200, h=50, color=0xFFFFFF, callback=lambda: dac_0.set_voltage(1.65)) # Set DAC to 1.65V app.add_button(text='Get DAC Voltage', x=50, y=260, w=200, h=50, color=0xFFFFFF, callback=lambda: print('DAC Voltage:', dac_0.get_voltage())) app.run() ``` -------------------------------- ### Micropython Watering Unit Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/watering.rst An example demonstrating the usage of the WateringUnit in Micropython. This snippet shows how to initialize the unit and control the water pump. ```python from m5 import machine from m5stack_unit import WateringUnit import time # Initialize the WateringUnit # Assuming the unit is connected to port A (ADC: GPIO34, Pump: GPIO35) watering = WateringUnit(port=(34, 35)) print("Starting watering cycle...") # Turn on the pump for 5 seconds watering.on() time.sleep(5) # Turn off the pump watering.off() print("Watering cycle finished.") # Get sensor voltage voltage = watering.get_voltage() print(f"Sensor voltage: {voltage:.2f}V") # Get raw ADC value raw_value = watering.get_raw() print(f"Raw ADC value: {raw_value}") ``` -------------------------------- ### Micropython WDT Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/hardware/wdt.rst Example of how to use the Watchdog Timer in Micropython. This snippet demonstrates the basic setup and usage of the WDT to prevent system resets. ```python import time from machine import WDT # Initialize WDT with a timeout of 5 seconds (5000 ms) wdt = WDT(timeout=5000) print("WDT initialized. Feeding in 3 seconds...") time.sleep(3) # Feed the WDT to prevent reset wdt.feed() print("WDT fed.") print("Waiting for 7 seconds (WDT should reset the system)...") time.sleep(7) # This part of the code should not be reached if the WDT resets the system print("System did not reset. This should not happen.") ``` -------------------------------- ### MicroPython time Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/system/time.rst An example demonstrating the usage of the MicroPython time module, likely showcasing time-related functions and delays. ```python import time # Get current time in UTC utc_now = time.gmtime() print(f"UTC Time: {utc_now}") # Get current time in local time local_now = time.localtime() print(f"Local Time: {local_now}") # Convert local time tuple to seconds since epoch seconds_since_epoch = time.mktime(local_now) print(f"Seconds since Epoch: {seconds_since_epoch}") # Sleep for 1 second time.sleep(1) print("Slept for 1 second.") # Sleep for 500 milliseconds time.sleep_ms(500) print("Slept for 500 milliseconds.") # Sleep for 100 microseconds time.sleep_us(100) print("Slept for 100 microseconds.") # Get tick counts ticks_ms_val = time.ticks_ms() ticks_us_val = time.ticks_us() print(f"Ticks MS: {ticks_ms_val}") print(f"Ticks US: {ticks_us_val}") ``` -------------------------------- ### Micropython Example for OP90 Unit Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/unit/op90.rst This Micropython code demonstrates how to initialize and use the OP90 Unit. It includes setting up the I2C interface, creating an OPUnit object, and calling methods to get and reset count values. ```micropython import os, sys, io import M5 from M5 import * from hardware import * import time from unit import * i2c0 = None op90_0 = None def setup(): global i2c0, op90_0 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) op90_0 = OPUnit((8, 9), type=1) M5.begin() Widgets.fillScreen(0x222222) print(op90_0.get_value) time.sleep(1) print(op90_0.count_value) time.sleep(1) op90_0.count_reset() time.sleep(1) ``` -------------------------------- ### MicroPython Accel Unit Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/accel.rst This example demonstrates how to get the acceleration value from the Accel Unit and display it on the screen using MicroPython. ```python from m5 import * from unit import * import time accel = AccelUnit(port=PORTA) while True: x, y, z = accel.get_acceleration() print(f"X: {x:.2f}, Y: {y:.2f}, Z: {z:.2f}") time.sleep_ms(100) ``` -------------------------------- ### MicroPython Audio Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/system/audio.rst An example demonstrating the usage of the audio module in MicroPython, likely showcasing playback or recording functionalities on a CoreS3 board. ```python .. literalinclude:: ../../../examples/system/audio/cores3_audio_example.py :language: python :linenos: ``` -------------------------------- ### DMX Start Address Management Source: https://github.com/m5stack/uiflow-micropython/blob/master/m5stack/components/esp_dmx/keywords.txt Functions to get and set the DMX start address for a device. This is fundamental for assigning channels in a DMX universe. ```c dmx_get_start_address(dmx_port_t dmx_num) dmx_set_start_address(dmx_port_t dmx_num, int start_address) ``` -------------------------------- ### Micropython Zigbee RX Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/module/zigbee.rst Example code demonstrating how to receive data using the Zigbee module in Micropython. ```python .. literalinclude:: ../../../examples/module/zigbee/core2_zigbee_rx_example.py :language: python :linenos: ``` -------------------------------- ### Micropython Example for BLEUARTServer Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/system/bleuart.server.rst An example demonstrating the usage of the BLEUARTServer class in a Micropython environment. ```python .. literalinclude:: ../../../examples/system/bleuart/cores3_bleuart_server_example.py :language: python :linenos: ``` -------------------------------- ### Micropython FlashLight Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/flash_light.rst Example code demonstrating the usage of the FlashLightUnit in Micropython. This snippet shows how to initialize and control the flashlight. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit app = App.create() flash_light_0 = unit.get(unit.FLASH_LIGHT, unit.PORTA) @app.route('/') def menu(): label_0 = Label("cores3_flashlight_example", x=0, y=0, color=0x000000, text="cores3_flashlight_example") label_1 = Label("info", x=0, y=20, color=0x000000, text="cores3_flashlight_example") btn_1 = Button(x=100, y=100, w=100, h=50, label="flash") def btn_1_pressed(): flash_light_0.flash(FlashLightUnit.BRIGHTNESS_100, FlashLightUnit.TIME_220MS) btn_1.on_press(btn_1_pressed) label_2 = Label("info", x=0, y=40, color=0x000000, text="cores3_flashlight_example") btn_2 = Button(x=100, y=160, w=100, h=50, label="turn off") def btn_2_pressed(): flash_light_0.flash(FlashLightUnit.BRIGHTNESS_100, FlashLightUnit.TIME_220MS, turn_off=True) btn_2.on_press(btn_2_pressed) label_3 = Label("info", x=0, y=60, color=0x000000, text="cores3_flashlight_example") btn_3 = Button(x=100, y=220, w=100, h=50, label="constant") def btn_3_pressed(): flash_light_0.on(FlashLightUnit.BRIGHTNESS_100) btn_3.on_press(btn_3_pressed) label_4 = Label("info", x=0, y=80, color=0x000000, text="cores3_flashlight_example") btn_4 = Button(x=100, y=280, w=100, h=50, label="turn off") def btn_4_pressed(): flash_light_0.off() btn_4.on_press(btn_4_pressed) app.run() ``` -------------------------------- ### Setting up ESP-IDF Build Environment Source: https://github.com/m5stack/uiflow-micropython/blob/master/README.md This snippet outlines the commands to set up the ESP-IDF build environment. It involves creating a workspace, cloning the ESP-IDF repository, initializing submodules, installing the IDF, and exporting the environment variables. ```shell mkdir uiflow_workspace && cd uiflow_workspace git clone --depth 1 --branch v5.4.1 https://github.com/espressif/esp-idf.git git -C esp-idf submodule update --init --recursive ./esp-idf/install.sh . ./esp-idf/export.sh ``` -------------------------------- ### MicroPython UWB Anchor Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/uwb.rst Example code demonstrating how to use the UWB Unit as an anchor in a MicroPython environment. This snippet showcases basic setup and communication for positioning. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit import time # Initialize UWB Unit as an anchor # Assuming UWB unit is connected to UART port A (port=0) # Device mode is set to Anchor (1) # Device ID is set to 0 # Verbose output is enabled (True) uwb_0 = unit.get(unit.UWB, unit.PORTA) uwb_0.set_device_mode(unit.UWB.ANCHOR, 0) while True: # Update UWB data uwb_0.update() # Get distance from the first anchor (index 0) dist = uwb_0.get_distance(0) print(f"Distance to anchor 0: {dist} meters") time.sleep_ms(100) ``` -------------------------------- ### Driver Installation Links Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/zh_CN/quick-reference/index.rst Provides download links for USB drivers (CP210x and CH9102) for various operating systems. Users should download the driver matching their system and USB chip version. ```APIDOC CP210x_VCP_Windows: CP2104 |CP210x_VCP_Windows|_ CP210x_VCP_MacOS: CP2104 |CP210x_VCP_MacOS|_ CP210x_VCP_Linux: CP2104 |CP210x_VCP_Linux|_ CH9102_VCP_SER_Windows: CH9102 |CH9102_VCP_SER_Windows|_ CH9102_VCP_SER_MacOS v1.7: CH9102 |CH9102_VCP_MacOS_v1.7|_ ``` -------------------------------- ### LaserTX CoreS3 Example Source: https://github.com/m5stack/uiflow-micropython/blob/master/docs/en/units/laser_tx.rst Example demonstrating the usage of the LaserTX unit with the CoreS3 board in Python. ```python from m5stack import * from m5stack_ui import * from uiflow import * import unit app = App.create() laser_tx = unit.get(unit.LASER_TX, unit.PORTA) @app.add_event(buttonA) def buttonA_pressed(): laser_tx.write('Hello from LaserTX!') print('Data sent') @app.add_event(buttonB) def buttonB_pressed(): laser_tx.on() print('Laser ON') @app.add_event(buttonC) def buttonC_pressed(): laser_tx.off() print('Laser OFF') app.run() ```