spidev


Namespidev JSON
Version 3.6 PyPI version JSON
download
home_pagehttp://github.com/doceme/py-spidev
SummaryPython bindings for Linux SPI access through spidev
upload_time2022-11-03 20:39:08
maintainerStephen Caudle
docs_urlNone
authorVolker Thoms
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Python Spidev
=============

This project contains a python module for interfacing with SPI devices from user space via the spidev linux kernel driver.

All code is MIT licensed unless explicitly stated otherwise.

Usage
-----

```python
import spidev
spi = spidev.SpiDev()
spi.open(bus, device)
to_send = [0x01, 0x02, 0x03]
spi.xfer(to_send)
```
Settings
--------

```python
import spidev
spi = spidev.SpiDev()
spi.open(bus, device)

# Settings (for example)
spi.max_speed_hz = 5000
spi.mode = 0b01

...
```

* `bits_per_word`
* `cshigh`
* `loop` - Set the "SPI_LOOP" flag to enable loopback mode
* `no_cs` - Set the "SPI_NO_CS" flag to disable use of the chip select (although the driver may still own the CS pin)
* `lsbfirst`
* `max_speed_hz`
* `mode` - SPI mode as two bit pattern of clock polarity and phase [CPOL|CPHA], min: 0b00 = 0, max: 0b11 = 3
* `threewire` - SI/SO signals shared
* `read0` - Read 0 bytes after transfer to lower CS if cshigh == True

Methods
-------

    open(bus, device)

Connects to the specified SPI device, opening `/dev/spidev<bus>.<device>`

    readbytes(n)

Read n bytes from SPI device.

    writebytes(list of values)

Writes a list of values to SPI device.

    writebytes2(list of values)

Similar to `writebytes` but accepts arbitrary large lists.
If list size exceeds buffer size (which is read from `/sys/module/spidev/parameters/bufsiz`),
data will be split into smaller chunks and sent in multiple operations.

