BeagleBone Black

For BeagleBone Black, there is a Python library from Adafruit that is similar to the one we saw with Tinkerboard's library.

In Ubuntu, you can install the library using pip by following these steps:

  1. Update and install dependencies:
$ sudo apt-get update
$ sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
  1. Install the library using the pip command:
$ sudo pip install Adafruit_BBIO

In Debian, you can clone the repository and install it manually by following these steps:

  1. Update and install the dependencies:
$ sudo apt-get update
$ sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
  1. Clone the workspace and install the library manually:
$ git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
$ cd adafruit-beaglebone-io-python
$ sudo python setup.py install

Now that the Python library is installed, let's see how to control an LED blink from a ROS topic. You can find the whole code here: https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_7_ws/beagleboneblack_gpio.py. Check out the important details of the code:

...

import Adafruit_BBIO.GPIO as GPIO

LED = "P8_10"
GPIO.setup(LED,GPIO.OUT)

def ledBlink(data):
if data.data = true:
GPIO.output(LED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(LED, GPIO.LOW)
time.sleep(0.5)
else:
GPIO.cleanup()

...

In the preceding code, we make use of the Adafruit_BBIO.GPIO library we installed. After the necessary import statements, we define the GPIO that we would use as OUT, meaning output (as it is LED in our case; it would be IN if it was a switch). Then, we have the function to make the LED blink in case the /led_status topic receives a Boolean that's true or false.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset