Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class does not work with Pi2 due to RPi.GPIO not working (yet) #19

Open
liamkennedy opened this issue Feb 11, 2015 · 50 comments
Open

Class does not work with Pi2 due to RPi.GPIO not working (yet) #19

liamkennedy opened this issue Feb 11, 2015 · 50 comments

Comments

@liamkennedy
Copy link

Just a heads up (which you probably already know).. this class does not work in a Pi2 due to the RPi.GPIO library not supporting the Pi2 currently. I have heard there is a Dev version of RPi.GPIO available. I have not yet tried that.

Thanks!

-Liam

@ghost
Copy link

ghost commented Feb 11, 2015

AH
That why I couldn't get it to work
Thanks

@liamkennedy
Copy link
Author

The folks from PiMoroni sent me to this branch of the library which does not need to use RPi.GPIO
https://github.com/gadgetoid/piglow

@Boeeerb
Copy link
Owner

Boeeerb commented Feb 11, 2015

Thanks for keeping everyone updated Liam!
It's a very easy fix, as all RPi.GPIO does is check what version of Pi you have so it knows which i2c bus to use.
I haven't got round to getting myself a Pi2 yet, but after seeing the changes it didn't seem like there is anything I needed to update, just await on the dependancies to catch up. I know there are other ways around the version check, but not had time to play yet.

@ghost
Copy link

ghost commented Feb 12, 2015

hi
when im trying to run any script i get this,

pi@raspberrypi ~/PiGlow $ sudo python cpu.py
Traceback (most recent call last):
File "cpu.py", line 13, in
piglow = PiGlow()
File "/home/pi/PiGlow/piglow.py", line 25, in init
self.bus = SMBus(i2c_bus)
IOError: [Errno 2] No such file or directory

im new to this so i don't know what it means or what to do about it.
thanks

@liamkennedy
Copy link
Author

type this command

sudo nano /boot/config.txt

and add this line to the end of your /boot/config.txt file

dtparam=i2c_arm=on

@ghost
Copy link

ghost commented Feb 13, 2015

Thanks
I will try this when I get home and report back

@liamkennedy
Copy link
Author

Make sure you reboot after making this change to /boot/config.txt

This is what made everything work for me...and I got the same error as you did.

@DougRamsey
Copy link

I had this excact same issue with my pi2 and the suggested fix to the config.txt and the new piglow installlaton and reboot resulted in the exact same i/o error. Wonder why this did not work for me?

@electronicsguy
Copy link

If you're uncomfortable with manually entering those commands, just do "sudo apt-get update" && sudo apt-get upgrade and then use raspi-config to enable I2C bus. It has been updated to use the new device trees.

@liamkennedy
Copy link
Author

@DougRamsey - you have to also use the workaround piglow.py I referenced above.
https://github.com/gadgetoid/piglow

Have you done that or are you still using the one in this library?

@DougRamsey
Copy link

Thanks electronics guy and liamkennedy
Tried both suggestions and still get the following when trying to use PyGlow module on the pi2
pi@raspberrypi ~/PiGlow/Examples $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 9, in
piglow = PiGlow()
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 25, in init
self.bus = SMBus(i2c_bus)
IOError: [Errno 2] No such file or directory

Not sure if the setup took care of installing the piglow file you mentioned above. I am new to pi and lynux so help is appreciated.

@liamkennedy
Copy link
Author

I'm at a loss to know what else to suggest. If you changed config.txt and you are using the replacement piglow.py code I have no further ideas. Sorry

@electronicsguy
Copy link

@DougRamsey Did you do install the python smbus module? Do this and then try again:

sudo apt-get install python-smbus

@DougRamsey
Copy link

Thanks electronicsguy liamkennedy and I have installed the smbus. Might just be the pi2 don't yet work with piglow. I have my project on the b+ board and all is well with it.

Do either of you have piglow working on pi2?

@liamkennedy
Copy link
Author

I can assure you the PiGlow works on the Pi2. I have it working just fine with my ISS-Above project and I have an image with my code that works just great.

Perhaps my base image I used to support the Pi2 had some other code installed that made this work more easily. I don't know what that might be.

@electronicsguy
Copy link

did you do the actual install, (the last line):
sudo python setup.py install

or did you simply download the files and try to run them? just making sure.

@DougRamsey
Copy link

Thanks you for your help electronics guy and liamkennedy.

