adafruit-beaglebone-io-python icon indicating copy to clipboard operation
adafruit-beaglebone-io-python copied to clipboard

ADC not found on BeagleBone Enhanced

Open pdp7 opened this issue 5 years ago • 1 comments

copied from comment on closed issued https://github.com/adafruit/adafruit-beaglebone-io-python/issues/269#issuecomment-610604001 @krupal756 wrote:

This is my first time on github

I am using Beaglebone Enhanced and I too ran into the same issue as @sampathkmurthy with the ADC Error, but I was able to find the problem and also solve it too.

Finding the problem: I tried to google for the solution and found out this website (link below): https://www.teachmemicro.com/beaglebone-black-adc/ wherein he has explained for the exact location to probe for ADC raw values on Beaglebone Black on the command line, which is:

/sys/bus/iio/devices/iio:device0

When I tried to find the same on Enhanced and probed into /devices folder for iio:devices0, there were three folders iio:devices0,1 and 2. The in_voltage#_raw (# is the number) was missing, so I checked the same at other locations and found it in iio:device2. I cross checked the Adafruit_BBIO library, to find out from which location the library was probing the raw values from, on github and found out the c file (link) on line no 58 which had the probing location:

adafruit-beaglebone-io-python/source/c_adc.c

strncat(adc_prefix_dir, "/sys/bus/iio/devices/iio:device0/in_voltage", sizeof(adc_prefix_dir));

which will surely work for BBB, but may or may not work for other upgraded boards like Beaglebone Blue or Beaglebone Enhanced.

Solution: What I did is I manually downloaded the complete Adafruit_BBIO library onto the board, and changed the location of the adc folder on the line as below (this is for Enhanced, you may need to find out yours)

strncat(adc_prefix_dir, "/sys/bus/iio/devices/iio:device2/in_voltage", sizeof(adc_prefix_dir));

and then reinstalled the library. After which I restarted the system and ran the adc example from Adafruit and it worked just perfectly fine.

What I would like to suggest to @pdp7 to keep the flexibility of providing the adc folder location through the code, instead of fixed locations, as an update to the library, as most of the new boards as an additional input, if in case the manufacturer have these locations changed, we can fix it in our codes itself.

pdp7 avatar Apr 21 '20 18:04 pdp7

notes from @RobertCNelson:

debian@bbb-pwr01-ser09:~$ cat /sys/bus/iio/devices/iio\:device0/name
44e0d000.tscadc:adc.0.auto
8:43
debian@bbb-pwr01-ser09:/sys/devices/platform/ocp/44e0d000.tscadc/44e0d000.tscadc:adc.0.auto$ ls -lha
total 0
drwxrwxr-x 4 root gpio    0 Apr 20 16:41 .
drwxrwxr-x 4 root gpio    0 Apr 20 16:41 ..
lrwxrwxrwx 1 root gpio    0 Apr 20 16:41 driver -> ../../../../../bus/platform/drivers/TI-am335x-adc
-rw-rw-r-- 1 root gpio 4.0K Apr 20 16:41 driver_override
drwxrwxr-x 5 root gpio    0 Apr 20 16:41 iio:device0
-r--r--r-- 1 root gpio 4.0K Apr 20 16:41 modalias
lrwxrwxrwx 1 root gpio    0 Apr 20 16:41 of_node -> ../../../../../firmware/devicetree/base/ocp/tscadc@44e0d000/adc
drwxrwxr-x 2 root gpio    0 Apr 20 16:41 power
lrwxrwxrwx 1 root gpio    0 Apr 20 16:41 subsystem -> ../../../../../bus/platform
-rw-rw-r-- 1 root gpio 4.0K Apr 20 16:41 uevent
8:44

4.14

debian@bbb-pwr01-ser09:/sys/devices/platform/ocp/44e0d000.tscadc/44e0d000.tscadc:adc.0.auto/iio:device0$ ls
buffer  in_voltage0_raw  in_voltage2_raw  in_voltage4_raw  in_voltage6_raw  name     power          subsystem
dev     in_voltage1_raw  in_voltage3_raw  in_voltage5_raw  in_voltage7_raw  of_node  scan_elements  uevent
8:45

4.19.94-ti-r42

debian@bbb-pwr03-ser11:~$ uname -r ; ls /sys/devices/platform/ocp/44e0d000.tscadc/TI-am335x-adc.0.auto/iio\:device0/
4.19.94-ti-r42
buffer  in_voltage0_raw  in_voltage2_raw  in_voltage4_raw  in_voltage6_raw  name     power          subsystem
dev     in_voltage1_raw  in_voltage3_raw  in_voltage5_raw  in_voltage7_raw  of_node  scan_elements  uevent
8:45

5.4.20-ti-r6

debian@bbb-pwr05-ser13:~$ uname -r ; ls /sys/devices/platform/ocp/
5.4.20-ti-r6
40300000.ocmcram        47c00000.interconnect  49900000.tptc          4c000000.emif    modalias                    subsystem
44c00000.interconnect   48000000.interconnect  49a00000.tptc          53100000.sham    ocp:target-module@56000000  uevent
47400000.usb            49000000.edma          4a000000.interconnect  53500000.aes     of_node
478102fc.target-module  49800000.tptc          4b144400.interconnect  driver_override  power

pdp7 avatar Apr 21 '20 18:04 pdp7