Python GPIO Error

Greetings. I ssh into my BB_B and I have followed this guide and everything works fine. However when I try typing this code to test my installation it doesn’t work:

  1. python -c "import Adafruit_BBIO.GPIO as GPIO; print GPIO"

I get an error:

`
root@beaglebone:~/adafruit-beaglebone-io-python# python blink.py Traceback (most recent call last): File “blink.py”, line 1, in import Adafruit_BBIO.GPIO as GPIO ImportError: No module named GPIO


root@beaglebone:~/adafruit-beaglebone-io-python# python -c “import Adafruit_BBIO.GPIO as GPIO; print GPIO”
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named GPIO
root@beaglebone:~/adafruit-beaglebone-io-python#
`

I tried to move along in the guide and typed this code into a new python file called blink.py:

`
import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup(“P8_10”, GPIO.OUT)

while True:
GPIO.output(“P8_10”, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(“P8_10”, GPIO.LOW)
time.sleep(0.5)

`

When I try to run blink.py I get a similar error to the one above:

root@beaglebone:~/adafruit-beaglebone-io-python# python blink.py Traceback (most recent call last): File “blink.py”, line 1, in import Adafruit_BBIO.GPIO as GPIO ImportError: No module named GPIO

So I know something is up with my GPIO ports but I just do not know what. Please help me.
Thanks for reading

See if Adafruit_BBIO installs correctly by running following commands separately:

opkg update

opkg install python-pip python-setuptools python-smbus

pip install Adafruit_BBIO

Changing the current directory should help.

Python is loading Adafruit_BBIO from the current (source) directory, which only contains the init.py file. By changing the current directory, it will load it from the correct (installed) area, which contains the other pieces (such as GPIO.so)

I am using Beaglebone Black to run ultrasonic sensor. I am using the following code.

#!/usr/bin/env python

import BBIO.GPIO as GPIO # Import GPIO library
import time # Import time library
GPIO.setmode(GPIO.BCM) # Set GPIO pin numbering

TRIG = 23 # Associate pin 23 to TRIG
ECHO = 24 # Associate pin 24 to ECHO

print “Distance measurement in progress”

GPIO.setup(TRIG, GPIO.OUT) # Set pin as GPIO out
GPIO.setup(ECHO, GPIO.IN) # Set pin as GPIO in

while True:

GPIO.output(TRIG, False) # Set TRIG as LOW
print “Waitng For Sensor To Settle”
time.sleep(2) # Delay of 2 seconds

GPIO.output(TRIG, True) # Set TRIG as HIGH
time.sleep(0.00001) # Delay of 0.00001 seconds
GPIO.output(TRIG, False) # Set TRIG as LOW

while GPIO.input(ECHO) == 0: # Check whether the ECHO is LOW
pulse_start = time.time() # Saves the last known time of LOW pulse

while GPIO.input(ECHO) == 1: # Check whether the ECHO is HIGH

pulse_end = time.time() # Saves the last known time of HIGH pulse

pulse_duration = pulse_end - pulse_start # Get pulse duration to a variable

distance = pulse_duration * 17150 # Multiply pulse duration by 17150 to get distance
distance = round(distance, 2) # Round to two decimal points

if distance > 2 and distance < 400: # Check whether the distance is within range
print “Distance:”,distance - 0.5,“cm” # Print distance with 0.5 cm calibration
else:
print “Out Of Range” # display out of range

While I try to implement it using the Beaglebone Black I am getting the following error.
“Traceback (most recent call last):
File “ult.py”, line 5, in
import BBIO.GPIO as GPIO # Import GPIO library
ImportError: No module named BBIO.GPIO”

I need help.

You do not say whether you have done this and are getting the error, but have you installed the BBIO python library?

https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/overview

Cheers,

Pete.

Hi,

Can you please not include me in future messages.

Thanks,
KC

Hi I have the same problem but I don’t know how to change the directory you mentioned, would you tell me how should I do it?