JackNoobie
Posts: 3
Joined: Fri Apr 05, 2013 3:13 pm

SPI

Fri Apr 05, 2013 3:21 pm

Hi, I'm new to debian linux, raspberry pi.
I have my Pi up and running flashing leds on the GPIO on certain events and emailing me on certain events. Now I want to interface to an ADC something like the MCP3008 using SPI. I've tried following instructions on installing spidev but when I include "import spidev" in my python script , i just get an "ImportError: No module named spidev". I tried numerous different methods outlined on the web but still can;t solve this one. Is there an idiot proof step by step instruction anywhere on how to install this and have it working? cheers

vistauser
Posts: 8
Joined: Mon Mar 18, 2013 6:48 pm

Re: SPI

Fri Apr 05, 2013 4:39 pm

Hallo,
have you followed the instructions from Alex?

Analog < > Digital converter programs (NEW 13 December 2012)
=====================================
To make use of atod.py, dtoa.py and dad.py you MUST have SPI enabled

sudo nano /etc/modprobe.d/raspi-blacklist.conf

make sure there IS a # before blacklist spi-bcm2708, so it looks like this...
#blacklist spi-bcm2708

Adding this # prevents SPI being disabled. If you had to change it, you'll need to
reboot to activate SPI.

sudo reboot

You will need to install the Python SPI wrapper: (Python 2.7)

cd ~
git clone git://github.com/doceme/py-spidev


If you don’t have git installed, the above command will fail. Install git with...

sudo apt-get update
sudo apt-get install git

When asked if you want to continue, answer Y
then, after installation, try again
git clone git://github.com/doceme/py-spidev

then it should copy the files into a directory called py-spidev. Go there next

cd py-spidev/
If you have already installed WiringPi for Python the next step (python-dev) may not be necessary...

then type
sudo apt-get install python-dev
y (to confirm).

sudo python setup.py install
And after that you should be able to use the ADC/DAC programs. No further reboot needed.

JackNoobie
Posts: 3
Joined: Fri Apr 05, 2013 3:13 pm

Re: SPI

Fri Apr 05, 2013 10:16 pm

Thanks, Yes had found this and have done all this. spidev is listed when I do lsmod, but still comes up with the error when I add "import spidev" . I'd rather not rbuild the whole thing again from scratch but might have to if I can't get anywhere with this.
What should I check to ensure its all installed properly?

trouch
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
Contact: Website

Re: SPI

Sat Apr 06, 2013 3:56 pm

take a look on WebIOPi
it include a full I2C/SPI python stack with no dependency.
it also have many devices drivers, including MCP3008
https://code.google.com/p/webiopi/wiki/MCP3000
https://code.google.com/p/webiopi/wiki/ ... on_example

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com

JackNoobie
Posts: 3
Joined: Fri Apr 05, 2013 3:13 pm

Re: SPI

Sun Apr 07, 2013 9:49 pm

Thanks for you help (vistauser) and suggestions (trouch -will look at that some day soon).
After much playing around I now discover it works in Python 2.7 but does not work in Python 3 ("No module named spidev"). Does that make any sense?
Anyway, I'm happy to continue with 2.7

trouch
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
Contact: Website

Re: SPI

Sun Apr 07, 2013 10:41 pm

thats the cool thing with webiopi
none of official i2c or spi python module works with python 3
webiopi i2c/spi stack works with both python 2 and 3 !

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com

Jupiter1
Posts: 1
Joined: Wed Jul 03, 2013 5:31 pm

Re: SPI

Wed Jul 03, 2013 5:34 pm

I am trying to use the SPI interface as pi user. but when I do this I get
>>> spi.open(0,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied
>>> exit

But if I use Python as sudo then it works ok. How do I use teh SPI as a normal user pi please?

Many thanks

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: SPI

Mon Jul 08, 2013 2:44 pm

Writing to the GPIO port requires admin privileges, so Sudo will be required if not logged in with appropriate log in.
Don't think there is any way around it,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

notro
Posts: 695
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: SPI

Tue Jul 09, 2013 12:54 am

You could also change the permissions on the device:
sudo chmod 666 /dev/spidev0.0

To make it permanent, add to /etc/rc.local
A professional solution would be to make an udev rule, but that is beyond me.

bhollehday
Posts: 19
Joined: Thu Mar 27, 2014 12:53 am

Re: SPI

Thu Apr 24, 2014 7:00 am

Im having a similar issue getting SPI to work. I noticed when I installed git clone, it ran through a couple errors like the links were out of date or something. Im running python 2.7.3

failed to fetch http://mirrordirector.raspbian.org/rasp ... aremhf.deb 404 not found

It had like 5 or 6 of these in the command line. Any ideas?

I keep getting no such module name spidev error.

Im trying to get my OLED up and running but no luck!

This is what ive been using...
https://learn.adafruit.com/adafruit-ole ... ur-display

Return to “Interfacing (DSI, CSI, I2C, etc.)”