Read analog input on BeagleBone, prevent "segmentation fault" error

I am new to Beaglebone and follow a pretty good click until this strange problem pops up. I spent the whole weekend trying to figure this out before posting here.

I am trying to read the analog input using several sensors from beaglebone with Angstrom 3.2.5+, and I have a problem that I think may be a hardware problem.

Using this Python script and Alexander Hiam PyBBIO I successfully tested a photoresistor (the value responds to more and less random light):

# Import PyBBIO library:
from bbio import *

# Create a setup function:
def setup(): pass # Nothing to do here

# Create a main function:
def loop():

  print "-----"

  print "AIN0 [P9.39] - " + str(analogRead(A0))
  print "AIN1 [P9.40] - " + str(analogRead(A1))
  print "AIN2 [P9.37] - " + str(analogRead(A2))
  print "AIN3 [P9.38] - " + str(analogRead(A3))
  print "AIN4 [P9.35] - " + str(analogRead(A4))
  print "AIN5 [P9.36] - " + str(analogRead(A5))
  print "AIN6 [P9.33] - " + str(analogRead(A6))
  print "AIN7 [P9.39] - " + str(analogRead(A7))

  delay(500)

# Start the loop:
run(setup, loop)

But any other analog (AINx (2-7)) that I read using the script above always shows the same value of the photoresistor that I connected to AIN1

, , , - AINx (1-7), cat

cat /sys/bus/platform/devices/tsc/ain1
Segmentation fault

? . .

PS: ...

10k . :

  • P9 Pin 32 (VDD_ADC (1.8V))
  • P9 Pin 34 (GNDA_ADC)
  • P9 Pin 39 (AIN0)

, : enter image description here

AINx (1-7), ...

# cat /sys/bus/platform/devices/tsc/ain0 
cat: /sys/bus/platform/devices/tsc/ain0: No such file or directory 
# cat /sys/bus/platform/devices/tsc/ain1 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain2 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain3 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain4 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain5 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain6 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain7 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain8 
Segmentation fault 
# cat /sys/bus/platform/devices/tsc/ain9 
cat: /sys/bus/platform/devices/tsc/ain9: No such file or directory

1

analog_test_simple.py, ADC BeagleBone. .

-----
AIN0 [P9.39] - 3948
AIN1 [P9.40] - 4016
AIN2 [P9.37] - 4002
AIN3 [P9.38] - 3934
AIN4 [P9.35] - 4001
AIN5 [P9.36] - 3935
AIN6 [P9.33] - 3968
AIN7 [P9.39] - 4005
-----
AIN0 [P9.39] - 3946
AIN1 [P9.40] - 4005
AIN2 [P9.37] - 3945
AIN3 [P9.38] - 3957
AIN4 [P9.35] - 4018
AIN5 [P9.36] - 3945
AIN6 [P9.33] - 3967
AIN7 [P9.39] - 3955
...

, , , :

-----
AIN0 [P9.39] - 2836
AIN1 [P9.40] - 2836
AIN2 [P9.37] - 2837
AIN3 [P9.38] - 2831
AIN4 [P9.35] - 2840
AIN5 [P9.36] - 2837
AIN6 [P9.33] - 2837
AIN7 [P9.39] - 2837
-----
AIN0 [P9.39] - 2834
AIN1 [P9.40] - 2834
AIN2 [P9.37] - 2829
AIN3 [P9.38] - 2825
AIN4 [P9.35] - 2826
AIN5 [P9.36] - 2817
AIN6 [P9.33] - 2815
AIN7 [P9.39] - 2815
...
+3
2

, , , PyBBIO. ...

1: /

PyBBIO- script. :

# python PyBBIO/examples/analog_test_simple.py
-----
AIN0 [P9.39] - 3955
AIN1 [P9.40] - 4015
AIN2 [P9.37] - 4012
AIN3 [P9.38] - 3950
AIN4 [P9.33] - 3998
AIN5 [P9.36] - 4007
AIN6 [P9.35] - 3984
-----
AIN0 [P9.39] - 4007
AIN1 [P9.40] - 3953
AIN2 [P9.37] - 4005
AIN3 [P9.38] - 3941
AIN4 [P9.33] - 3956
AIN5 [P9.36] - 3934
AIN6 [P9.35] - 3946
...

