DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
DepthAI 教程
DepthAI API 参考

本页目录

  • Demo
  • 设置
  • 源代码
  • Pipeline

脚本 UART 通信

此示例使用 Script 节点进行 UART 通信。请注意,OAK 相机没有易于使用的 UART 引脚,我们在 OAK-FFC-4P 上焊接了导线以暴露 UART 引脚。

Demo

https://user-images.githubusercontent.com/18037362/232458809-a36dc418-6bb5-411f-9172-5130a926191d.jpg

设置

请运行安装脚本以下载所有必需的依赖项。请注意,此脚本必须在 git 上下文中运行,因此您需要先下载 depthai-python 仓库,然后运行该脚本。
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
更多信息,请参考安装指南

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2'''
3NOTE: This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration!
4'''
5import depthai as dai
6import time
7
8# Start defining a pipeline
9pipeline = dai.Pipeline()
10
11script = pipeline.create(dai.node.Script)
12script.setScript("""
13    import serial
14    import time
15
16    ser = serial.Serial("/dev/ttyS0", baudrate=115200)
17    i = 0
18    while True:
19        i += 1
20        time.sleep(0.1)
21        serString = f'TEST_{i}'
22        ser.write(serString.encode())
23""")
24# Define script for output
25script.setProcessor(dai.ProcessorType.LEON_CSS)
26
27
28config = dai.Device.Config()
29# Get argument first
30GPIO = dai.BoardConfig.GPIO
31config.board.gpio[15] = GPIO(GPIO.OUTPUT, GPIO.ALT_MODE_2)
32config.board.gpio[16] = GPIO(GPIO.INPUT, GPIO.ALT_MODE_2)
33config.board.uart[0] = dai.BoardConfig.UART()
34
35
36with dai.Device(config) as device:
37    device.startPipeline(pipeline)
38    print("Pipeline started")
39    while True:
40        time.sleep(1)

C++

WIP

Pipeline

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。