Skip to content

Commit 0da2d02

Browse files
authored
Merge pull request #811 from luxonis/uart_example_script
Added UART example from Script node
2 parents c22d7f8 + 677327e commit 0da2d02

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Script UART communication
2+
=========================
3+
4+
This example uses :ref:`Script` node for `UART communication <https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter>`__. Note that OAK
5+
cameras don't have UART pins easily disposed, and we soldered wires on `OAK-FFC-4P <https://docs.luxonis.com/projects/hardware/en/latest/pages/DD2090.html>`__
6+
to expose UART pins.
7+
8+
.. note::
9+
10+
This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration.
11+
12+
Demo
13+
####
14+
15+
.. raw:: html
16+
17+
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; height: auto;">
18+
<iframe src="https://www.youtube.com/embed/nbS1BczO5sE" frameborder="0" allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe>
19+
</div>
20+
21+
22+
.. figure:: https://user-images.githubusercontent.com/18037362/232458809-a36dc418-6bb5-411f-9172-5130a926191d.jpg
23+
24+
Oscilloscope connected to the OAK-FFC-4P UART pins
25+
26+
Setup
27+
#####
28+
29+
.. include:: /includes/install_from_pypi.rst
30+
31+
Source code
32+
###########
33+
34+
.. tabs::
35+
36+
.. tab:: Python
37+
38+
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/Script/script_uart.py>`__
39+
40+
.. literalinclude:: ../../../../examples/Script/script_uart.py
41+
:language: python
42+
:linenos:
43+
44+
.. tab:: C++
45+
46+
Not yet available
47+
48+
49+
.. include:: /includes/footer-short.rst

docs/source/tutorials/code_samples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ are presented with code.
122122
- :ref:`Script HTTP server` - Serve still image over HTTP response (only OAK-POE devices)
123123
- :ref:`Script MJPEG server` - Serve MJPEG video stream over HTTP response (only OAK-POE devices)
124124
- :ref:`Script NNData example` - Constructs :ref:`NNData` in Script node and sends it to the host
125+
- :ref:`Script UART communication` - UART communication with Script node
125126

126127
.. rubric:: SpatialDetection
127128

examples/Script/script_uart.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
'''
3+
NOTE: This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration!
4+
'''
5+
import depthai as dai
6+
import time
7+
8+
# Start defining a pipeline
9+
pipeline = dai.Pipeline()
10+
11+
script = pipeline.create(dai.node.Script)
12+
script.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
25+
script.setProcessor(dai.ProcessorType.LEON_CSS)
26+
27+
28+
config = dai.Device.Config()
29+
# Get argument first
30+
GPIO = dai.BoardConfig.GPIO
31+
config.board.gpio[15] = GPIO(GPIO.OUTPUT, GPIO.ALT_MODE_2)
32+
config.board.gpio[16] = GPIO(GPIO.INPUT, GPIO.ALT_MODE_2)
33+
config.board.uart[0] = dai.BoardConfig.UART()
34+
35+
36+
with dai.Device(config) as device:
37+
device.startPipeline(pipeline)
38+
print("Pipeline started")
39+
while True:
40+
time.sleep(1)

0 commit comments

Comments
 (0)