-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #811 from luxonis/uart_example_script
Added UART example from Script node
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Script UART communication | ||
========================= | ||
|
||
This example uses :ref:`Script` node for `UART communication <https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter>`__. Note that OAK | ||
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>`__ | ||
to expose UART pins. | ||
|
||
.. note:: | ||
|
||
This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration. | ||
|
||
Demo | ||
#### | ||
|
||
.. raw:: html | ||
|
||
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; height: auto;"> | ||
<iframe src="https://www.youtube.com/embed/nbS1BczO5sE" frameborder="0" allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe> | ||
</div> | ||
|
||
|
||
.. figure:: https://user-images.githubusercontent.com/18037362/232458809-a36dc418-6bb5-411f-9172-5130a926191d.jpg | ||
|
||
Oscilloscope connected to the OAK-FFC-4P UART pins | ||
|
||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/Script/script_uart.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/Script/script_uart.py | ||
:language: python | ||
:linenos: | ||
|
||
.. tab:: C++ | ||
|
||
Not yet available | ||
|
||
|
||
.. include:: /includes/footer-short.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
''' | ||
NOTE: This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration! | ||
''' | ||
import depthai as dai | ||
import time | ||
|
||
# Start defining a pipeline | ||
pipeline = dai.Pipeline() | ||
|
||
script = pipeline.create(dai.node.Script) | ||
script.setScript(""" | ||
import serial | ||
import time | ||
ser = serial.Serial("/dev/ttyS0", baudrate=115200) | ||
i = 0 | ||
while True: | ||
i += 1 | ||
time.sleep(0.1) | ||
serString = f'TEST_{i}' | ||
ser.write(serString.encode()) | ||
""") | ||
# Define script for output | ||
script.setProcessor(dai.ProcessorType.LEON_CSS) | ||
|
||
|
||
config = dai.Device.Config() | ||
# Get argument first | ||
GPIO = dai.BoardConfig.GPIO | ||
config.board.gpio[15] = GPIO(GPIO.OUTPUT, GPIO.ALT_MODE_2) | ||
config.board.gpio[16] = GPIO(GPIO.INPUT, GPIO.ALT_MODE_2) | ||
config.board.uart[0] = dai.BoardConfig.UART() | ||
|
||
|
||
with dai.Device(config) as device: | ||
device.startPipeline(pipeline) | ||
print("Pipeline started") | ||
while True: | ||
time.sleep(1) |