RaspberryCruiser
Posts: 1
Joined: Thu Jul 07, 2016 8:35 am

spi.open(0,0) IOError: Errno 2 No such file or directory

Thu Jul 14, 2016 5:35 am

I am very new to Python programming, so please be patient.
I am trying to use an MCP3208 chip to input light levels.

I have downloaded a py script (mcp3008_tmp36.py), and run it.
Then I get "spi.open(0,0) IOError: Errno 2 No such file or directory"

The previous lines are:

import spidev
import time
import os

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

I have updated and upgraded before trying to run the script.
Any help would be appreciated
Thank you.

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Fri Jul 15, 2016 12:31 am

Have you enabled SPI in sudo raspi-config?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Wed Jan 18, 2017 11:59 pm

Hi there. Just wondering whether we can get this thread restarted because I, too, have the following error:

Code: Select all

IOError: [Errno 2] No such file or directory
This error comes after the following code is executed:

Code: Select all

import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
while True:
   resp = spi.xfer2([0x00])
   print resp[0]
   time.sleep(1) 
Another note - have also ensured using raspi-config that SPI is on, yet nothing.
Would love some help!

Thanks,
B

User avatar
joan
Posts: 15784
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Thu Jan 19, 2017 9:12 am

What is reported by

ls /dev/spi*

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sat Jan 21, 2017 3:43 am

joan wrote:What is reported by

ls /dev/spi*
It says no such file or directory! Also ran ls | grep "sp" and nothing came up either.

User avatar
joan
Posts: 15784
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sat Jan 21, 2017 10:03 am

SPI is not enabled.

Are you using a recent Raspbian image?

uname -a
cat /etc/os-release

Do you have the line dtparam=spi=on in /boot/config.txt?

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sun Jan 22, 2017 3:38 am

joan wrote:SPI is not enabled.

Are you using a recent Raspbian image?

uname -a
cat /etc/os-release

Do you have the line dtparam=spi=on in /boot/config.txt?

Thanks for getting back to me, Joan! I'm almost certain it is enabled, though. So in raspi-config it is enabled and I'm on Jessie. Futher, I have already ammended the dtparam line you mentioned above to the boot config file.

I don't suppose you know what the next step is?

User avatar
joan
Posts: 15784
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sun Jan 22, 2017 10:27 am

result of uname -a

contents of /etc/os-release

contents of /boot/config,txt

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sun Jan 22, 2017 10:36 am

In an LXterminal run
grep -i 'dtparam' /boot/config.txt
and check that sudo raspi-config has done the right stuff.

Then reboot.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Mon Jan 23, 2017 10:53 pm

Thanks all!

Results:

Code: Select all

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.34+ #930 Wed Nov 23 15:12:30 GMT 2016 armv6l GNU/Linux
pi@raspberrypi:~ $ vi /etc/os-release/
NOTHING THERE
pi@raspberrypi:~ $ cd /etc/os-release
-bash: cd: /etc/os-release: Not a directory
pi@raspberrypi:~ $ vi /boot/config.txt 

# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

#Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

dtoverlay=w1-gpio,pullup=y
Dougie, this is the results of your query (of course, also found above if you wish to see in context!)

Code: Select all

pi@raspberrypi:~ $ grep -i 'dtparam' /boot/config.txt 
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
dtparam=audio=on

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Mon Jan 23, 2017 11:23 pm

Have you rebooted with that config?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Mon Jan 23, 2017 11:29 pm

DougieLawson wrote:Have you rebooted with that config?
Thanks for the quick reply - should have said so, but yes I have!

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Mon Jan 23, 2017 11:44 pm

Can you run sudo fdisk -l /dev/mmcblk0 and post the results.

Is your system run Raspbian because on my Raspbian systems there's a /etc/os-release file which looks like

Code: Select all

PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 12:01 am

DougieLawson wrote:Can you run sudo fdisk -l /dev/mmcblk0 and post the results.

Is your system run Raspbian because on my Raspbian systems there's a /etc/os-release file which looks like

Code: Select all

PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Hi again Dougie,
Yep - running Jessie (lite, I think?) and that file does exist which you are referring to; I must have made a typo copying it in, but the file is there and it looks identical to the one you've provided above.

As for your disk operation command, the results are as follows:
Disk /dev/mmcblk0: 3.7GiB
disklabel: DOS

Device:
/dev/mmcblk0p1 is FAT32 with 63MB size
/dev/mmcblk0p2 is Linux type and 3.6GB

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 12:14 am

Have a look at /etc/modprobe.d/raspi-blacklist.conf is spi blacklisted in that file?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 12:20 am

DougieLawson wrote:Have a look at /etc/modprobe.d/raspi-blacklist.conf is spi blacklisted in that file?

The file is empty, I'm afraid.

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 12:21 am

Try sudo rpi-update to get a 4.4.44 kernel and latest bootcode.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 1:07 am

DougieLawson wrote:Try sudo rpi-update to get a 4.4.44 kernel and latest bootcode.
Hi Dougie,
Done!

Should I now reattempt all of the above? Or perhaps just check the raspi-config is still correct and then check the blacklist?

BC

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 10:54 am

Your config.txt and cmdline.txt don't change when you run rpi-update. It updates lots of other bits in /boot and /lib/modules.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

bcartwri
Posts: 10
Joined: Wed Jan 18, 2017 11:50 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Tue Jan 24, 2017 10:49 pm

DougieLawson wrote:Your config.txt and cmdline.txt don't change when you run rpi-update. It updates lots of other bits in /boot and /lib/modules.
Thanks for that - updated. I don't suppose there are any more steps before it is better just to reflash a copy of Jessie to the CM?

Thanks, again!

jezcaudle
Posts: 5
Joined: Tue Mar 11, 2014 10:18 am

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Wed Nov 01, 2017 1:00 pm

I had the same problem and followed all the steps and still got the same error, what allowed me to run the code was:

Code: Select all

sudo python program_name
Without sudo I go the error, with sudo I didn't.

I hope this helps either you or others.

Lakshana
Posts: 7
Joined: Fri Dec 22, 2017 8:19 am

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Thu Jan 11, 2018 8:46 am

Try installing spidev and also check ls /dev/spi*... if you are getting something like /dev/spidev1.0 then write 1 instead of the first 0 in spi.open(0,0)...hope this works!

wilgaced
Posts: 1
Joined: Fri Aug 02, 2019 6:31 am

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Fri Aug 02, 2019 6:33 am

Edit /boot/config.txt, add the following line, and reboot.

dtoverlay=spi1-3cs

You should then have the following devices.

$ ls /dev/sp*
/dev/spidev0.0 /dev/spidev0.1 /dev/spidev1.0 /dev/spidev1.1 /dev/spidev1.2

Michael1989
Posts: 4
Joined: Sun Aug 16, 2020 1:43 pm

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sun Aug 16, 2020 1:49 pm

Hey


This is my first work experience with raspberry pi, i use raspberry pi 3b+
I do not have these spidev files.
What do I need to do now?

Michael

DirkS
Posts: 10699
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: spi.open(0,0) IOError: Errno 2 No such file or directory

Sun Aug 16, 2020 4:47 pm

Michael1989 wrote:
Sun Aug 16, 2020 1:49 pm
Hey


This is my first work experience with raspberry pi, i use raspberry pi 3b+
I do not have these spidev files.
What do I need to do now?

Michael
Did you activate SPI?

Return to “Troubleshooting”