Search by Tags

How to Use UART with Torizon VS Code Extension

 

Article updated at 31 Mar 2020
Subscribe for this article updates

Introduction

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

This article complies to 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 TorizonCore, UART devices can be accessed through /dev/tty*. Depending on the UART hardware implementation, those devices can have different names. Take a look to UART (Linux) article to understand the different /dev/tty* names across the Toradex's Modules.

Once you identify the exact name for 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 TorizonCore Using Visual Studio Code article for detailed instructions.


  • Python project

    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

    Show the Configurations View

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


  • Add New Device to The Project

    Add New Device to The Project

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

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


  • Adding tty device

    Adding tty device

Check if the device was added to your project.


  • Project's Devices

    Project's Devices

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

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.

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.