Use Python to control GPIO

Dear Community;

My question is simple: Can I use pythoncin Ubuntu to control the GPIOs of my Colibri T20 ? If so, can anyone give me a simple example in Python of how to turn on a GPIO?

Thanks in advance.

Have a look at this article for GPIO access through sysfs using Python.

Regarding Ubuntu rootfs, we officially only support Angstrom based rootfs build via Open Embedded aka Yocto. For Ubuntu based rootfs you can try Nvidia’s L4T rootfs which is documented in this article.

Sorry for this late reply… So I have installed Linux 2.6 beta in my Colibri T20 to try GPIOs. I used the GPIOConfig tool to turn on/off some gpios and everything went fine. Looking for this article I tried to use the Gpios from the Linux terminal, but there is not way. This are the commands I use, for example for the gpio 218 sodimm pin 133:

root@dhcppc3:~# echo 218 > /sys/class/gpio/export

-sh: echo: write error: Device or resource busy

I can not also read gpios as inputs with this lines, for example gpio 98 sodimm pin 103:

echo 98 > /sys/class/gpio/export

-sh: echo: write error: Device or resource busy

I also tried the ADC and this works fine.

Is something wrong? Thanks in advance.

GPIO98 is already exported, and 218 is configured as a button.
You can see list of in use GPIO by runnung:

cat /sys/kernel/debug/gpio

Thank you for the answer. So as gpio 98 is already exported I suppose that I would be able to read a digital input. For the gpio 218 is there any way to use it? I need exactly that gpio to control a relay. I suppose that if your application GPIOConfig can use gpio 218 there is also a way to control it via terminal/python. So how can I configure it? Thanks in advance. Any help is appreciated.

Hello. I have been testing what you have said. With GPIO98 there no any problem, as you said it is already exported and can I read it without any problems. Then I am using 4 GPIO to control 4 relays. GPIO 88 and 94 work fine. But GPIO 218 and 171 don´t. using cat /sys/kernel/debug/gpio I can see that they are defined as KEY_POWER and KEY_BACK, so I imagine that I can´t use them because of that. My question is: Is there any way to modify that two GPIO and control them? For example from your GPIOConfig application I can activate them.

Thanks in advance.

You would need to adjust GPIO keys usage of resp. GPIOs here or completely disable CONFIG_KEYBOARD_GPIO and rebuild your kernel as explained in the following article on our developer website. In theory one could hard-code GPIO and pin muxing usage behind the Linux kernel’s back just like the GPIO tool does but this is neither recommended nor supported by us.

Thanks this works!

I have also problems with T30 with the sodimm pin 85 gpio 94. I can export it and set it as high but nothing happens. Any idea?
Thanks a lot.

Colibri T30 sodimm pin 85 is not gpio no. 94.

True, thanks is 171