I did the upgrade and update, apt-get psutil and smbus they installed properly
I enabled the ic2 in raspi-config
I modified /boot/config.txt with a line for dtparam-i2c_arm=on
I downloaded and ran the setup for the new pyglow module from https://github.com/gadgetoid/piglow

I still get that io error
pi@raspberrypi ~/PiGlow/Examples $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 9, in
piglow = PiGlow()
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 25, in init
self.bus = SMBus(i2c_bus)
IOError: [Errno 2] No such file or directory

this is exactly the same error that connnormilner198 reported but never got back if he got it fixed
My project is working with the pib+ and I will continue to develop on it and port it over the the pi2 for the next phase. You have given me some good places to look but if you have piglow working on the pi2 I should be able to figure it out when I get back to it and I will let you know then what I found..thanks again thanks and I will update you on this in a few weeks.

Doug

@electronicsguy
Copy link

Ok, lets debug the i2c and smbus. What do you get when you do this?:

i2cdetect -y 1
lsmod | grep -i i2c

btw, try the official pimoroni github again. It should work. make sure you've done "sudo rpi-update" before. Type here exactly what error you get with that.

@DougRamsey
Copy link

Thanks electronics guy.

I did the rpi-update successfully then redid the git hup and reran the setup successfully
other test results
pi@raspberrypi ~ $ i2cdetect -y 1
Error: Could not open file /dev/i2c-1' or/dev/i2c/1': No such file or directory
pi@raspberrypi ~ $ lsmod | grep -i i2c
i2c_bcm2708 4990 0
When i try to run test.py I get the following:
pi@raspberrypi ~/PiGlow/Examples $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 7, in
from piglow import PiGlow
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 22, in
import sn3218
ImportError: No module named sn3218
At least ther was no i/o error this time but coulnt find the sn3218 module?

@electronicsguy
Copy link

ok, check it on channel 0 as well: i2cdetect -y 0

If this also gives an error (or no output) like above, then your i2c bus has not been activated, which is the root cause of your problems.

you need these lines in the respective files:
/boot/config.txt:
dtparam=spi=on
dtparam=i2c_arm=on

/etc/modules:
i2c-dev
i2c-bcm2708

