Soon after we released A13-GPIO for Python https://olimex.wordpress.com/2013/03/08/a13-olinuxino-gpio-python-libraries/ we got requests to do same for iMX233.
iMX233_GPIO is released on PyPi now https://pypi.python.org/pypi/iMX233_GPIO/0.1.0
it works identical to pyA13 you can use same commands:
import iMX233_GPIO as GPIO #init module GPIO.init() #configure module GPIO.setinput(GPIO.PIN#) GPIO.setoutput(GPIO.PIN#) #set GPIO high GPIO.output(GPIO.PIN#, 1) #set GPIO low GPIO.output(GPIO.PIN#, 0) #read input state = GPIO.input(GPIO.PIN#)
due to the GPIO multiplexing we add only these GPIOs in the base package:
PIN9, PIN10, PIN11, PIN12, PIN13, PIN14, PIN15, PIN16, PIN17, PIN18, PIN23, PIN24, PIN25, PIN26, PIN27, PIN28, PIN29, PIN31
you can use this as template, and if you for instance disable LCD in your linux image you can have access to all LCD pins too.
After you download the package from PyPi do as follows to install it:
#tar -zxvf iMX233_GPIO-0.1.0.tar.gz #cd iMX233_GPIO-0.1.0.tar.gz #sudo python setup.py install
after the installation you can use it this way:
#sudo python >>> import iMX233_GPIO as GPIO >>> GPIO.init() #init GPIOs >>> GPIO.getcfg(GPIO.PIN31) #config PIN31 as GPIO >>> GPIO.setcfg(GPIO.PIN31, GPIO.OUTPUT) #config PIN31 as output >>> GPIO.output(GPIO.PIN31, GPIO.HIGH) #set PIN31 high >>> GPIO.output(GPIO.PIN31, GPIO.LOW) #set PIN31 low >>> GPIO.setcfg(GPIO.PIN31, GPIO.INPUT) #config PIN31 as input >>> GPIO.input(GPIO.PIN31) #read PIN31
PINxx assignments is exactly as per imx233-OLinuXino-MAXI schematic
Maximum iMX233 GPIO toggle speed via Python is 15,6 kHz, which is kind of dissapointing, as /dev/mem C approach achieve about 5.7 6 Mhz, but Python is running slow on imx233 so this probably cause the slow GPIOs access.
On A13 is opposite /dev/mem is running slower at 1Mhz but pyA13 GPIO achieve up to 100 kHz as Python is running faster on A13.
Apr 23, 2013 @ 21:02:18
Thanks for implementing this! I ran ‘python setup.py install’ and then tried to run the test program, but got this:
Traceback (most recent call last):
File “./test.py”, line 3, in
import iMX233_GPIO as GPIO
ImportError: dynamic module does not define init function (PyInit_iMX233_GPIO)
I then tried to rename initiMX233_GPIO to PyInit_iMX233_GPIO which fixed the init error; but now I run into this:
Traceback (most recent call last):
File “./leds.py”, line 3, in
import iMX233_GPIO as GPIO
ValueError: module functions cannot set METH_CLASS or METH_STATIC
Would you expect this code to work with Python3? I’m using Python 3.3.1, running on an ArchLinux distro on the OLinuXino-mini board.
Thanks for your help!
Apr 23, 2013 @ 21:22:36
sorry forgot to claify that this module is for python 2.7
Apr 24, 2013 @ 00:29:09
Thanks for the update – FYI I made some fixes so it works with Python3; you can find them in this patch:
https://github.com/mikevoyt/iMX233_GPIO/commit/3eb578f25d48fcabddb74290d435e7d8b8d6cab0
Apr 24, 2013 @ 01:37:33
FYI I also noticed a bug – PIN23 is not included in the init routine PyModule_AddObject, so there’s an off by 1 mapping error starting with PIN24. I fixed that in the commit below (oh, and added mappings for PIN7 & PIN8, which I needed for my project):
https://github.com/mikevoyt/iMX233_GPIO/commit/ee46908bb96da5b81e9d4d5a2e565bade05faabe
Apr 24, 2013 @ 15:37:11
Hi Olimex guys!
There is a faster python alternative:
http://www.cython.org/
😉
Apr 24, 2013 @ 16:01:22
Python developers interested in performance may also take a look at this, even if it is not Python:
https://live.gnome.org/Genie
Jan 01, 2014 @ 19:04:13
Hi! I fixed some bugs and made it work with Python3. You can find the module source here: https://github.com/droid4control/iMX233_GPIO
in iMX233 you can use it like this:
#!/usr/bin/python
import iMX233_GPIO as GPIO
import time
GPIO.setoutput(GPIO.LED)
GPIO.output(GPIO.LED, 0)
time.sleep(1)
GPIO.output(GPIO.LED, 1)