Skip to main content

Python interface for SPI communications

Project description

python3-spi

Python 3.x interface for SPI communications using Linux spidev

This is a fork of https://github.com/tomstokes/python-spi which seems to be abandoned with the python 3 compatibility patch proposed by Tom Egan applied.

Features

  • Pure Python implementation. No C module to compile.
  • Supports half-duplex reads and writes as well as full-duplex transfers.
  • Exposes all available spidev interface options as properties.

Requirements

  • spidev enabled in the kernel and (if necessary) the device tree.
  • Write permissions to the /dev/spidevN.N device.
    • Some distributions have an 'spi' group for this purpose. If available, add this group to the user account and ensure the spidev device is group-writeable.
    • If no 'spi' group exists, a udev rule can be created to set the permissions of the spidev device.
    • As a last resort, running the python script as root should allow access to the spidev. Note This is not recommended. Use the 'spi' group or udev rules whenever possible.

Example

import spi
spi = SPI("/dev/spidev1.0")
spi.mode = SPI.MODE_0
spi.bits_per_word = 8
spi.speed = 500000
received = spi.transfer([0x11, 0x22, 0xFF])
spi.write([0x12, 0x34, 0xAB, 0xCD])
received = spi.read(10)

Project details


Download files

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

Source Distribution

python3-spi-0.3.1.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

python3_spi-0.3.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page