Can one read the ADC as a non-root user?

I want to read the ADC inputs on my Beaglebone Black without root
privilege. Using the Adafruit_BBIO.ADC package in Python requires
root privilege, are there any ways of doing it without?

Check out libpruio (ie. pre-compiled examples io_input or oszi). Currently it supports FreeBASIC and C programming language, somebody made a Java binding.

I want to read the ADC inputs on my Beaglebone Black without root
privilege. Using the Adafruit_BBIO.ADC package in Python requires
root privilege, are there any ways of doing it without?

Use group permissions. If you are part of a group and ADC is part of the
same group, you can access ADC without being root.

Regards,
John

Do you have a pointer to the Java binding? Google could not find it.

David

Er, ADC can't really be "part of a group" as it's not a user.

If there *is* a group whose membership allows access to the ADC inputs
then I'd like to know what it is. I've looked through /etc/group and
there's nothing obviously associated with IO.

ssl reports in the following thread that he did the job

http://www.freebasic.net/forum/viewtopic.php?f=14&t=22501&start=30#p198874

But it seems that he didn’t upload it. I sent him an Email with a link to this thread, asking if he can help you.

>I want to read the ADC inputs on my Beaglebone Black without root
>privilege. Using the Adafruit_BBIO.ADC package in Python requires
>root privilege, are there any ways of doing it without?
Use group permissions. If you are part of a group and ADC is part of the
same group, you can access ADC without being root.

Er, ADC can't really be "part of a group" as it's not a user.

In Unix, everything is a file so you can assign groups to almost anything.

If there *is* a group whose membership allows access to the ADC inputs
then I'd like to know what it is. I've looked through /etc/group and
there's nothing obviously associated with IO.

These are standard Unix/Linux concepts. I don¹t know how you are accessing
the ADC device (device, IIO, sys, etc), but the same principles apply. If
you are accessing a device for example (/dev/adc?) then you assign a group
to that device either in an init script or udev. If your userid is part of
the same group, then you don¹t need root permission to access that device.
Reading a good Linux book will explain this concept.

Regards,
John

Well, by having a quick look at the Adafruit_BBIO.ADC package you mentioned we can see that it is indeed reading the value from a file.

https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/c_adc.c#L46

We can see there that there are some AIN files located in the /sys/devices/ directory. The following command will tell you more about them:

find /sys/devices/ -name '*AIN*'

You should see something like

/sys/devices/ocp.2/helper.14/AIN0

/sys/devices/ocp.2/helper.14/AIN1

/sys/devices/ocp.2/helper.14/AIN2

/sys/devices/ocp.2/helper.14/AIN3

/sys/devices/ocp.2/helper.14/AIN4

/sys/devices/ocp.2/helper.14/AIN5

/sys/devices/ocp.2/helper.14/AIN6

/sys/devices/ocp.2/helper.14/AIN7

What you can do next is doing something like

ls -alh /sys/devices/ocp.2/helper.14/AIN0

which will tell you more about the access rights to that file. Once you have this kind if knowledge it should be pretty straightforward to set the rights in such a way that a non-root user should be able to read from ADC.

Hope this helps.

I've been using and programming on Unix/Linux systems since the early
1980s thank you.

The group associated with the /sys/devices/.... files associated with
the ADC is 'root' and, anyway, the group only has read permission so
even if I added my user to that group I wouldn't be able to configure
the ADC subsystem. To set up the ADC one needs to write, similarly to
access the GPIO one needs write.

It would appear (if you do a few google searches for Beaglebone Black
non-root access to IO) that the existing situation is that it's very
difficult indeed to make IO on the BBB work for non-root users and
quite a few people think this should be fixed.

The group associated with the /sys/devices/… files associated with
the ADC is ‘root’ and, anyway, the group only has read permission so
even if I added my user to that group I wouldn’t be able to configure
the ADC subsystem.

root user can change associated group and privileges (ie. on start-up).

To set up the ADC one needs to write, similarly to
access the GPIO one needs write.

Your subject is about ‘… read the ADC as a non-root user’.

It would appear (if you do a few google searches for Beaglebone Black
non-root access to IO) that the existing situation is that it’s very
difficult indeed to make IO on the BBB work for non-root users and
quite a few people think this should be fixed.

I agree. That’s why I wrote libpruio. And I’m improving and extending it.

It would appear (if you do a few google searches for Beaglebone Black
non-root access to IO) that the existing situation is that it’s very
difficult indeed to make IO on the BBB work for non-root users and
quite a few people think this should be fixed.

Reading of a value may not be a big deal, but giving write( ability to change the setup ) access of such a device to a regular user is a very bad idea. Or would you allow a regular user have such access to say, /dev/mem too ?

If there ever was a perfect use for setuid / setgid, and / or IPC, I’d think this would be it. However if these “many people” who find such things diffficult should spend more time reading about the OS they’re trying to use.

I don't know why people keep writing emails saying "I use Linux since forever" when they are wrong and trying to get info. The guy that previously answered the question is just trying to help... why so serious?

Anyway, for gpio without root I use the idea found in this git project:
https://github.com/quick2wire/quick2wire-gpio-admin

Although it's written for Rpi, it works for BBB. It creates a gpio group and uses it when exports a pin. It is NOT what you want, but you may find guidelines in the Makefile and the gpio-admin.c file to achieve what you are looking for ADC.

Best,
Miguel

No use at all. I want access for a user that doesn't need root access
before to set it up.

If I do as you suggest and open up the permissions on the /sys/devices...
files it will work until the next reboot and then I have to do it all
over again - once again using root access to do it. OK, I *could* do
it in /etc/rc.local but it's fundamentally wrong on a Unix/Linux
system to have to do this to allow a user to access things which are
really (in the case of the BBB in particular) the thing that it's
designed to do.

There should either be mapping of the ADC, IO etc. to user space or
there should be setuid processes/drivers that allow a user to get to
this information (and output to GPIO).

I believe others are actually working on this as there seems to be
quite a lot of 'noise' about it if you Google the subject. Thus I
will be patient and see if future software releases sort it out.