I am currently using a Colibri iMX6ULL 1GB SoM and running Torizon OS. At the moment, I am controlling GPIOs using a Docker container with the libgpiod library and a Python script. However, I would like to toggle a GPIO directly from the host system without relying on a container.
Is there a recommended way to achieve this using a shell script or other native methods on Torizon OS? If so, what would be the correct approach for configuring and toggling the GPIOs outside of a container?
Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
Hello,
To toggle GPIOs directly from the host system on Torizon OS without using a Docker container, you can utilize the libgpiod command-line tools. These tools allow you to interact with GPIOs directly from the command line, bypassing the need for a containerized environment.
Here’s how you can achieve this:
Ensure libgpiod is Installed: TorizonCore typically includes the libgpiod tools by default. You can verify this by checking if the gpiod commands are available on your system.
Identify GPIO Chips and Lines: Use the gpiodetect command to list all GPIO chips available on your system. Each GPIO chip corresponds to a /dev/gpiochipN device.
gpiodetect
Find the Specific GPIO Line: Once you have identified the correct GPIO chip, use the gpioinfo command to list all lines (pins) available on that chip.
gpioinfo /dev/gpiochip0
Toggle the GPIO Line: Use the gpioset command to set the GPIO line to a high or low state. For example, to set line 5 on chip 0 to high, you would use:
gpioset /dev/gpiochip0 5=1
To set it to low, use:
gpioset /dev/gpiochip0 5=0
Automate with Shell Scripts: You can incorporate these commands into a shell script to automate GPIO control. For example:
#!/bin/bash
# Toggle GPIO line 5 on chip 0
gpioset /dev/gpiochip0 5=1
sleep 1
gpioset /dev/gpiochip0 5=0
By following these steps, you can control GPIOs directly from the host system on Torizon OS without the need for a Docker container. This method leverages the libgpiod tools, which are the recommended approach for GPIO manipulation in modern Linux systems, including Torizon OS.
I hope this helps you with your project!
Best regards,
Toradex AI Assistant.
Please, also check if these links can help you solve your problem:
Just to understand better your issue, why do you want to toggle the GPIOs from user space instead of docker containers?
The Torizon OS environment is prepared to deal with all the applications run by containers. You could either use different containers for different parts of the applications, or use the same container for all.