A13-OLinuXino GPIO Python libraries


Image

Python is one of the most popular languages in the last years, it’s used by Google for their search engine and many other apps like game designs, databases etc.

Python combines the easy of use of the interpretive languages with powerful datastructures, so it replaces the old days BASIC but opens up lot of new possibilities.

If you want to learn more about Python you can read http://www.learnstreet.com/lessons/study/python or the official Python language web site http://python.org/

The best of all are the Python libraries you can see thousands of these at https://pypi.python.org/pypi

A13-OLinuXino as any Linux platform can run Python language, what we were missing was GPIO library which to allow Python users to have access to A13-OLinuXino GPIOs.

Now this library is done! You can download is from https://pypi.python.org/pypi/pyA13/ or from GitHub: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A13/PYTHON-A13-GPIO

then install it:

#tar -zxvf pyA13-0.1.7.tar.gz
#cd pyA13-0.1.7.tar.gz
#sudo python setup.py install

after the installation you can use it this way:

#sudo python

>>> import A13_GPIO as GPIO
>>> GPIO.init()                           #init GPIOs
>>> GPIO.getcfg(GPIO.PIN37)               #config PIN37 as GPIO
>>> GPIO.setcfg(GPIO.PIN37, GPIO.OUTPUT)  #config PIN37 as output
>>> GPIO.output(GPIO.PIN37, GPIO.HIGH)    #set PIN37 high
>>> GPIO.output(GPIO.PIN37, GPIO.LOW)     #set PIN37 low
>>> GPIO.setcfg(GPIO.PIN37, GPIO.INPUT)   #config PIN37 as input
>>> GPIO.input(GPIO.PIN37)                #read PIN37

PINxx assignments is exactly as per A13-OLinuXino schematic

EDIT: Maximum GPIO toggle speed via Python is 101 kHz

11 Comments (+add yours?)

  1. Luigi
    Mar 10, 2013 @ 14:00:10

    Hello, first of all I congratulate you for your work 🙂

    I have tried the library but seems to not work. look at this

    https://www.olimex.com/forum/index.php?topic=1036.0

    thanks

    Reply

  2. TheDareGuy
    Mar 11, 2013 @ 14:34:15

    THAT’S GREAT !!!

    Thank you for start to implement APIs in Python !!!
    Python is the BEST CHOICE !!!

    Good job !!!

    Reply

  3. OLIMEX Ltd
    Mar 11, 2013 @ 14:40:28

    Indeed Python is very easy to use, we implemented now GPIOs, SPI and I2C APIs and demo codes for our UEXT modules will follow. This will make it very easy to start using the UEXT modules with A13 and IMX233 OLinuXino

    Reply

  4. LH
    Apr 01, 2013 @ 14:49:26

    did anyone port this for olinuxino yet (I have a maxi)?
    I’m having a look at the source code, maybe it’s possible to port this myself but if someone has already done it … I can save some time 🙂

    Reply

  5. LH
    Apr 03, 2013 @ 22:27:55

    Yes that’s what I mean.
    Looked at it last weekend and it looks fairly easy to do – will work on it this week to get basic I/O working first.

    Reply

  6. LH
    Apr 04, 2013 @ 04:43:40

    I created a similar version of this library for IMX233 today,
    the GPIO structure is quite different from the A13 it seems.

    Took me a few days to study-in but it seems pretty clear to me now how things work on the IMX233 (from the freescale documentation and thanks to gpio_mmap.h from David Whittaker, see also http://tech.groups.yahoo.com/group/olinuxino/message/2022)

    Tested on my Olinuxino Maxi, of course it’s a real ‘alpha version’: the only test I’ve been able to do sofar is blinking the green led 🙂

    If you want to test this for yourself, please download from pypi:
    https://pypi.python.org/pypi/pyIMX233

    place the package in root’s home directory on your olinuxino, unzip/tar, and run python install (which will compile/gcc the c code and take care of the package installation in the python tree!):

    —- to compile & install:
    [root@alarm ~]# mkdir demo
    [root@alarm ~]# cd demo
    [root@alarm demo]# tar zxf ../pyIMX233-0.0.1.tar.gz
    [root@alarm demo]# cd pyIMX233-0.0.1/
    [root@alarm pyIMX233-0.0.1]# python2 setup.py install

    —- test2.py, this should blink the led 1 sec on/1 sec off:
    #!/usr/bin/python2
    import IMX233_GPIO as GPIO # reference the GPIO library
    import time

    #init module
    GPIO.init()

    #configure pin65 for output (the port that drives the green led!)
    GPIO.setcfg(GPIO.PIN65, GPIO.OUT)

    #
    #read the current GPIO configuration (1=’output’)
    #(and no error means it’s a valid GPIO pin)
    #
    config = GPIO.getcfg(GPIO.PIN65)
    print “config pin 65={0}”.format(config)

    #
    # now blink 10 times
    #
    for i in range(10):
    print “round {0}”.format(i)

    #set GPIO high
    GPIO.output(GPIO.PIN65, GPIO.HIGH)

    time.sleep(1)

    #set GPIO low
    GPIO.output(GPIO.PIN65, GPIO.LOW)

    time.sleep(1)

    raw_input(‘Press return to exit’)

    #cleanup
    GPIO.cleanup()
    —–
    copy/paste the above text in a file testgpio.py and make the script executable:

    chmod 744 testgpio.py

    Then run it:
    ./testgpio.py

    Enjoy and let me know if there’s any problems – not sure how much time I can afford to ‘support’ but will try on best effort basis – or feel free to modify the package yourself of course – it’s open source of course 🙂

    Reply

  7. Trackback: iMX233-OLinuXino GPIO Python Libraries | olimex
  8. LH
    Apr 27, 2013 @ 19:28:17

    something must have gone wrong uploading, wasn’t familiar with the Pypi website I guess, silly!
    Ok I see there’s an official Olimex release now too, great.
    For what it is worth, I’ve still uploaded my 0.0.1 version for comparison…

    Reply

  9. Majid Manzoor
    Sep 10, 2014 @ 09:09:52

    Can we use LCD pins as GPIO?

    Reply

Leave a comment