, :

# python PyBBIO/examples/analog_test_simple.py
-----
AIN0 [P9.39] - 2888
AIN1 [P9.40] - 2894
AIN2 [P9.37] - 2899
AIN3 [P9.38] - 2907
AIN4 [P9.33] - 2914
AIN5 [P9.36] - 2912
AIN6 [P9.35] - 2914
-----
AIN0 [P9.39] - 2912
AIN1 [P9.40] - 2905
AIN2 [P9.37] - 2901
AIN3 [P9.38] - 2891
AIN4 [P9.33] - 2896
AIN5 [P9.36] - 2890
AIN6 [P9.35] - 2896
...

, .

, script PyBBIO. Python BeagleBone Python os. os.system('cat ...') . :

import os,time
i = 1

while(True):
    os.system("cat /sys/bus/platform/devices/tsc/ain" + str(i))
    print " - AIN" + str(i-1)
    if i==7: 
        i=1
        time.sleep(.5)
        print "------"
    else:
        i+=1    
    time.sleep(.1)

- , BeagleBone:

# python analog-test-all-pins.py
------
3943 - AIN0
3819 - AIN1
3955 - AIN2
2018 - AIN3
2093 - AIN4
3583 - AIN5
3658 - AIN6
------
3947 - AIN0
3746 - AIN1
3959 - AIN2
2034 - AIN3
2123 - AIN4
3547 - AIN5
3644 - AIN6
...

AIN0:

# python analog-test-all-pins.py
------
2915 - AIN0
3347 - AIN1
3556 - AIN2
1478 - AIN3
1602 - AIN4
2393 - AIN5
2402 - AIN6
------
2913 - AIN0
3337 - AIN1
3560 - AIN2
1487 - AIN3
1606 - AIN4
2350 - AIN5
2489 - AIN6

AIN2:

# python analog-test-all-pins.py
------
3939 - AIN0
3792 - AIN1
2881 - AIN2
1986 - AIN3
2089 - AIN4
3462 - AIN5
3543 - AIN6
------
3923 - AIN0
3791 - AIN1
2866 - AIN2
1960 - AIN3
2055 - AIN4
3528 - AIN5
3615 - AIN6
...

AIN3:

# python analog-test-all-pins.py
------
3951 - AIN0
3764 - AIN1
3933 - AIN2
2899 - AIN3
2134 - AIN4
3606 - AIN5
3737 - AIN6
------
3960 - AIN0
3823 - AIN1
3957 - AIN2
2910 - AIN3
2118 - AIN4
3635 - AIN5
3645 - AIN6
...

photoresistor and TMP36 sensor

, AIN0 mrBBIO , :

from mrbbio import *

def setup():
    #pinMode("P9.36", INPUT)
    pass

def loop():

    print "-----"

    for key, value in analogPinDef.items():
        # There is currently an error in mrBBIO, as the analogPinDef dict points to:
        # ain[0-6] in /sys/devices/platform/tsc/ while it should point at: ain[1-7]
        if key=="P9.39": 
            print analogRead(key) + " - " + value
            delay(100)

    delay(1000)

run (setup,loop)

:

# python mrbbio/analog-test-all-pins.py
-----
2005 - ain4
3636 - ain6
3812 - ain2
2114 - ain5
3872 - ain3
3950 - ain1
-----
2002 - ain4
3530 - ain6
3787 - ain2
2059 - ain5
3895 - ain3
3952 - ain1
...
Cleaning up. Unexporting the following pins:

, cat - , , .

# cat /sys/bus/platform/devices/tsc/ain1
3960
# cat /sys/bus/platform/devices/tsc/ain2
3830
+5

AIN0 AGND 1 . (2 ). , , , . 1 .

0

All Articles