I got trouble with a seemingly dumb-proofly simple code:

import time
import pigpio
import spidev

DS = 17
STCP = 27
SHCP = 22
MR = 5

spi = spidev.SpiDev()
spi.open(0, 0)

Running the code gives error:

Traceback (most recent call last):
    File "shiftreg.py", line 12, in <module>
    IOError: [Errno 22] Invaild argument

I tried using spi.xfer(0b10011011), throws

TypeError: Argument must be a list of least one, but not more than 4096 integers

Using list(0b10011011) does not work, of course:

TypeError: 'int' object is not iterable

As you see, I am only at the very beginning of the code (yust waned to try out how the default SPI setup works with a shift register), so there are unused variables and imports. Since all my parenthesis are okey, the code complies well, I am pretty much in a WTF state now.

((unrelated, but if I am here with this code...) Oh, and if you know any good rescource for controlling a shift register via SPI, please let me know.)

  • 2
    The root cause is likely to be that given in the answer here raspberrypi.stackexchange.com/questions/27204/… – joan Jan 22 '16 at 17:49
  • @joan So you say this might be a SpiDev bug? It is strange because I have another code that uses it, and it works flawlessly. (And still, if the module is broken, I would expext the error happening in the module not in my code...) Does anyone know any good alternative? (I do not like it too much, the documentation is awful.) – Neinstein Jan 22 '16 at 18:01
  • It is odd that the same module works with other code - however I would upgrade the module. The error is identical to the one I got before upgrading. Your code mentions pigpio. You could try its SPI support, see abyz.co.uk/rpi/pigpio/python.html#spi_open. It may be sufficient for your needs. – joan Jan 22 '16 at 18:13
  • Also, the first error IOError is passed on by the module. – goldilocks Jan 22 '16 at 18:15
  • Trying the update, right now apt-get updating (just in case...) Until it is finished, here is the code that works, in case anyone wishes to solve this puzzle. (It is for playing with a max7219-based led array.) gist.github.com/godot11/7ca8839943afd923f704 – Neinstein Jan 22 '16 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.