What I am trying to do

As part of setting up a robot with ubuntu the library I call to access spi is called spidev. When I do the following lines, I get the following error:

>>> import spidev
>>> spi = spidev.SpiDev()
>>> spi.open(0,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied

When I further examine things, I see this:

[onboard:mr2]~/catkin_ws$ ls -la /dev/spi*
crw------- 1 root root 153, 0 Apr  1  2020 /dev/spidev0.0
crw------- 1 root root 153, 1 Apr  1  2020 /dev/spidev0.1

Meaning that they seem to only be accessible to root. I believe it is a really bad idea to change file permissions of the /dev files. So my question is:

How do I enable /dev/spi* on Ubuntu 20.04 on Raspberry Pi?

  • It seems that the common advice is to run raspi-config. However, everything I have seen is that raspi-config is not available, or functional, on Ubuntu just on Raspian.

  • The other more promising advice is to modify one of the various config files. But for Ubuntu 20.04 server for Pi, I cannot find the corresponding ones.

  • One workaround is if I log in as root. So it kind of proves that it's a file permissions issue. But I don't know which file and again, it seems a bad idea to muck with permissions set by the system.

So I think I am barking up the wrong tree, but I don't know what else to try.

  • 1st Idea: Do any of the steps in this tutorial work? (It seems to show how to add non-root access for SPI, GPIO, and I2C) 2nd Idea: The ubuntu server install guide here shows enabling gpio for non-root access - perhaps there is a parallel for SPI and I2C - sorry if a dead end idea. May 30, 2021 at 17:39

1 Answer 1


Create /etc/udev/rules.d/90-gpio-spi.rules with:

KERNEL=="spidev0.0", OWNER="root", GROUP="spi"
KERNEL=="spidev0.1", OWNER="root", GROUP="spi"

Create the group itself and assign it to an existing user "ubuntu":

sudo groupadd -f --system spi
sudo usermod -a -G spi ubuntu


sudo shutdown -r now

And try again.

Source relating to issue with GPIO on Raspberry Pi

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.