SPIDEV0 and I2C issues on BBB in Python

I would expect this to be an easy question, but it has been beating me severely about the head and shoulders for the past week. I am running the 11.7 iot emmc flasher version (5.10) on a BBB. I have installed smbus2 If I attempt to use uboot_overlay_addr4=/lib/firmware/ADAFRUIT-SPI0-00A0.dtbo in the uEnv.txt file it doesn’t seem to work. I have switched to uboot_overlay_addr4=/lib/firmware/BB-SPIDEV0-00A0.dtbo. I am working out of VScode if that makes a difference. on just my SPI loopback test I get the following:
debian@BeagleBone:/dev$ python -u “/home/debian/examples/BeagleBone/test-spi.py”
Traceback (most recent call last):
File “/home/debian/examples/BeagleBone/test-spi.py”, line 11, in
spi = SPI(0,0)
PermissionError: [Errno 13] Permission denied
debian@BeagleBone:/dev$ sudo python -u “/home/debian/examples/BeagleBone/test-spi.py”
[32, 11, 110, 22, 220]

so I am not sure how to get the code window to run in sudo… Then the next issue pops up if I try to add smbus2 to the test.
debian@BeagleBone:/etc/udev/rules.d$ python -u “/home/debian/examples/BeagleBone/test-spi.py”
Traceback (most recent call last):
File “/home/debian/examples/BeagleBone/test-spi.py”, line 12, in
spi = SPI(0,0)
PermissionError: [Errno 13] Permission denied
debian@BeagleBone:/etc/udev/rules.d$ sudo python -u “/home/debian/examples/BeagleBone/test-spi.py”
Traceback (most recent call last):
File “/home/debian/examples/BeagleBone/test-spi.py”, line 2, in
import smbus2
ModuleNotFoundError: No module named ‘smbus2’

at this point my test code looks like this:

from Adafruit_BBIO.SPI import SPI
import smbus2

From Adafruit Learning System:

SPI | Setting up IO Python Library on BeagleBone Black | Adafruit Learning System

#spi = SPI(bus, device) #/dev/spidev.
#spi = SPI(0,0) #/dev/spidev1.0
#spi = SPI(0,1) #/dev/spidev1.1
#spi = SPI(1,0) #/dev/spidev2.0
#spi = SPI(1,1) #/dev/spidev2.1
bus = smbus2.SMBus(1)
spi = SPI(0,0)
spiResponse= spi.xfer2([32, 11, 110, 22, 220])
print (spiResponse)
spi.close()

So how is it that smbus2 only runs not as root, and SPI on runs as root?
debian@BeagleBone:/dev$ ls /dev/spi* -al
crw-rw---- 1 root spi 153, 0 Sep 2 18:02 /dev/spidev0.0
crw------- 1 root root 153, 1 Sep 2 18:02 /dev/spidev0.1
crw------- 1 root root 153, 2 Sep 2 18:02 /dev/spidev1.0
crw------- 1 root root 153, 3 Sep 2 18:02 /dev/spidev1.1

what does your “dmesg | grep spi” output

i get
pinctrl-single 44e10800.pinmux: pin PIN84 already requested by ocp:P9_22_pinmu
x; cannot claim for 48030000.spi
[ 9.559314] pinctrl-single 44e10800.pinmux: pin-84 (48030000.spi) status -22
[ 9.566450] pinctrl-single 44e10800.pinmux: could not request pin 84 (PIN84) from group sp
i0_pins_s0 on device pinctrl-single
[ 9.577914] omap2_mcspi 48030000.spi: Error applying setting, reverse things back
[ 9.585511] omap2_mcspi: probe of 48030000.spi failed with error -22

one other thing that i’m seeing
No such file or directory: ‘/sys/devices/platform/bone_capemgr/slots’

don’t know much about Adafruit_BBIO.SPI, but it appears to be for older images

also, there’s
/opt/source/spidev-test
just compile it with gcc

a quick search, apparently Adafruit stuff is no longer supported

I get a command executed and failed (exit code 1) on the dmesg | grep spi

I did get things up and running on 10.3 finally. So I may just keep going down that path since the 5.10 kernel seems to be an unmitigated disaster.

1 Like

It runs very well for us, we are even using the factory IoT image.

More than likely its your python code. Python is fine for certain applications, for controlling I/O it is the last choice. Big problem is python developers have you by the short hairs regarding I/O, you have to wait for them to fix the problem. When ever you abstract out the critical parts expect trouble. C/C++ is the only way to go if you demand world class software running your products.

1 Like