PiGlow icon indicating copy to clipboard operation
PiGlow copied to clipboard

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

Open liamkennedy opened this issue 10 years ago • 50 comments

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

liamkennedy avatar Feb 11 '15 06:02 liamkennedy

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

ghost avatar Feb 11 '15 15:02 ghost

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

liamkennedy avatar Feb 11 '15 20:02 liamkennedy

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.

Boeeerb avatar Feb 11 '15 20:02 Boeeerb

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

ghost avatar Feb 12 '15 20:02 ghost

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

liamkennedy avatar Feb 13 '15 00:02 liamkennedy

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

ghost avatar Feb 13 '15 10:02 ghost

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.

liamkennedy avatar Feb 13 '15 10:02 liamkennedy

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?

DougRamsey avatar Feb 27 '15 19:02 DougRamsey

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.

electronicsguy avatar Mar 24 '15 23:03 electronicsguy

@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?

liamkennedy avatar Mar 24 '15 23:03 liamkennedy

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.

DougRamsey avatar Mar 26 '15 13:03 DougRamsey

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

liamkennedy avatar Mar 26 '15 15:03 liamkennedy

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

sudo apt-get install python-smbus

electronicsguy avatar Mar 26 '15 21:03 electronicsguy

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?

DougRamsey avatar Mar 26 '15 22:03 DougRamsey

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.

liamkennedy avatar Mar 26 '15 22:03 liamkennedy

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.

electronicsguy avatar Mar 26 '15 22:03 electronicsguy

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

DougRamsey avatar Mar 27 '15 14:03 DougRamsey

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.

electronicsguy avatar Mar 27 '15 18:03 electronicsguy

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?

DougRamsey avatar Mar 27 '15 20:03 DougRamsey

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 avatar Mar 27 '15 20:03 electronicsguy

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

electronicsguy avatar Mar 27 '15 20:03 electronicsguy

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

DougRamsey avatar Mar 27 '15 23:03 DougRamsey

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

electronicsguy avatar Mar 27 '15 23:03 electronicsguy

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

DougRamsey avatar Mar 28 '15 01:03 DougRamsey

glad I could help! image

electronicsguy avatar Mar 28 '15 02:03 electronicsguy

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?

RobSeder avatar Apr 10 '15 04:04 RobSeder

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.

electronicsguy avatar Apr 10 '15 05:04 electronicsguy

@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) ...

RobSeder avatar Apr 10 '15 06:04 RobSeder

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.

DougRamsey avatar Apr 10 '15 16:04 DougRamsey

@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.

RobSeder avatar Apr 10 '15 16:04 RobSeder