Select the version of your OS from the tabs below. If you don't know the version you are using, run the command cat /etc/os-release
or cat /etc/issue
on the board.
Remember that you can always refer to the Torizon Documentation, there you can find a lot of relevant articles that might help you in the application development.
In this article, we will show how to add a UART device to be accessed in a containerized application in TorizonCore.
This article complies to the Typographic Conventions for Torizon Documentation
RS-485 is a communication protocol running on top of the UART stack. The same steps provided in the more generic article UART (Linux): RS-485 apply to TorizonCore.
In Linux, UART devices can be accessed through files on /dev/apalis-uart*
, /dev/colibri-uart*
and /dev/verdin-uart*
. Take a look to UART (Linux) article to understand the standard names across the Toradex's module families.
Once you identify the exact name for your UART device, you can add it to your container using docker run
or docker-compose
.
To add a host device to the container, use the --device
flag with the docker run
command.
For example, let's assume we want to access the /dev/verdin-uart1
device inside a container based on the Torizon Debian base container:
# docker run --rm -it --device /dev/verdin-uart1 torizon/debian:$CT_TAG_DEBIAN
To check if the device was added, run this on the container's terminal:
## ls /dev/verdin-uart1
/dev/verdin-uart1
If you are using Docker Compose, set the devices
configuration in your YAML file for device mappings. Uses the same format as the --device
docker client create option.
docker-compose.yamldevices: - "/dev/verdin-uart1:/dev/verdin-uart1"
The serial port can be used with several programming languages and libraries, same as with any Linux distribution. For demonstration purposes, we provide Python and .NET Core samples.
Documented use cases are provided in the following subsections.
If you want to use .NET Core to access the UART with the Torizon Visual Studio Code Extension, please read the following article for more information:
The source code from the example Python: Connect to a Serial GPS Using Command-line Interface is also used to explain how to use UART with the Torizon Visual Studio Code Extension. Please read the following article for more information:
The GPS example project is available at Torizon Samples Github Page
This example uses the Python's pyserial
module to read the data from UART. The application then uses pynmea2
module to parse the GPGGA string and get the values for time, latitude and longitude. The parsed data than is printed on stdout.
Warning: there may be other Python libraries with similar functionality, we've chosen pyserial
and pynmea2
because they are well-known libraries.
The goal of this sample is to demonstrate how UART can be accessed from within a container.
Connect a GPS Module to an available UART on your board.
In our case, the example was tested on Apalis iMX6 Evaluation Board and the GPS is connected to UART2. However, you can easily adapt the example for any Toradex's module.
Any GPS module with NMEA output should work. In this example, we are connecting to a Adafruit Ultimate GPS Breakout board module.
Board GPS
VCC <--------> VCC
RX <--------> TX
TX <--------> RX
GND <--------> GND
Make sure the power supply and logic levels match between the board and GPS or be prepared for some magic smoke.
In your development PC, clone the samples repository:
$ git clone https://github.com/toradex/torizon-samples.git
Copy the gps/python
directory from your PC to your Torizon module (change X.X.X.X
to your module’s IP-address):
$ scp -r ./samples/gps/python/ torizon@X.X.X.X:/home/torizon/
In your module's terminal, change the current directory to the gps/python
directory:
# cd /home/torizon/gps/python
Build the container. Choose from the tabs below to see the example for 32 or 64 bit Arm:
# docker build -t gps .
# docker build --build-arg IMAGE_ARCH=linux/arm64 -t gps .
Please remember that if you once built your image for one architecture, you need to pass the --pull
argument to build for another architecture. According to the Docker documentation, the pull
argument will always attempt to pull a newer version of the image.
Example:
$ docker build --pull .
On the Apalis iMX6 with an Apalis Evaluation Board, UART2 is accessible through /dev/apalis-uart2
. Hence, run the container using the following command:
# docker run -it --rm --device=/dev/apalis-uart2 gps
The --device
parameter allows the UART to be accessible from within the container. Adjust the value according to your needs. For UART and pinout information on other boards, please refer to UART (Linux) article.
Please, note that the same needs to be reflected in readgps.py
file when calling the Serial()
function.
Time = 07:53:31
Latitude = 3340.18707, N
Longitude = 07259.43225, E
.
.
The Dockerfile of this project is available on Torizon Samples Github Page.
It starts from a <arch>-debian-base
image and installs python3 along with utilities for package management. The requirements.txt file defines the modules pyserial
and pynmea2
, required for running the sample. These dependencies are installed with pip install
. Finally the sample application readgps.py
is copied to the container’s filesystem and set as the default command.
The readgps.py Python script imports the required libs:
import sys import pynmea2 import serial
Sets the serial device that is connected to the GPS:
ser = serial.Serial("/dev/apalis-uart2",9600, 8, 'N', 1, timeout=1)
Reads the data from the GPS over the UART line by line:
data = ser.readline()
After that, it checks for the GPGGA
string. Geographic coordinates and time are extracted from this line and printed on stdout
.
You can learn more about pySerial's API on their developer's website.
In this article, we will show how to add a UART device to be accessed in a containerized application in TorizonCore.
This article complies to the Typographic Conventions for Torizon Documentation
In Linux, 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 container using docker run
or docker-compose
.
To add a host device to the container, use the --device
flag with the docker run
command.
For example, let's assume we want to access the /dev/tty0
device inside a container based on the Torizon Debian base container. Choose from the tabs below to see the example command for 32 and 64 bit Arm:
# docker run --rm -it --device /dev/tty0 torizon/arm32v7-debian-base
# docker run --rm -it --device /dev/tty0 torizon/arm64v8-debian-base
To check if the device was added, run this on the container's terminal:
## ls /dev/tty*
/dev/tty /dev/tty0
If you are using Docker Compose, set the devices
configuration in your YAML file for device mappings. Uses the same format as the --device
docker client create option.
docker-compose.yamldevices: - "/dev/tty0:/dev/tty0"
The serial port can be used with several programming languages and libraries, same as with any Linux distribution. For demonstration purposes, we provide Python and .NET Core samples.
Documented use cases are provided in the following subsections.
If you want to use .NET Core to access the UART with the Torizon Visual Studio Code Extension, please read the following article for more information:
The source code from the example Python: Connect to a Serial GPS Using Command-line Interface is also used to explain how to use UART with the Torizon Visual Studio Code Extension. Please read the following article for more information:
The GPS example project is available at Torizon Samples Github Page
This example uses the Python's pyserial
module to read the data from UART. The application then uses pynmea2
module to parse the GPGGA string and get the values for time, latitude and longitude. The parsed data than is printed on stdout.
Warning: there may be other Python libraries with similar functionality, we've chosen pyserial
and pynmea2
because they are well-known libraries.
The goal of this sample is to demonstrate how UART can be accessed from within a container.
Connect a GPS Module to an available UART on your board.
In our case, the example was tested on Apalis iMX6 Evaluation Board and the GPS is connected to UART2. However, you can easily adapt the example for any Toradex's module.
Any GPS module with NMEA output should work. In this example, we are connecting to a Adafruit Ultimate GPS Breakout board module.
Board GPS
VCC <--------> VCC
RX <--------> TX
TX <--------> RX
GND <--------> GND
Make sure the power supply and logic levels match between the board and GPS or be prepared for some magic smoke.
In your development PC, clone the samples repository:
$ git clone https://github.com/toradex/torizon-samples.git
Copy gps
directory from your PC to your Torizon module (change X.X.X.X
to your module’s IP-address):
$ scp -r ./samples/gps/ torizon@X.X.X.X:/home/torizon/
In your module's terminal, change the current directory to the gps
directory:
# cd /home/torizon/gps
Build the container. Choose from the tabs below to see the example for 32 or 64 bit Arm:
# docker build -t gps .
# docker build --build-arg IMAGE_ARCH=linux/arm64 -t gps .
Please remember that if you once built your image for one architecture, you need to pass the --pull
argument to build for another architecture. According to the Docker documentation, the pull
argument will always attempt to pull a newer version of the image.
Example:
$ docker build --pull .
On the Apalis iMX6 with an Apalis Evaluation Board, UART2 is accessible through /dev/ttymxc1
. Hence, run the container using the following command:
# docker run -it --rm --device=/dev/ttymxc1 gps
The --device
parameter allows the UART to be accessible from within the container. Adjust the /dev/tty*
value according to your needs. For UART and pinout information on other boards, please refer to UART (Linux) article.
Please, note that the same needs to be reflected in readgps.py
file when calling the Serial()
function.
Time = 07:53:31
Latitude = 3340.18707, N
Longitude = 07259.43225, E
.
.
The Dockerfile of this project is available on Torizon Samples Github Page.
It starts from a <arch>-debian-base
image and installs python3 along with utilities for package management. The requirements.txt file defines the modules pyserial
and pynmea2
, required for running the sample. These dependencies are installed with pip install
. Finally the sample application readgps.py
is copied to the container’s filesystem and set as the default command.
The readgps.py Python script imports the required libs:
import sys import pynmea2 import serial
Sets the serial device that is connected to the GPS:
ser = serial.Serial("/dev/ttymxc1",9600, 8, 'N', 1, timeout=1)
Reads the data from the GPS over the UART line by line:
data = ser.readline()
After that, it checks for the GPGGA
string. Geographic coordinates and time are extracted from this line and printed on stdout
.
You can learn more about pySerial's API on their developer's website.