# Script UART communication

This example uses [Script](https://docs.luxonis.com/software/depthai-components/nodes/script.md) 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://shop.luxonis.com/products/oak-ffc-4p) to expose UART pins.

> This should only be run on OAK-FFC-4P, as other OAK cameras might have different GPIO configuration.

## Demo

## Setup

Please run the [install script](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py) to download
all required dependencies. Please note that this script must be ran from git context, so you have to download the
[depthai-python](https://github.com/luxonis/depthai-python) repository first and then run the script

```bash
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
```

For additional information, please follow the [installation guide](https://docs.luxonis.com/software/depthai/manual-install.md).

## Source code

#### Python

```python
#!/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)
```

#### C++

WIP

## Pipeline

### examples/script_uart.pipeline.json

```json
{
  "pipeline": {
    "connections": [],
    "globalProperties": {
      "calibData": null,
      "cameraTuningBlobSize": null,
      "cameraTuningBlobUri": "",
      "leonCssFrequencyHz": 700000000.0,
      "leonMssFrequencyHz": 700000000.0,
      "pipelineName": null,
      "pipelineVersion": null,
      "sippBufferSize": 18432,
      "sippDmaBufferSize": 16384,
      "xlinkChunkSize": -1
    },
    "nodes": [
      [
        0,
        {
          "id": 0,
          "ioInfo": [],
          "name": "Script",
          "properties": {
            "processor": 0,
            "scriptName": "<script>",
            "scriptUri": "asset:__script"
          }
        }
      ]
    ]
  }
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
