2

I was happily controlling Shiftbrite LEDs using SPI and Python based on this code

Today I upgraded my Pi using

sudo apt-get update && sudo apt-get dist-upgrade
sudo rpi-update

Now my script no longer works. I get this error:

File "/home/pi/shiftbrite/go.py", line 81, in <module>
    fcntl.ioctl(spidev, 0x40046b04, array.array('L', [5000000]))
IOError: [Errno 25] Inappropriate ioctl for device

Might the value 0x40046b04 need to change since the upgrade? And I wonder if it was the upgrade to Raspbian or the Pi firmware that caused this.

1

The value 0x40046b04 is the value of macro SPI_IOC_WR_MAX_SPEED_HZ and there have been no changes there.

Are you sure spidev is an open descriptor for a SPI device?


The following code works on my Pi2.

Raspbian 3.18.8-v7+ #765 SMP PREEMPT

#!/usr/bin/env python

import time
import math
import array
import fcntl

spidev = file("/dev/spidev0.0", "wb")

rgb=bytearray(3)

#set the spi frequency to 20 kbps
fcntl.ioctl(spidev, 0x40046b04, array.array('L', [20000]))

while True :

   for i in range(0, 48):
      #use your own colors here
      rgb[0] = 1
      rgb[1] = 1
      rgb[2] = 1
      spidev.write(rgb)

   spidev.flush()
   time.sleep(0.2)
  • Hi Joan. I have exactly the same Raspbian version, and your code gives me the same error I have been getting. I'm sorry I don't understand what you mean by "Are you sure spidev is an open descriptor for a SPI device?" – TrevorJ Mar 5 '15 at 23:29
  • I just meant was spidev the result of opening a non SPI device, in which case the SPI specific IOCTL would be illegal. – joan Mar 6 '15 at 7:39
1

The solution was to re-enable SPI in raspi-config as described in I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Funnily enough I was led to that post by this previous answer by Joan - thanks Joan!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.