/etc/modprobe.d/raspi-blacklist.conf:
(either this file is blank, or if there are any entries related to i2c blacklist, comment them out by adding a hash symbol at the beginning of the line like this:
#blacklist i2c-bcm2708

then reboot, and check if i2cdetect works now.

@electronicsguy
Copy link

also install this library:
sudo apt-get install libi2c-dev

@DougRamsey
Copy link

Thankks aginb electronicsguy
I did all your suggestions above (the only thing that had not been done before was the dtparam spi=on and the update to the libic2-dev (that black list file was empty on mi pi) I then rebooted and and still got the following
pi@raspberrypi ~/PiGlow/Examples $ sudo python test.py
Traceback (most recent call last):
File "test.py", line 7, in
from piglow import PiGlow
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 22, in
import sn3218
ImportError: No module named sn3218
where is this sn318 modue?
The ic2 test failed alo per below:
2cdetect -y 0
Error: Could not open file /dev/i2c-0' or/dev/i2c/0': No such file or directory

Doug

@electronicsguy
Copy link

Looks like you have 2 problems: sn3218 and i2c. lets take the first one. the sn3218 is the chip on the piglow. the module should have been installed. but if not try this:

sudo apt-get install python-pip
sudo pip install sn3218

then reboot and run the example and see if it atleast eliminates the first error. But as its pointed out here: http://forums.pimoroni.com/t/display-o-tron-3000/29/23

the error should not be there if your i2c module hasn't been activated. So lets look at the i2c again. please print out the i2c relevant contents of the 3 files I had mentioned in the previous post.

also do this: sudo modprobe i2c-dev, then reboot

Unless you get i2cdetect working as pointed above, the piglow is not going to work. Someone in the URL I referenced above had similar errors to yours, and it seems he got a new raspbian image and did the standard steps and it worked for him. I cannot pinpoint your problem but from what I understand, the kernel is refusing the load the i2c module. If you have the patience, take a new SD card, flash a fresh raspbian install and do the standard steps outlined in the pimoroni github, after doing apt-get update/upgrade, rpi-update, and raspi-config to enable i2c and see if it works.

oh, btw, what's your default python version? I don't think the piglow works with version 3+. you have to use 2.xx. do a 'python --version' and check. Mine is 2.7.3

@DougRamsey
Copy link

Thanks electronics guy for hanging in there with me on this.
The icw detect on chanel 1 worked when I went with sudo and the install you suggested seem to get me pretty much working.
I my project I use the pulsing function in the benleb branch the creates PyGlow. My test program now works fine so I am good for now.

Programs in the regular PiGlow director produce many errors that I wont concern my self with for now.
glowpi@raspberrypi ~/PiGlow/Examples $ sudo python test.py
White: 255
Traceback (most recent call last):
File "test.py", line 12, in
piglow.white(val)
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 42, in white
self.update()
AttributeError: PiGlow instance has no attribute 'update'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(_targs, *_kargs)
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 33, in off
self.all(0)
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 76, in all
self.update()
AttributeError: PiGlow instance has no attribute 'update'
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(_targs, *_kargs)
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 33, in off
self.all(0)
File "/usr/local/lib/python2.7/dist-packages/piglow.py", line 76, in all
self.update()
AttributeError: PiGlow instance has no attribute 'update'
if you are interested here is an attempt to run out of Pi

Thanks for all your help
Doug

@electronicsguy
Copy link

glad I could help!
image

@RobSeder
Copy link

I have several Pi 2's with PiGlow's and I too, can't get it working. Here is what I did:

  • Started from a fresh image of the newer Raspian build
  • Ran raspi-config and enabled i2c
  • Modified /boot/config.txt and added: dtparam=i2c_arm=on, dtparam=i2c=on1=on, and dtparam=spi=on
  • Modified /etc/modules and added i2c-bcm2708, and i2c-dev
  • Verified I do NOT have a /etc/modprobe.d/raspi-blacklist.conf
  • Verified with "python --version" I am defaulted to 2.7.3
  • Ran "sudo modprobe i2c-dev", "apt-get upgrade", "apt-get update", "apt-get install python-pip", "pip install sn3218", "apt-get install python-smbus", etc...

if I do "ls /dev/i*", I just see "mice" and nothing else. When I run "i2cdetect -y 0" or "i2cdetect -y 1", I get "Error: Could not open file /dev/i2c-0' or/dev/i2c/0': No such file or directory"

If I run any of the samples from anyone's site, I pretty consistently get "IOError: [Errno 2] No such file or directory" or "ImportError: No module named piglow"

After scouring the web, I believe that's all of the advice everyone has given, at one point or another. Yet, I can't get this to work. Anyone have anything else for me to try?

@electronicsguy
Copy link

hmm tricky. one thing I want to checkL: you did do a reset after changes to the config files right?

Are you able to do any GPIO? This can be checked by connecting a LED and a 10K resistor to any GPIO pin and some simple led flash code you find. If not there may be a problem with the python gpio lib.

You said you installed python-smbus. did you get any errors? ALso, did you install libi2c-dev? that's required.

@RobSeder
Copy link

@electronicsguy yes, libi2c-dev installed. Yes, reboots done after every major step and plenty in-between. Yes, GPIO works (plus I'm doing this in parallel on 4 pi's with 4 piglows and the behavior is on all 4 - so, it's not bad Pi or PiGlow hardware).

With python-smbus, I uninstalled and re-installed and I think it's fine:
Unpacking python-smbus (from .../python-smbus_3.1.0-2_armhf.deb) ...
Setting up python-smbus (3.1.0-2) ...

@DougRamsey
Copy link

I did all these things also and the only way it works for me is to simply run
sudo modprobe i2c-dev

before running my python program which at some point electronics guy recommended and after that it works fine. No reboot or anything is required. Not sure why this was required but I will wait keep monitoring for the ultimate solution.

@RobSeder
Copy link

@DougRamsey I run that, and there is no output - the prompt comes back. Should I see something!

Running python after that I get the same result.

@DougRamsey
Copy link

My experience is before it run sudo modprobe i2c-dev from the raspberrypi directory, my piglow program does not work and returns the io error. After running sudo modprobe i2c-dev it returns to the raspberrypi directory and prompt and then I navigate to my program and voilla.....it works

@RobSeder
Copy link

@DougRamsey thanks, here's what I get:

pi@pi01 ~ $ sudo modprobe i2c-dev 
pi@pi01 ~ $ sudo python piglow-example.py 
Traceback (most recent call last):
  File "piglow-example.py", line 54, in <module>
    piglow = PiGlow(1)
  File "piglow-example.py", line 21, in __init__
    self.bus = SMBus(i2c_bus)
IOError: [Errno 2] No such file or directory
pi@pi01 ~ $ 

@DougRamsey
Copy link

In order to get the ic2 detection I had to run it with sudo i2cdetect - y - 0

When I run "i2cdetect -y 0" or "i2cdetect -y 1", I get "Error: Could not open file /dev/i2c-0' or/dev/i2c/0': No such file or directory"

@RobSeder
Copy link

I get:

pi@pi01 ~ $ sudo i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory
pi@pi01 ~ $ sudo i2cdetect -y 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
pi@pi01 ~ $ sudo i2cdetect - y - 0
Error: Unsupported option "-"!
Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]
       i2cdetect -F I2CBUS
       i2cdetect -l
  I2CBUS is an integer or an I2C bus name
  If provided, FIRST and LAST limit the probing range.
pi@pi01 ~ $ 

@DougRamsey
Copy link

I get the same for bus 0 but when I try bus 1 I get detection:

pi@raspberrypi ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Sorry I am not able to help

@RobSeder
Copy link

No problem, I appreciate you trying!!

@electronicsguy
Copy link

Rob, there's nothing wrong with the instructions per se, they've been tested with many people. There's definitely something wrong with enabling the i2c bus in your setup, even though you seem to have done everything right. Maybe there's some hidden system conflict that we cannot see.
did you install a lot of programs before trying this out? If so, maybe one of them is conflicting. Its difficult to say what, sitting here, but keep working on enabling the i2c bus. maybe the linux experts over at experts exchange will be more knowledgeable.

@RobSeder
Copy link

@electronicsguy Ugg. I want to get this going, so I figured I'd start from scratch. I have a Pi 2. Here's what I did:

  • Burn the SD card with a fresh image of Raspian Wheezy: 2015-01-31-raspian.img
  • sudo raspi-config (enable i2c)
  • reboot
  • sudo apt-get install python-smbus
  • sudo modprobe i2c-dev (app fails with IOError No such file, without running this)
  • sudo python piglow-example.py (and this works)

Before, I did the same thing but I did have "RabbitMQ" installed and configured. So, there may have been some problem with that.

Now that I have this working, I'll try to re-install RabbitMQ and see if/when it breaks...

OH - one more thing, the examples that use from piglow import PiGlow I get ImportError: No module named piglow even after sudo apt-get install python-psutil

@electronicsguy
Copy link

cool. Install the "libi2c-dev" module too, in case you haven't. that may make the i2cdetect work for you.

Well you have to install the "piglow" python module to use it. Did you only download the relevant python project? You either have to put the relevant modules in the python packages directory (/usr/lib/python2.7/dist-packages/) or add the path to your pythonpath environment variable. Its explained here: https://github.com/benleb/PyGlow. Actually you could also put them in the local python directory (/usr/local/lib/python2.7/dist-packages). My local python packages directory looks like this:
PiGlow-0.4.egg-info piglow.pyc PyGlow.py
CherryPy-3.6.0.egg-info piglow.py PyGlow-0.2.egg-info PyGlow.pyc

I used the python "pip" utility to install the piglow package so I didn't have to copy these manually. You can google for python "pip".

@RobSeder
Copy link

That already worked; here's what I get now:

pi@pi01 ~ $ sudo i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory
pi@pi01 ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@pi01 ~ $ 

@RobSeder
Copy link

I did install pip (I didn't know what that was before):

sudo apt-get install python-pip
sudo pip install sn3218

and I still get that "No module named piglow". So, I assume it's a path issue now? I don't know much about Python. Any ideas?

@RobSeder
Copy link

I did everything from https://github.com/benleb/PyGlow and I just can't get this to work. I continue to get "ImportError: No module named PiGlow" (and then verified with PyGlow, as there are samples with both spellings! Even though that module does seem nice, I've spent a couple hours on this and at this point it's not worth it to pursue anymore.

OK, hopefully this saves some future, poor soul! Here's what I did to get the PiGlow working on a Raspberry Pi 2:

  • Burn the SD card with a fresh image of Raspian Wheezy: 2015-01-31-raspian.img
  • sudo raspi-config (enable i2c)
  • Reboot
  • sudo apt-get install python-smbus
  • sudo modprobe i2c-dev (app fails with IOError No such file, without running this)
  • sudo python piglow-example.py (and this works)
  • Reboot
  • All non-PyGlow/PiGlow samples now work.

FYI

@DougRamsey
Copy link

Hey Rob, I had to move my programs from the examples directory up into the PyGlow directory and then run them from there to get them to work. I like that ben leeb pulsing functionality.

@RobSeder
Copy link

@DougRamsey I did, stubbornly, play with this for longer. I ended up pulling down the latest "PiGlow" library too (see: http://forums.pimoroni.com/t/raspberry-pi-2-what-works-and-what-doesnt/352/14) - that seems the closest to working, but I get several AttributeError: PiGlow instance has no attribute 'update'. I ran the examples from the /Examples/ directory (and got that same error).

The bottom line is that PiGlow/PyGlow module simply isn't ready for primetime. I've probably got 6+ hours into fiddling with this using every combination of every approach I can find. I'm dead in the water with that "PyGlow/PiGlow" approach - it simply doesn't work or requires significant development on the consumer's part. Which, i my opinion, is not acceptable. So, I'm done with that approach!

@liamkennedy
Copy link
Author

I know this is hard for you to accept.. But you are doing something wrong. I've got this working in hundreds of my shipped devices (issabove) using the piglow (but using the modified version of the code I pointed to at the beginning of this thread). I've had none of the issues you have been experiencing.

The piglow is a pretty standard little add on for the raspberry Pi. Have you thought about contacting pimoroni direct?

On Apr 11, 2015, at 7:22 AM, Rob Seder [email protected] wrote:

@DougRamsey I did, stubbornly, play with this for longer. I ended up pulling down the latest "PiGlow" library too (see: http://forums.pimoroni.com/t/raspberry-pi-2-what-works-and-what-doesnt/352/14) - that seems the closest to working, but I get several AttributeError: PiGlow instance has no attribute 'update'. I ran the examples from the /Examples/ directory (and got that same error).

The bottom line is that PiGlow/PyGlow module simply isn't ready for primetime. I've probably got 6+ hours into fiddling with this using every combination of every approach I can find. I'm dead in the water with that "PyGlow/PiGlow" approach - it simply doesn't work or requires significant development on the consumer's part. Which, i my opinion, is not acceptable. So, I'm done with that approach!


Reply to this email directly or view it on GitHub.

@RobSeder
Copy link

@liamkennedy haha! That's not difficult for me to accept at all! Just please send me the link of what I should be doing and I'll be on my way!

As for support, everyone seems to point to GitHub to give details since this apperently is the module that isn't working, not a problem with the hardware. I have 4 Pi2's and 4 PiGlows an the behavior is the same on all.

So please, correct me! Give me a list of things to do to make it work! There are countless examples on the web and I get errors with lots of them!

To be clear, what does NOT work now is the PyGlow or PiGlow modules, the raw examples DO work.

@liamkennedy
Copy link
Author

Sorry but I'm just not willing to spend more time on this thread. I think everything you need to know is here already. And above I point to a different github repository for an updated piglow module that I'm using. Do reach out to pimoroni though.

Good luck.

Sent from my iPad

On Apr 11, 2015, at 7:50 AM, Rob Seder [email protected] wrote:

@liamkennedy haha! That's not difficult for me to accept at all! Just please send me the link of what I should be doing and I'll be on my way!

As for support, everyone seems to point to GitHub to give details since this apperently is the module that isn't working, not a problem with the hardware. I have 4 Pi2's and 4 PiGlows an the behavior is the same on all.

So please, correct me! Give me a list of things to do to make it work! There are countless examples on the web and I get errors with lots of them!

To be clear, what does NOT work now is the PyGlow or PiGlow modules, the raw examples DO work.


Reply to this email directly or view it on GitHub.

@electronicsguy
Copy link

wrt: PyGlow or PiGlow:

what does your local python packages directory look like: post the output of 'ls' here.

@RobSeder
Copy link

@electronicsguy I don't know where that packages folder is - what is the path?

Meanwhile, I did accidentally get "PyGlow" module working - but I have no idea how. I am planning to re-format the SD and try again to see if I can trace the steps to get it working. Out of principle at this point, I'll likely do a blog post with all of the gory details, and I'll post back here once I've untangled the big mess!! I know now, it's possible to get Pi2 + PiGlow working, but as far as what needs to be installed or configured in what order, that is the big mystery I hope to unravel.

Thanks for your help.

@RobSeder
Copy link

Just FYI, I never could get the "PiGlow" module working, but I DID get the "PyGlow" module working.

I wrote down detailed step-by-step instructions on how to get that working, here: Getting a PiGlow to work with a Raspberry Pi 2 which covers most all of the concepts and techniques discussed in this thread.

Thanks, all for your help in trying to troubleshoot and I hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants