I14R10
Posts: 31
Joined: Tue Dec 15, 2015 1:02 am

Program only works from root

Tue Dec 15, 2015 1:09 am

Hi. Raspberry newbie here.
I just bought Raspberry PI B, installed Raspbian, and I wrote a program which uses I2C to get data from AVR microcontroller. But, the problem is that program only works from root directory. If I move it to /var/www and try to compile and run it from here, I2C stops working - I get read or write error. What could be the problem? It's definitely not error in programming, since it works every time from root directory and never works from /var/www directory. I choose that directory so my files could be accessible from the internet. I'm running apache server on it.

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

Re: Program only works from root

Tue Dec 15, 2015 8:40 am

You need to Google Linux permissions and gain an understanding of how Linux grants access to files and devices.

At its simplest you need to add the Apache user (www-data?) to the i2c group. Members of the i2c group may access the I2C devices.

I14R10
Posts: 31
Joined: Tue Dec 15, 2015 1:02 am

Re: Program only works from root

Tue Dec 15, 2015 5:05 pm

Thank you, I managed to make it work!

Return to “Troubleshooting”