Skip to main content
Version: Torizon OS 6.x.y

How to Use UART with Torizon Visual Studio Code Extension (Python)

Introduction

In this article, we will show how you can manipulate UART using Visual Studio Code Extension for Torizon.

This article complies with the Typographic Conventions for Torizon Documentation

Prerequisites

Instructions

In the following sections, we will demonstrate how to use the VS Code Extension for Torizon.

Define the UART Device

In Linux systems, including Torizon OS, UART devices can be accessed through /dev/tty*. Toradex adds a layer of abstraction with symlinks, so the UART names are standardized for a given SoM family. Take a look to UART (Linux) article to understand the different /dev/tty* names across the Toradex's Module families.

Once you identify the exact name of your UART device, you can add it to your application.

Create a New Project

On VS Code, create a new Torizon Python Application. See the Python Development and Debugging on Torizon OS Using Visual Studio Code article for detailed instructions.

Python project

Add UART Device to the Application

To add UART to your project, first, open the Torizon Configuration View. To do that, press F1 in Visual Studio Code command bar and then type "Torizon/Python: Focus on Configurations View"

Show the Configurations View

On the device item, press the '+' button on the right.

Add New Device to The Project

On the same command box, type the selected tty device. As an example, we will add /dev/tty0.

caution

/dev/tty0 is a ficticious example. Find your UART name on the previous section Define the UART Device.

Adding tty device

Check if the device was added to your project.

Project's Devices

Add Torizon User to dialout Group

By default UART devices are accessible only for users that belong to the dialout group, the torizon user is not part of that group in the base container configuration, but you can fix this by setting the "buildcommands" custom property to:

 RUN usermod -a -G dialout torizon

Examples

The serial port can be used with several programming languages and libraries, same as with any Linux distribution. This article focuses on Python.

Documented use cases are provided in the following subsections.

Connect to a Serial GPS

The example application used in this article comes from the example Python: Connect to a Serial GPS. Please read the following sections from it:

Add the UART Device to Project and Torizon User to dialout Group

Use the instructions from the beginning of this article to add the corresponding /dev/tty* to your project. On the Apalis iMX6, UART2 is accessible through /dev/ttymxc1. Remember to also add the user to the dialout group.

Prepare the Project's Files

This example is very simple. From your new empty project template, you only need to replace the content of 2 files: requirements.txt and main.py:

Run the Example

Press F5 to build and run the example.

Sample Output
Time = 07:53:31
Latitude = 3340.18707, N
Longitude = 07259.43225, E
.
.

Example Explained: The Project's Dockerfile

Read the Example Explained: The Project's Dockerfile.



Send Feedback!