Also, `writebytes2` understands [buffer protocol](https://docs.python.org/3/c-api/buffer.html)
so it can accept numpy byte arrays for example without need to convert them with `tolist()` first.
This offers much better performance where you need to transfer frames to SPI-connected displays for instance.

    xfer(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be released and reactivated between blocks.
Delay specifies the delay in usec between blocks.

    xfer2(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be held active between blocks.

    xfer3(list of values[, speed_hz, delay_usec, bits_per_word])

Similar to `xfer2` but accepts arbitrary large lists.
If list size exceeds buffer size (which is read from `/sys/module/spidev/parameters/bufsiz`),
data will be split into smaller chunks and sent in multiple operations.

    close()

Disconnects from the SPI device.

Changelog
---------

3.6
====

* Added read0 flag to enable reading 0 bytes after transfer to lower CS when cshigh == True

3.5
====

* Fixed memory leaks

3.4
=====

* Changed license to MIT

3.0.1
=====

* Fixed README.md and CHANGELOG.md formatting, hopefully

3.0
===

* Memset fix recommended by Dougie Lawson
* Fixes for Kernel 3.15+ from https://github.com/chrillomat/py-spidev
* Fixes for Python 3/2 compatibility.
* Added subclassing support - https://github.com/doceme/py-spidev/issues/10

2.0
===

Code sourced from http://elk.informatik.fh-augsburg.de/da/da-49/trees/pyap7k/lang/py-spi
and modified.

Pre 2.0
=======

spimodule.c originally uathored by Volker Thoms, 2009.



            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/doceme/py-spidev",
    "name": "spidev",
    "maintainer": "Stephen Caudle",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "scaudle@doceme.com",
    "keywords": "",
    "author": "Volker Thoms",
    "author_email": "unconnected@gmx.de",
    "download_url": "https://files.pythonhosted.org/packages/c7/d9/401c0a7be089e02826cf2c201f489876b601f15be100fe391ef9c2faed83/spidev-3.6.tar.gz",
    "platform": null,
    "description": "Python Spidev\n=============\n\nThis project contains a python module for interfacing with SPI devices from user space via the spidev linux kernel driver.\n\nAll code is MIT licensed unless explicitly stated otherwise.\n\nUsage\n-----\n\n```python\nimport spidev\nspi = spidev.SpiDev()\nspi.open(bus, device)\nto_send = [0x01, 0x02, 0x03]\nspi.xfer(to_send)\n```\nSettings\n--------\n\n```python\nimport spidev\nspi = spidev.SpiDev()\nspi.open(bus, device)\n\n# Settings (for example)\nspi.max_speed_hz = 5000\nspi.mode = 0b01\n\n...\n```\n\n* `bits_per_word`\n* `cshigh`\n* `loop` - Set the \"SPI_LOOP\" flag to enable loopback mode\n* `no_cs` - Set the \"SPI_NO_CS\" flag to disable use of the chip select (although the driver may still own the CS pin)\n* `lsbfirst`\n* `max_speed_hz`\n* `mode` - SPI mode as two bit pattern of clock polarity and phase [CPOL|CPHA], min: 0b00 = 0, max: 0b11 = 3\n* `threewire` - SI/SO signals shared\n* `read0` - Read 0 bytes after transfer to lower CS if cshigh == True\n\nMethods\n-------\n\n    open(bus, device)\n\nConnects to the specified SPI device, opening `/dev/spidev<bus>.<device>`\n\n    readbytes(n)\n\nRead n bytes from SPI device.\n\n    writebytes(list of values)\n\nWrites a list of values to SPI device.\n\n    writebytes2(list of values)\n\nSimilar to `writebytes` but accepts arbitrary large lists.\nIf list size exceeds buffer size (which is read from `/sys/module/spidev/parameters/bufsiz`),\ndata will be split into smaller chunks and sent in multiple operations.\n\nAlso, `writebytes2` understands [buffer protocol](https://docs.python.org/3/c-api/buffer.html)\nso it can accept numpy byte arrays for example without need to convert them with `tolist()` first.\nThis offers much better performance where you need to transfer frames to SPI-connected displays for instance.\n\n    xfer(list of values[, speed_hz, delay_usec, bits_per_word])\n\nPerforms an SPI transaction. Chip-select should be released and reactivated between blocks.\nDelay specifies the delay in usec between blocks.\n\n    xfer2(list of values[, speed_hz, delay_usec, bits_per_word])\n\nPerforms an SPI transaction. Chip-select should be held active between blocks.\n\n    xfer3(list of values[, speed_hz, delay_usec, bits_per_word])\n\nSimilar to `xfer2` but accepts arbitrary large lists.\nIf list size exceeds buffer size (which is read from `/sys/module/spidev/parameters/bufsiz`),\ndata will be split into smaller chunks and sent in multiple operations.\n\n    close()\n\nDisconnects from the SPI device.\n\nChangelog\n---------\n\n3.6\n====\n\n* Added read0 flag to enable reading 0 bytes after transfer to lower CS when cshigh == True\n\n3.5\n====\n\n* Fixed memory leaks\n\n3.4\n=====\n\n* Changed license to MIT\n\n3.0.1\n=====\n\n* Fixed README.md and CHANGELOG.md formatting, hopefully\n\n3.0\n===\n\n* Memset fix recommended by Dougie Lawson\n* Fixes for Kernel 3.15+ from https://github.com/chrillomat/py-spidev\n* Fixes for Python 3/2 compatibility.\n* Added subclassing support - https://github.com/doceme/py-spidev/issues/10\n\n2.0\n===\n\nCode sourced from http://elk.informatik.fh-augsburg.de/da/da-49/trees/pyap7k/lang/py-spi\nand modified.\n\nPre 2.0\n=======\n\nspimodule.c originally uathored by Volker Thoms, 2009.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python bindings for Linux SPI access through spidev",
    "version": "3.6",
    "project_urls": {
        "Homepage": "http://github.com/doceme/py-spidev"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "287348c2f27691b95dc7eff2263e92e62522b2f034186be5ecc294087b3d38aa",
                "md5": "e5b17670981a7fb3d5e8573f88ec2cfb",
                "sha256": "280abc00a1ef7780ef62c3f294f52a2527b6c47d8c269fea98664970bcaf6da5"
            },
            "downloads": -1,
            "filename": "spidev-3.6-cp39-cp39-linux_armv7l.whl",
            "has_sig": false,
            "md5_digest": "e5b17670981a7fb3d5e8573f88ec2cfb",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 40010,
            "upload_time": "2022-11-03T10:53:54",
            "upload_time_iso_8601": "2022-11-03T10:53:54.474685Z",
            "url": "https://files.pythonhosted.org/packages/28/73/48c2f27691b95dc7eff2263e92e62522b2f034186be5ecc294087b3d38aa/spidev-3.6-cp39-cp39-linux_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7d9401c0a7be089e02826cf2c201f489876b601f15be100fe391ef9c2faed83",
                "md5": "83a73279d6e823a9030c4315577bfae3",
                "sha256": "14dbc37594a4aaef85403ab617985d3c3ef464d62bc9b769ef552db53701115b"
            },
            "downloads": -1,
            "filename": "spidev-3.6.tar.gz",
            "has_sig": false,
            "md5_digest": "83a73279d6e823a9030c4315577bfae3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11917,
            "upload_time": "2022-11-03T20:39:08",
            "upload_time_iso_8601": "2022-11-03T20:39:08.257418Z",
            "url": "https://files.pythonhosted.org/packages/c7/d9/401c0a7be089e02826cf2c201f489876b601f15be100fe391ef9c2faed83/spidev-3.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-03 20:39:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "doceme",
    "github_project": "py-spidev",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "spidev"
}
        
Elapsed time: 0.07373s