### Basic RTSP Video Streaming Setup Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/video/rtsp_streaming.md Initializes the camera, sets up an RTSP server, binds the camera to it, and starts the stream. Use this for basic video-only streaming. ```python from maix import time, rtsp, camera, image server = rtsp.Rtsp() cam = camera.Camera(2560, 1440, image.Format.FMT_YVU420SP) server.bind_camera(cam) server.start() print(server.get_url()) while True: time.sleep(1) ``` -------------------------------- ### Deploy Local Package via Maixtool Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/app.md Start a local service on your PC to deploy a local package. This allows installation via QR code scanning on the device. Ensure `maixtool` is installed. ```shell maixtool deploy --pkg ``` -------------------------------- ### Full Keyword Recognition Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/keyword.md This is a complete example demonstrating keyword recognition setup and execution. It initializes the speech module, defines keywords and a callback, and enters a loop to process audio frames. ```python from maix import app, nn speech = nn.Speech("/root/models/am_3332_192_int8.mud") speech.init(nn.SpeechDevice.DEVICE_MIC) kw_tbl = ['xiao3 ai4 tong2 xue2', 'ni3 hao3', 'tian1 qi4 zen3 me yang4'] kw_gate = [0.1, 0.1, 0.1] def callback(data:list[float], len: int): for i in range(len): print(f"\tkw{i}: {data[i]:.3f};", end=' ') print("\n") speech.kws(kw_tbl, kw_gate, callback, True) while not app.need_exit(): frames = speech.run(1) if frames < 1: print("run out\n") break ``` -------------------------------- ### Camera and Display Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/README_no_screen.md This Python snippet initializes the display and camera, then continuously reads frames from the camera and displays them on the screen. It includes setup for display and camera objects and a loop to show camera feed until the application needs to exit. ```python from maix import camera, display, app disp = display.Display() # Create a display object and initialize the screen cam = camera.Camera(640, 480) # Create a camera object, manually setting the resolution to 640x480, and initialize the camera while not app.need_exit(): # Keep looping until the program exits (can exit by pressing the device's function button or clicking the stop button in MaixVision) img = cam.read() # Read the camera feed into the img variable, print(img) can be used to print img details disp.show(img) # Display img on the screen ``` -------------------------------- ### Initialize and Start WebRTC Server Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/video/webrtc_streaming.md Creates a WebRTC instance, binds the configured camera to it, and starts the streaming service. ```python server = webrtc.WebRTC() server.bind_camera(cam) server.start() ``` -------------------------------- ### Start Local Preview Server Source: https://github.com/sipeed/maixpy/blob/main/docs/README.md Start a local preview server for the documentation. Open http://127.0.0.1:2333 in your browser to view the docs. ```shell teedoc serve ``` -------------------------------- ### Initialize and Start RTSP Server Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/video/rtsp_streaming.md Creates an Rtsp server object, binds a camera to it, and starts the RTSP push stream. ```python server = rtsp.Rtsp() server.bind_camera(cam) server.start() ``` -------------------------------- ### Example Server Log Output Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/deploy_online_recognition.md This is an example of the log output when the Sherpa-ONNX server starts successfully, indicating the listening address and port. ```shell 2024-12-23 09:25:17,557 INFO [streaming_server.py:667] No certificate provided 2024-12-23 09:25:17,561 INFO [server.py:715] server listening on [::]:6006 2024-12-23 09:25:17,561 INFO [server.py:715] server listening on 0.0.0.0:6006 2024-12-23 09:25:17,561 INFO [streaming_server.py:693] Please visit one of the following addresses: http://localhost:6006 Since you are not providing a certificate, you cannot use your microphone from within the browser using public IP addresses. Only localhost can be used.You also cannot use 0.0.0.0 or 127.0.0.1 ``` -------------------------------- ### Install Doc Plugins Source: https://github.com/sipeed/maixpy/blob/main/docs/README.md Install plugins required for the MaixPy documentation. Navigate to the docs directory and run the teedoc install command. ```shell cd MaixPy/docs teedoc install ``` -------------------------------- ### Install Application via CLI Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/app.md Use this command to install an application package from the local file system. ```shell app_store_cli install ``` -------------------------------- ### Example Command for Generating MaixCAM System Image Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/pro/compile_os.md An example of how to execute the gen_os.sh script with specific file paths and arguments for building a MaixCAM-Pro system image. ```shell ./gen_os.sh '/home/xxx/.../LicheeRV-Nano-Build/install/soc_sg2002_licheervnano_sd/images/2024-08-13-14-43-0de38f.img' ../../dist/MaixPy-4.4.21-py3-none-any.whl '/home/xxx/.../maixcam_builtin_files' 0 maixcam-pro ``` -------------------------------- ### Install HuggingFace Hub Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/mllm/basic.md Install the huggingface_hub library using pip. This is a prerequisite for using HuggingFace download methods. ```shell pip install huggingface_hub ``` -------------------------------- ### YOLO11 Configuration Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/ai_model_converter/maixcam2.md Example JSON configuration file for YOLO11 models. Key parameters include calibration data and NPU mode settings. ```json # same as original ``` -------------------------------- ### Install axp-tools Source: https://github.com/sipeed/maixpy/blob/main/tools/os/maixcam2/axp-tools/README.md Install the axp-tools package using pip. ```shell pip install axp-tools ``` -------------------------------- ### Initialize I2C with SMBus Library Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/peripheral/i2c.md This example shows how to initialize an I2C bus using the `smbus` library, which can be used alongside MaixPy's `pinmap` for I2C communication. It requires installing `smbus` (`pip install smbus`) and configuring pins via `pinmap`. The `i2c_id` is determined based on the device model. ```python from maix import i2c, pinmap, sys, err import smbus # get pin and i2c number according to device id device_id = sys.device_id() if device_id == "maixcam2": scl_pin_name = "A1" scl_i2c_name = "I2C6_SCL" sda_pin_name = "A0" sda_i2c_name = "I2C6_SDA" i2c_id = 6 else: scl_pin_name = "A15" scl_i2c_name = "I2C5_SCL" sda_pin_name = "A27" sda_i2c_name = "I2C5_SDA" i2c_id = 5 # set pinmap err.check_raise(pinmap.set_pin_function(scl_pin_name, scl_i2c_name), "set pin failed") err.check_raise(pinmap.set_pin_function(sda_pin_name, sda_i2c_name), "set pin failed") bus = smbus.SMBus(i2c_id) ``` -------------------------------- ### Install MaixPy Wheel Package Source: https://github.com/sipeed/maixpy/blob/main/tools/maix_module/docs/doc/en/faq.md Use this command to install the MaixPy wheel package after uploading it to the device. Ensure the file path is correct. ```python import os os.system("pip install /root/xxx.whl") ``` -------------------------------- ### Install teedoc Source: https://github.com/sipeed/maixpy/blob/main/docs/README.md Install the teedoc documentation build tool using pip. This is a prerequisite for local documentation preview and building. ```shell pip install teedoc -U ``` -------------------------------- ### Initialize and Start WebRTC Streaming Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/video/webrtc_streaming.md This snippet initializes the camera, sets up the WebRTC server, binds the camera to the server, and starts the streaming service. The camera must be configured to output NV21 format for WebRTC compatibility. The original camera object should not be used after binding. ```python from maix import time, webrtc, camera, image cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP) server = webrtc.WebRTC() server.bind_camera(cam) server.start() print(server.get_url()) while True: time.sleep(1) ``` -------------------------------- ### Build and Install from Source with GPU Support Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/deploy_online_recognition.md If the pre-built package is unavailable or fails, build and install Sherpa-ONNX from source, enabling GPU support via CMake arguments. ```shell cd sherpa-onnx export SHERPA_ONNX_CMAKE_ARGS="-DSHERPA_ONNX_ENABLE_GPU=ON" python3 setup.py install ``` -------------------------------- ### Initialize and Start RTMP Stream Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/video/rtmp_streaming.md Creates an Rtmp object with server details, binds the camera, and starts the RTMP stream. The Camera object cannot be used after binding. ```python r = rtmp.Rtmp(host, port, app, stream, bitrate) r.bind_camera(cam) r.start() ``` -------------------------------- ### YOLO11 MUD File Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/ai_model_converter/maixcam2.md Example MUD file configuration for a YOLO11 model. The `[basic]` section is mandatory for loading the model. ```ini # same as previous MUD example ``` -------------------------------- ### MaixPy Line Tracking Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/line_tracking.md This example demonstrates how to capture images from the camera, detect lines using color thresholds, and draw the detected lines and their properties on the display. It requires initialization of camera and display modules. ```python from maix import camera, display, image cam = camera.Camera(320, 240) disp = display.Display() # thresholds = [[0, 80, 40, 80, 10, 80]] # red thresholds = [[0, 80, -120, -10, 0, 30]] # green # thresholds = [[0, 80, 30, 100, -120, -60]] # blue while 1: img = cam.read() lines = img.get_regression(thresholds, area_threshold = 100) for a in lines: img.draw_line(a.x1(), a.y1(), a.x2(), a.y2(), image.COLOR_GREEN, 2) theta = a.theta() rho = a.rho() if theta > 90: theta = 270 - theta else: theta = 90 - theta img.draw_string(0, 0, "theta: " + str(theta) + ", rho: " + str(rho), image.COLOR_BLUE) disp.show(img) ``` -------------------------------- ### Example MUD Configuration File Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/faq.md This is an example of a .mud file used to describe a MUD model. It specifies the .cvimodel file name and other parameters. Ensure the 'model' path correctly points to your .cvimodel file. ```ini [basic] type = cvimodel model = yolov5s_224_int8.cvimodel [extra] model_type = yolov5 input_type = rgb mean = 0, 0, 0 scale = 0.00392156862745098, 0.00392156862745098, 0.00392156862745098 anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 labels = person, bicycle, car, motorcycle, airplane, bus, train, truck, boat, traffic light, fire hydrant, stop sign, parking meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard, sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket, bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange, broccoli, carrot, hot dog, pizza, donut, cake, chair, couch, potted plant, bed, dining table, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave, oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy bear, hair dryer, toothbrush ``` -------------------------------- ### Install App using Python Script Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/app.md This Python script can be used for local installation of app packages. Ensure the `pkg_path` variable is correctly set to your package's location. ```python pkg_path = "/path/to/your/app.package" ``` -------------------------------- ### OpenMV/MaixPy-v1 LCD and Sensor Import Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/faq.md This is the import syntax for LCD and sensor modules as used in OpenMV and MaixPy-v1. ```python import lcd, sensor ``` -------------------------------- ### Full Hand Gesture Classification Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/hand_gesture_classification.md A complete example demonstrating real-time hand gesture classification using a camera feed, hand landmark detection, and the LinearSVCManager for prediction. Ensure necessary modules and preprocessing are included. ```python from maix import camera, display, image, nn, app import numpy as np # Add below me name_classes = ("one", "five", "fist", "ok", "heartSingle", "yearh", "three", "four", "six", "Iloveyou", "gun", "thumbUp", "nine", "pink") # Easy-to-understand class names npzfile = np.load("/maixapp/apps/hand_gesture_classifier/trainSets.npz") # Preload features and labels (name_classes index) X_train = npzfile["X"] y_train = npzfile["y"] clfm = LinearSVCManager(LinearSVC.load("/maixapp/apps/hand_gesture_classifier/clf_dump.npz"), X_train, y_train, pretrained=True) # Initialize LinearSVCManager with preloaded classifier detector = nn.HandLandmarks(model="/root/models/hand_landmarks.mud") cam = camera.Camera(320, 224, detector.input_format()) disp = display.Display() # Loading screen img = cam.read() img.draw_string(100, 112, "Loading...\nwait up to 10s", color = image.COLOR_GREEN) disp.show(img) while not app.need_exit(): img = cam.read() objs = detector.detect(img, conf_th = 0.7, iou_th = 0.45, conf_th2 = 0.8) for obj in objs: hand_landmarks = preprocess(obj.points[8:8+21*3], obj.class_id == 0, (img.width(), img.height(), 1)) # Preprocessing features = np.array([hand_landmarks.flatten()]) class_idx, pred_conf = clfm.test(features) # Get predicted class class_idx, pred_conf = class_idx[0], pred_conf[0] # Handle multiple inputs and outputs, take the first element msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}\n{name_classes[class_idx]}({class_idx})={pred_conf*100:.2f}%' img.draw_string(obj.points[0], obj.points[1], msg, color = image.COLOR_RED if obj.class_id == 0 else image.COLOR_GREEN, scale = 1.4, thickness = 2) detector.draw_hand(img, obj.class_id, obj.points, 4, 10, box=True) disp.show(img) ``` -------------------------------- ### Clone MaixPy Repository Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/source_code/build.md Clone the MaixPy repository to your local machine. This is the first step to start development. ```shell mkdir -p ~/maix cd ~/maix git clone https://github.com/sipeed/MaixPy ``` -------------------------------- ### Install Docker Dependencies and Docker CE on Ubuntu Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/ai_model_converter/maixcam.md Installs necessary dependencies and the Docker CE engine on an Ubuntu system. Follow the official Docker installation guide for detailed steps. ```shell # Install dependencies for Docker sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common # Add the official Docker source curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Install Docker sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ``` -------------------------------- ### Initialize Camera and Display Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/apriltag.md Set up the camera to capture video and the display to show the processed images. ```python cam = camera.Camera() disp = display.Display() ``` -------------------------------- ### Initialize and Configure Qwen3-VL Model Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/mllm/vlm_qwen3.md Loads the Qwen3-VL model, retrieves input dimensions and format, and sets up a system prompt and reply callback. This is essential for preparing the model for inference. ```python from maix import app, nn, err, image, display, time import requests import json model = "/root/models/Qwen3-VL-2B-Instruct-GPTQ-Int4-AX630C-P320-CTX448-maixcam2/model.mud" disp = display.Display() qwen3_vl = nn.Qwen3VL(model) in_w = qwen3_vl.input_width() in_h = qwen3_vl.input_height() in_fmt = qwen3_vl.input_format() print(f"input size: {in_w}x{in_h}, format: {image.format_name(in_fmt)}") def on_reply(obj, resp): print(resp.msg_new, end="") qwen3_vl.set_system_prompt("You are Qwen3VL. You are a helpful vision-to-text assistant.") qwen3_vl.set_reply_callback(on_reply) # load and set image img = image.load("/maixapp/share/picture/2024.1.1/ssd_car.jpg", format=in_fmt) qwen3_vl.set_image(img, fit=image.Fit.FIT_CONTAIN) # if size not math, will auto resize first disp.show(img) while not app.need_exit(): print('wait model is ready') if qwen3_vl.is_ready(): break time.sleep(1) ``` -------------------------------- ### Initialize Camera and Display Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/find_blobs.md Initializes the camera with a specified resolution and format, and sets up the display output. ```python cam = camera.Camera(320, 240) # Initialize the camera with an output resolution of 320x240 in RGB format disp = display.Display() ``` -------------------------------- ### Initialize MaixPy Module Project Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/source_code/add_c_module.md Run this command in the copied module template directory to set up the project files. ```bash python init_files.py ``` -------------------------------- ### UART Data Reporting Example Source: https://github.com/sipeed/maixpy/blob/main/projects/app_scan_qrcode/README.md Example of how recognition data is reported over UART. The example shows a hex-encoded data packet for a QR code containing the string "123456789". ```text # uart data AA CA AC BB 0D 00 00 00 E1 05 31 32 33 34 35 36 37 38 39 1A 15 # 31 32 33 34 35 36 37 38 39: means the qrcode is "123456789" ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/deploy_online_recognition.md Install the required Python libraries, numpy and websockets, for the Sherpa-ONNX server. ```python pip install numpy pip install websockets ``` -------------------------------- ### Camera Display Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/README_MaixCAM.md This Python script initializes the camera and display, then continuously reads frames from the camera and shows them on the display. It requires the maix library for camera, display, and app functionalities. ```python from maix import camera, display, app disp = display.Display() # Construct a display object and initialize the screen cam = camera.Camera(640, 480) # Construct a camera object, manually set the resolution to 640x480, and initialize the camera while not app.need_exit(): # Keep looping until the program exits (you can exit by pressing the function key on the device or clicking the stop button in MaixVision) img = cam.read() # Read the camera view and save it to the variable img, you can print(img) to print the details of img disp.show(img) # Display img on the screen ``` -------------------------------- ### Verify Sherpa-ONNX Installation Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/deploy_online_recognition.md Run this Python command to check if Sherpa-ONNX is installed correctly and print its version. ```python python3 -c "import sherpa_onnx; print(sherpa_onnx.__version__)" ``` -------------------------------- ### Initialize Recorder with Custom Parameters Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/record.md Demonstrates initializing the Recorder with custom sample rate, format, and channel. Note that only specific sample rates and formats have been tested. ```python r = audio.Recorder(sample_rate=48000, format=audio.Format.FMT_S16_LE, channel = 1) ``` -------------------------------- ### Install Sherpa-ONNX Package Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/deploy_online_recognition.md Install the Sherpa-ONNX Python package. For GPU support, use the CUDA-enabled package. ```python pip install sherpa-onnx ``` ```python pip install sherpa-onnx==1.10.16+cuda -f https://k2-fsa.github.io/sherpa/onnx/cuda.html # For users in China # pip install sherpa-onnx==1.10.16+cuda -f https://k2-fsa.github.io/sherpa/onnx/cuda-cn.html ``` -------------------------------- ### Run Qwen3-VL Model for Image Description in MaixPy Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/mllm/vlm_qwen3.md This Python script demonstrates how to load and run the Qwen3-VL model on MaixPy for image description. It includes setting up the display, loading an image, and sending prompts to the model. Ensure the model path and image path are correct for your setup. ```python from maix import app, nn, err, image, display, time import requests import json model = "/root/models/Qwen3-VL-2B-Instruct-GPTQ-Int4-AX630C-P320-CTX448-maixcam2/model.mud" disp = display.Display() qwen3_vl = nn.Qwen3VL(model) in_w = qwen3_vl.input_width() in_h = qwen3_vl.input_height() in_fmt = qwen3_vl.input_format() print(f"input size: {in_w}x{in_h}, format: {image.format_name(in_fmt)}") def on_reply(obj, resp): print(resp.msg_new, end="") qwen3_vl.set_system_prompt("You are Qwen3VL. You are a helpful vision-to-text assistant.") qwen3_vl.set_reply_callback(on_reply) # load and set image img = image.load("/maixapp/share/picture/2024.1.1/ssd_car.jpg", format=in_fmt) qwen3_vl.set_image(img, fit=image.Fit.FIT_CONTAIN) # if size not math, will auto resize first disp.show(img) while not app.need_exit(): print('wait model is ready') if qwen3_vl.is_ready(): break time.sleep(1) def example1(): print('') # set prompt msg = "请描述图中有什么" print(">>", msg) resp = qwen3_vl.send(msg) err.check_raise(resp.err_code) def example2(): print('') msg = "Describe the picture" print(">>", msg) resp = qwen3_vl.send(msg) err.check_raise(resp.err_code) example1() example2() del qwen3_vl # Must release vlm object ``` -------------------------------- ### Install Bleak Package Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/modules/bluetooth.md Install the 'bleak' Python package, a necessary library for Bluetooth Low Energy (BLE) applications. ```shell pip install bleak ``` -------------------------------- ### TCP Server Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/network/socket.md Sets up a TCP server that listens for incoming connections, spawns a thread for each client to handle communication, and echoes received messages back. Uses SO_REUSEADDR for immediate port reuse. ```python import socket import threading local_ip = "0.0.0.0" local_port = 8080 def receiveThread(conn, addr): while True: print('Reading...') client_data = conn.recv(1024) if not client_data: break print(client_data) conn.sendall(client_data) print(f"Client {addr} disconnected") ip_port = (local_ip, local_port) sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sk.bind(ip_port) sk.listen(50) print("Waiting for clients...") while True: conn, addr = sk.accept() print(f"Client {addr} connected") # Create a new thread to communicate with this client t = threading.Thread(target=receiveThread, args=(conn, addr)) t.daemon = True t.start() ``` -------------------------------- ### MaixPy PMU Module Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/modules/pmu.md Demonstrates basic usage of the PMU module for battery percentage, charging current, and voltage configuration of DCDC1. Includes a loop to print all channel voltages. ```python from maix import time, app from maix.ext_dev import pmu p = pmu.PMU("axp2101") # Get battery percent print(f"Battery percent: {p.get_bat_percent()}%") # Set the max battery charging current p.set_bat_charging_cur(1000) print(f"Max charging current: {p.get_bat_charging_cur()}mA") # Set DCDC1 voltage (!!! Do not modify the voltage of other channels, # as it may damage the device.) old_dcdc1_voltage = p.get_vol(pmu.PowerChannel.DCDC1) print(f"Old DCDC1 voltage: {old_dcdc1_voltage}mV") p.set_vol(pmu.PowerChannel.DCDC1, 3000) new_dcdc1_voltage = p.get_vol(pmu.PowerChannel.DCDC1) print(f"New DCDC1 voltage: {new_dcdc1_voltage}mV") # Get all channel voltages channels = [ pmu.PowerChannel.DCDC1, pmu.PowerChannel.DCDC2, pmu.PowerChannel.DCDC3, pmu.PowerChannel.DCDC4, pmu.PowerChannel.DCDC5, pmu.PowerChannel.ALDO1, pmu.PowerChannel.ALDO2, pmu.PowerChannel.ALDO3, pmu.PowerChannel.ALDO4, pmu.PowerChannel.BLDO1, pmu.PowerChannel.BLDO2 ] print("------ All channel voltages: ------") for channel in channels: print(f"{channel.name}: {p.get_vol(channel)}") print("-----------------------------------") # Poweroff (Important! Power will be cut off immediately) # p.poweroff () while not app.need_exit(): time.sleep_ms(1000) ``` -------------------------------- ### Example Recognition Output Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/digit.md This is an example of the continuous Chinese digit recognition output, showing recognized digits and silence indicators. ```shell _0123456789 ``` -------------------------------- ### DNS Server Configuration Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/network/network_settings.md Lists common DNS server IP addresses used for network resolution. This configuration is typically found in `/boot/resolv.conf` and copied to `/etc/resolv.conf` on startup. ```shell nameserver 114.114.114.114 # China nameserver 223.5.5.5 # Aliyun China nameserver 8.8.4.4 # Google nameserver 8.8.8.8 # Google nameserver 223.6.6.6 # Aliyun China ``` -------------------------------- ### Initialize Camera and Display Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/qrcode.md Initializes the camera with a resolution of 320x240 in RGB format and sets up the display. ```python cam = camera.Camera(320, 240) disp = display.Display() ``` -------------------------------- ### Install Docker on Ubuntu Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/ai_model_converter/maixcam2.md Installs Docker Engine on Ubuntu systems. Ensure you follow Docker's official documentation for the most up-to-date instructions. ```shell # Install Docker dependencies sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common # Add Docker repo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Install Docker sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ``` -------------------------------- ### Initialize Camera and Display Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/find_barcodes.md Initializes the camera with a resolution of 480x320 in RGB format and sets up the display. ```python cam = camera.Camera(480, 320) # Initialize the camera with a resolution of 480x320 in RGB format disp = display.Display() ``` -------------------------------- ### Install MaixPy Module Wheel Package on Device Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/source_code/add_c_module.md Installs the generated .whl package onto the MaixPy device. Replace the path with the actual location of your .whl file. ```python import os; os.system("pip install /root/xxxxx.whl") ``` -------------------------------- ### Qwen Model Configuration Parameters Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/mllm/llm_qwen.md Example configuration for controlling text generation behavior in Qwen models, including temperature, repetition penalty, and sampling strategies. ```ini [post_config] enable_temperature = true temperature = 0.9 enable_repetition_penalty = false repetition_penalty = 1.2 penalty_window = 20 enable_top_p_sampling = false top_p = 0.8 enable_top_k_sampling = true top_k = 10 ``` -------------------------------- ### Complete AprilTag Distance Measurement Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/vision/apriltag.md This complete example demonstrates how to continuously detect AprilTags, calculate the distance to them using a pre-determined coefficient 'k', and display the results. ```python from maix import camera, display, image import math ''' z_trans: The value of z_translation() when the distance is 'distance' (actual distance in mm). distance: The actual distance to the AprilTag when detected, in mm. Returns the constant coefficient 'k'. ''' def caculate_k(z_trans, distance): return distance / z_trans ''' x_trans: The value of x_translation() returned by detecting the AprilTag. y_trans: The value of y_translation() returned by detecting the AprilTag. z_trans: The value of z_translation() returned by detecting the AprilTag. k: Constant coefficient. Returns the distance in mm. ''' def calculate_distance(x_trans, y_trans, z_trans, k): return abs(k * math.sqrt(x_trans * x_trans + y_trans * y_trans + z_trans * z_trans)) cam = camera.Camera(160, 120) disp = display.Display() # When the distance is 200mm, the detected z_translation() of the AprilTag is -9.7 k = caculate_k(-9.7, 200) while 1: img = cam.read() apriltags = img.find_apriltags() for a in apriltags: corners = a.corners() for i in range(4): img.draw_line(corners[i][0], corners[i][1], corners[(i + 1) % 4][0], corners[(i + 1) % 4][1], image.COLOR_GREEN) # Calculate the distance x_trans = a.x_translation() y_trans = a.y_translation() z_trans = a.z_translation() distance = calculate_distance(x_trans, y_trans, z_trans, k) print(f'apriltag k:{k} distance:{distance} mm') disp.show(img) ``` -------------------------------- ### Recognition Result Example Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/audio/recognize.md Example output showing real-time speech recognition results. The output includes a status message and the decoded text along with its phonetic transcription. ```shell ### SIL to clear decoder! ('今天天气 怎么样 ', 'jin1 tian1 tian1 qi4 zen3 me yang4 ') ``` -------------------------------- ### Install MaixPy wheel file via SSH Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/upgrade.md Install a manually downloaded MaixPy wheel file using pip in the SSH terminal. Replace 'xxx.whl' with the actual filename. ```bash pip install xxx.whl ``` -------------------------------- ### Install MaixPy wheel file using os.system Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/upgrade.md Execute a manually downloaded MaixPy wheel file using the os.system command in Python. Replace 'xxx.whl' with the actual filename. ```python import os os.system("xxx.whl") ``` -------------------------------- ### Install tpu-mlir within Docker Container Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/ai_model_converter/maixcam.md Installs the tpu-mlir Python wheel package inside the running Docker container. Ensure the .whl file is downloaded and placed in the shared '~/data' directory. ```shell pip install tpu_mlir*.whl # Replace with the downloaded file name ``` -------------------------------- ### Get System Configuration Values Source: https://github.com/sipeed/maixpy/blob/main/docs/doc/en/basic/app.md Use `maix.app.get_sys_config_kv` to retrieve system settings. Remember that all retrieved values are strings and require appropriate casting. ```python from maix import app locale = app.get_sys_config_kv("language", "locale") print("locale:", locale) backlight = app.get_sys_config_kv("backlight", "value") print("backlight:", backlight, ", type:", type(backlight)) ```