SPI Bus in Python
@Tisham-Dhar the core logic can follow this function here: https://github.com/OnionIoT/omega2-lmic-lorawan/blob/master/native-spi.cpp#L110
Essentially it does two distinct transfers, one for writing and one immediately afterward for reading.
@Tisham-Dhar I've gone ahead and implemented a working half-duplex transmission function! Version 4.0.1 of
python-spidevfeatures a new
Getting the Latest Version of
If you don't have it installed already:
opkg update opkg install python-light python-spidev
If you have it installed, you'll need to upgrade:
opkg update opkg upgrade python-spidev
To use the new function:
values = spi.xfer3([<list of bytes to write>], <number of bytes to read>)
This will write all of the bytes from the list in the first argument and will then immediately read the number of bytes specified by the second argument.
The function will return a list of the bytes that were read.
Instead of using
values = spi.xfer3([0x80,0xD9], 2)
More details can be found in our python-spidev github repo readme
Let me know how it goes!
@Lazar-Demin Is this still just for python 2??? is there a python 3 version??
@Juan-Pablo-Jimenez A python3 version is now available as well! See https://github.com/OnionIoT/python-spidev#installation-on-omega2
@Lazar-Demin I cannot install version for python3.. it says "Unknown package 'python3-spidev'"
@Pablo-Fonovich Which firmware version are you running?
I ask because python3-spidev is published in the new package repo. Try upgrading your firmware to v0.3.0 or higher and trying again.
@Lazar-Demin Oh thanks! i had updated to the latest stable. I'm trying right now.
@Lazar-Demin That worked! thanks.. are gpio and serial packages available for pyhton3?
@Pablo-Fonovich you can get a list of available python3 packages by running:
opkg opkg list | grep python3
You can also install
python3-pipto install Python packages, see this guide for more details.
@Lazar-Demin , thanks, i've already knew that... but i cannot find any gpio module for python3, nor can i find a serial module for python3.. Are they available?
@Lazar-Demin Hey, sorry to continue this after this long. but i started with a second device, isntalled python3-pip, but command line says pip3 not found.. what could be happening?
@Lazar-Demin In fact, i can see pip3 binary in /usr/bin/, but running it, even with full absolute path, returns not found error
Maybe take a look at Lazar's recent response