I2C problem with remote Raspberry pi


480
views
1
5 months ago by

I am running WingIDE6.0 remotely connected to a Raspberry Pi. I can run a normal program no problem so I know it works.

I have a program that imports smbus for I2C access. The program runs fine from the RPi console but,when I run it using Wing IDE I get an error which is: IOError: [Errno 13] Permission denied.

Now, I can see that is it a permissions issue - but why? I have added the user to the i2c group but that didn't change things.

The Wing IDE connection is SSH with keys (is no password) and it is the same user as the RPi login so there should not be a problem with permissions.

The actual instruction that fails is: self._bus = smbus.SMBus(twi)

If this is a restriction for some reason then I'm stuck as I do a lot of native I/O on the RPi.



 

 

add commentfollow this post modified 5 months ago by dgoadby   • written 5 months ago by dgoadby  

3 Answers


3
5 months ago by

Ok, now were are sorted! And permissions is the problem.

A quick fix is to change the permissions of /dev/i2c-1  or /dev/i2c-0  (depends on rpi model) with the command:
sudo chmod a+rw /dev/i2c-*

This is temporary and is lost at next boot so, to fix it permanently you need to do the following:

  1. Edit the file /etc/udev/rules.d/99-com.rules
  2. If this line exists: SUBSYSTEM=="ic2-dev", GROUP="i2c", MODE="0660" then change the MODE to "0666".
  3. If it does not exist then add it with the MODE="0666" and also note the "==".
  4. Reboot.

NOTE: My system is RPi3. For other variants the file in /etc/udev/rules.d may have a different name so check them all to find the one with the entry you need to change.  Also, the entry may say KERNEL instead of SUBSYSTEM depending on you Debian version. The important thing to find is the line with "i2c-dev" in it.

After making the above changes you can use WingIDE on RPi with i2c devices actually working natively. For debugging it's worth every penny.


Following on from my experiences with i2c, the situation is much the same for GPIO, and the fix much the same.

The "quick fix" is: sudo chmod a+rw /dev/gpiomem

For the permanent fix the entry will be something like SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660".  As before change the MODE to "0666".

That's it, i2c and GPIO working with WingIDE.

If you happen to need the spi bus then, assuming you have enabled it using sudo raspi-config, you will need to make the same changes to the entry with "spidev" in it.

David

add comment written 5 months ago by dgoadby  

Thanks for posting this!  You may want to select this answer as the accepted answer for this question.

written 5 months ago by Wingware Support  
0
5 months ago by

My guess is when you're logged into the Raspberry Pi you are running the code with sudo and this is not being done by Wing's remote agent.  Probably the solution is setting access permissions so the user can access it without sudo.  The selected answer for http://stackoverflow.com/questions/34533913/python-rasberry-pi-piano-hat-permission-denied and the document it links to may be what you need.

add comment written 5 months ago by Wingware Support  
0
5 months ago by

Actually I'm not running as sudo. Earlier i2c implementations did require sudo or equivalent but I'm just running the program using: python test-prog.py as per normal.

It's 3am in the UK so I'm off top bed now but, when I return to the problem later today I will just check the permissions. 

The article you referenced is dated 12/2015 and that referred to a 2012 article so it is probably before the later smbus implementation but I will check and report back.

Thanks for a speedy reply BTW.

David

add comment written 5 months ago by dgoadby  
Please log in to add an answer/comment or follow this question.

Similar posts:
Search »