Page 1 of 1

Python libraries for hardware ports like i2c, spi

Posted: Sat Jul 13, 2013 1:25 pm
by helpme
Are there python libraries for controlling hardware ports like i2c and spi on the Raspberry Pi? Besides i2c/spi masters, is it possible that there are libraries that allow us to use Raspberry Pi as i2c/spi slaves?

Re: Python libraries for hardware ports like i2c, spi

Posted: Sat Jul 13, 2013 8:47 pm
by ghp
Hello,
for SPI, use "spidev". You also need to start the driver "sudo modprobe spi_bcm2708".
There are good tutorials at adafruit, demonstrating SPI for python.
The code snipped is just copied and shorted from one of may programs. It just demonstrates the basic usage.

Code: Select all

# -*- coding: utf-8 -*-
    import spidev
    -- os.system("modprobe spi_bcm2708")

        self.spi = spidev.SpiDev()
        self.spi.open(bus, device)
        self.spi.max_speed_hz = 1000000

        self.spi.xfer (list(bytesS))

Greetings
Gerhard

Re: Python libraries for hardware ports like i2c, spi

Posted: Mon Jul 15, 2013 2:28 pm
by TonyD
for I2C bus search for smbus and for GPIO search for RPi.GPIO