GitHub - OnionIoT - Python-Spidev Python Module For Interfacing With SPI Devices
GitHub - OnionIoT - Python-Spidev Python Module For Interfacing With SPI Devices
com/OnionIoT/python-spidev
GPL-2.0 license
Star Notifications
1 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
master Go to file
Lazar updated readme to explicitly call out half duplex and full du… … on Apr 23, 2020 97
View code
README.md
2 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
3 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
4 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
Releases
Python Spidev
No releases published
This project contains a python module for interfacing with SPI devices from user space
via the spidev linux kernel driver.
Packages
No packages
This ispublished
a modified version of the code originally found here
• https://onion.io/2bt-brand-new-os-release/#spiimprovement
5 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
• http://community.onion.io/topic/3179/spi-bus-in-python/17
Installation on Omega2
The spidev module is available for Python2 and Python3, the installation
commands are slightly different.
Connect to the Omega's command line and run the following commands to install the
Python2 module:
opkg update
opkg install python-light python-spidev
opkg update
opkg install python3-light python3-spidev
Usage
import spidev
spi = spidev.SpiDev()
spi.open(bus, device)
to_send = [0x01, 0x02, 0x03]
spi.xfer(to_send)
Settings
import spidev
spi = spidev.SpiDev()
spi.open(bus, device)
6 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
...
• 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
Methods
Connects to the specified SPI device, opening /dev/spidev<bus>.<device>
open(bus, device)
Read n bytes from SPI device. Returns list of bytes read by SPI controller
readbytes(n)
writebytes(list of values)
7 of 8 11/10/2022, 1:08 PM
GitHub - OnionIoT/python-spidev: Python module for interfacing with ... https://github.com/OnionIoT/python-spidev
Performs an SPI transaction. Chip-select should be held active between blocks. Returns
list of bytes read by SPI controller.
close()
Half-Duplex Transmissions
Performs a half-duplex SPI transaction. Chip-select should be held active between
blocks. Returns list of bytes read by SPI controller.
Use this function when the intent is to write a number of bytes and then
immediately read a number of bytes (register reads for example)
8 of 8 11/10/2022, 1:08 PM