How to Use UART with Torizon Visual Studio Code Extension (Python)
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
- TorizonCore installed on a Toradex module.
- Have completed the Python Development and Debugging on TorizonCore Using Visual Studio Code lessons.
- Define which UART device you want to use.
- (optional) understand How to Use UART on TorizonCore.
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*. 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 TorizonCore Using Visual Studio Code article for detailed instructions.
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"
On the device item, press the '+' button on the right.
On the same command box, type the selected tty device. As an example, we will add
/dev/tty0 is a ficticious example. Find your UART name on the previous section Define the UART Device.
Check if the device was added to your project.
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
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
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:
- From requirements.txt example on GitHub to requirements.txt file of your project.
- From readgps.py example on GitHub to main.py file of your project.
Run the Example
F5 to build and run the example.
Time = 07:53:31
Latitude = 3340.18707, N
Longitude = 07259.43225, E