Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Control GPIO, I2C and SPI

Project Description
This package provide methods for controlling GPIO pins, I2C and SPI buses.
This is written for A10-Lime, but it can be used with other boards. If you do
this we cannot guarantee proper operation of the module. Before using this
package we recommend reading the article at olimex wiki:

When using GPIO make sure that the desired gpio is not used by another periphery.


init() - Make initialization of the module. Always must be called first.
getcfg() - Read current configuration of gpio.
setcfg() - Write configuration to gpio.
input() - Return current value of gpio.
output() - Set output value.
pullup() - Set pull-up/pull-down.

The available constants are:

==== =========
HIGH -> 1
LOW -> 0
INPUT -> 0

The gpio are named two ways:

By port name: PH0, PG2, PE10, etc.
These can be imported from port module:

>>> from pyA10Lime.gpio import port
>>> dir(port)

By connector name and pin number: gpio2p12, gpio3p8, etc.
These can be imported from connector module:

>>> from pyA10Lime.gpio import connector
>>> dir(connector)

Generally these constants are just an offset in the memory from the base GPIO address, so they can
be assigned to a number type variable.

>>> led = port.PH2
>>> print led


init() - Make initialization of the module
open() - Begin communication with slave device
read() - Read from slave device
write() - Write data to slave device
close() - End communication with slave device


open() - Open SPI bus with given configuration
read() - Read data from slave device without write
write() - Write data to slave device without read
xfer() - Do write and after that read
close() - Close SPI bus



#!/usr/bin/env python

from pyA10Lime.gpio import gpio
from pyA10Lime.gpio import port
from pyA10Lime.gpio import connector

gpio.init() #Initialize module. Always called first

gpio.setcfg(port.PG9, gpio.OUTPUT) #Configure LED1 as output
gpio.setcfg(port.PG9, 1) #This is the same as above

gpio.setcfg(port.PE11, gpio.INPUT) #Configure PE11 as input
gpio.setcfg(port.PE11, 0) #Same as above

gpio.pullup(port.PE11, 0) #Clear pullups
gpio.pullup(port.PE11, gpio.PULLDOWN) #Enable pull-down
gpio.pullup(port.PE11, gpio.PULLUP) #Enable pull-up

while True:
if gpio.input(port.PE11) == 1:
gpio.output(port.PG9, gpio.LOW)
gpio.output(port.PG9, 0)
gpio.output(port.PG9, gpio.HIGH)
gpio.output(port.PG9, 1)


#!/usr/bin/env python

from pyA10Lime import i2c

i2c.init("/dev/i2c-2") #Initialize module to use /dev/i2c-2 #The slave device address is 0x55

#If we want to write to some register
i2c.write([0xAA, 0x20]) #Write 0x20 to register 0xAA
i2c.write([0xAA, 0x10, 0x11, 0x12]) #Do continuous write with start address 0xAA

#If we want to do write and read
i2c.write([0xAA]) #Set address at 0xAA register
value = #Read 1 byte with start address 0xAA

i2c.close() #End communication with slave device


#!/usr/bin/env python

from pyA10Lime import spi"/dev/spidev2.0")
#Open SPI device with default settings
# mode : 0
# speed : 100000kHz
# delay : 0
# bits-per-word: 8

#Different ways to open device"/dev/spidev2.0", mode=1)"/dev/spidev2.0", mode=2, delay=0)"/dev/spidev2.0", mode=3, delay=0, bits_per_word=8)"/dev/spidev2.0", mode=0, delay=0, bits_per_word=8, speed=100000)

spi.write([0x01, 0x02]) #Write 2 bytes to slave device #Read 2 bytes from slave device
spi.xfer([0x01, 0x02], 2) #Write 2 byte and then read 2 bytes.

spi.close() #Close SPI bus

It's important that you run your python script as root!

* pyA10Lime 0.2.1 (30 JUN 2015)
* Fixed issue with SPI xfer function

* pyA10Lime 0.2.0 (02 SEP 2014)
* Updated to enable SPI and I2C control
* GPIO constant in separate modules
* Added example files
* Added support for Python3

* pyA10Lime 0.1.0 (23 JAN 2014)
* Initial release
Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pyA10Lime-0.2.1.tar.gz (13.9 kB) Copy SHA256 Checksum SHA256 Source Jun 30, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting