UNIX-port and GPIO's?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

UNIX-port and GPIO's?

Post by Tetraeder » Mon Sep 12, 2016 9:12 am

Hello everyone,

I have a NXP/Freescale Sabre Board with i.MX6 and I run Linaro.
Has someone tried to control a Pin or any other hardware function over the UNIX-port (controller no matter)?
Anyone a idea to get this working?

I read something about "Linux Device Tree", is that the right way?

thanks in advance

User avatar
Posts: 1374
Joined: Thu May 28, 2015 5:54 pm

Re: UNIX-port and GPIO's?

Post by deshipu » Mon Sep 12, 2016 9:39 am

I think that in the true UNIX fashion, all those pins are exposed as files in the /dev subsystem, so you should be able to control them using regular file operations. Then again, not sure if this is the most efficient way of doing it.

Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: UNIX-port and GPIO's?

Post by markxr » Mon Sep 12, 2016 11:44 am

I've done it with non-micro python.

Under Linux, you write the ID of the GPIOs to export into /sys/class/gpio/export. In this context, "export" means from kernel-control to control of user processes.

Then files appear under /sys/class/gpio/gpioN (where N is the ID)

There are a bunch of other pseudo-files in there, which control the GPIO direction and output.

It's not the most efficient way, but it should work across different Linux GPIO implementations.

User avatar
Posts: 3457
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada

Re: UNIX-port and GPIO's?

Post by dhylands » Mon Sep 12, 2016 4:07 pm

You'll find documentation for sysfs access to gpio pins here:

Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: UNIX-port and GPIO's?

Post by pfalcon » Mon Sep 12, 2016 5:27 pm

Tetraeder wrote: Has someone tried
For example: http://forum.micropython.org/viewtopic. ... 137#p10744
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

Re: UNIX-port and GPIO's?

Post by Tetraeder » Tue Sep 13, 2016 1:05 pm

thanks for the hints!!
Regarding "GPIO Sysfs Interface":
Also a good reference for setting GPIO's from User Space http://falsinsoft.blogspot.nl/2012/11/a ... space.html
It's works with my other Board, Phytec phyBOATD-Wega-AM335x, with kernel version 3.12.61 but with my i.MX6 board i can't control the output state, only read out the input state is possible. Well I keep trying.

example to calculate the GPIO ID:
In my case every port has 32 pin's
Port number * 32 + Pin = 3 x 32 + 6 = 106 = ID

Post Reply