Wednesday, 19 February 2014

BeagleBone Black and PWM servo control by Babak Parvizi

BeagleBone Black and Pulse Width Modulation (PWM), Controlling a Servo Using HTML5, JavaScript, and Node.js. written by Babak Parvizi

http://tlfong01.com/2014/02/20/beaglebone-black-servo-control/

.END

Wednesday, 29 January 2014

Using the Adafruit_BBIO LibraryCreated by Justin Cooper

Using the Adafruit_BBIO Library - Created by Justin Cooper

http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/using-the-bbio-library

This library has quite a few changes being made to it. Please read the CHANGELOG anytime you update the library to ensure it doesn't break your programs.

Using the Adafruit_BBIO library with the BeagleBone Black (BBB) is fairly simple, especially if you're familiar with the RPi.GPIO library for the Raspberry Pi.

To start, you'll want to import the libary. There are two different options at this time to import. The first one is for GPIO:

Copy Code

import Adafruit_BBIO.GPIO as GPIO

If you'd like to use PWM, then import as follows:

Copy Code

import Adafruit_BBIO.PWM as PWM

You can access the channels by either referencing the pin "key" or the name. If you look at your BeagleBone Black, you can see that each set of pin headers has a name, either P8 or P9. Then, you can see that there are pin numbers that start from 1, and go to 46.

When you count the pins, you don't go length-wise, but start at 1, then across to 2, and then back up to the next pin 3, and so on. The following image illustrates this a bit better:

 BBB_pin_example.jpeg

So, to access the first pin on P9, you'd use "P9_1". You can also use the name of the pin to access it, which would be . You wouldn't want to do this though, as P9_1 is actually gnd! You'll want to view the last page of this guide to see which pins are available to use.

Not all pins are necessarily available. HDMI, and the eMMC flash module take up quite a few of them by default.

I2C is only compatible with Python2 due to the python-smbus dependency.

.END

Installing Adafruit-BeagleBone-IO-Python on Ubuntu - Created by Justin Cooper

Installation of  Adafruit-BeagleBone-IO-Python on Ubuntu - Created by Justin Cooper

http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/installation-on-ubuntu

The majority of this library will need to be run as sudo in Ubuntu.

Installing the Adafruit-BeagleBone-IO-Python (phew!) library is fairly simple. Let's make sure we have a good foundation setup first.

The most important part here is that you are using a Linux distribution with the 3.8 kernel. This kernel version made some fairly significant changes with how GPIO, PWM and ADC are accessed.

Connecting to your BeagleBone Black (SSH)

Let's ssh into the system so we can execute commands. Open your favorite terminal, and SSH into your BeagleBone Black (BBB). Note, Ubuntu does not come with Avahi-Daemon pre-installed. This means you need to use the IP address to connect and not the hostname.

Copy Code

ssh ubuntu@your.bbb.ip.address

Enter the the password (default is 'temppwd' most likely). You should now have a prompt available to enter commands.

Commands to setup and install BBIO

Now that you're connected to the BBB, you'll want to start with setting the date and time so that it's accurate. Copy and paste the following into your terminal (you may want to make it execute this on startup in the future):

Copy Code

sudo ntpdate pool.ntp.org

Next install the dependencies:

Copy Code

sudo apt-get update
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y

Now, execute the command to install BBIO:

Copy Code

sudo pip install Adafruit_BBIO

Test your Installation (optional)

You can optionally test if your installation was successful by simply trying to load one of the modules. Execute the following command from the console (not from within the python interpretor), it shouldn't throw any errors, but return one line:

Copy Code

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

#you should see this or similar:

<module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>

You can also validate by executing the 'python' command to enable the interpreter, and run the following code (you can tell you're in the right place when you see the ">>>" in your terminal):

Copy Code

import Adafruit_BBIO.GPIO as GPIO; print GPIO

#you should see this or similar:

<module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>

Manual Installation (optional)

You can also install BBIO by cloning the git repository. The following commands should get it installed as well:

Copy Code

sudo ntpdate pool.ntp.org
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip python-smbus -y
git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
cd adafruit-beaglebone-io-python
sudo python setup.py install
cd ..
sudo rm -rf adafruit-beaglebone-io-python

.END

Tuesday, 28 January 2014

Adafruit-BeagleBone-IO-Python installation - written by Justin Cooper

Installation on Angstrom - Created by Justin Cooper

http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/installation

Installing the Adafruit-BeagleBone-IO-Python (phew!) library is fairly simple. Let's make sure we have a good foundation setup first.

The most important part here is that you are using a Linux distribution with the 3.8 kernel. This kernel version made some fairly significant changes with how GPIO and PWM is accessed. The good news is that your BeagleBone Black came pre-installed with the proper kernel. It just may not be the latest and greatest. If you have some extra time, it may not be a bad idea to follow our installation guide for Angstrom, and flash your BeagleBone Black with the latest version.

Connecting to your BeagleBone Black (SSH)

Once you have the latest version of Angstrom on your BBB, let's ssh into the system so we can execute commands. The easiest way to gain access to the system is by using GateOne SSH. You can easily access GateOne by typing in the following into your browser window:

Copy Code

http://beaglebone.local

Once the page loads successully (you should see a green box that says "Your board is connected!"), you can click on the "GateOne SSH link to the upper left, in the sidebar. Then, click the "GateOne SSH client" link to get started. Some browsers may complain about invalid certificates, but you can proceed anyways.

 GateOne.jpeg

To sign into the beaglebone, type the following at the prompts (assuming root user on a fresh Angstrom installation):

Copy Code

Host/IP or SSH URL [localhost]:  beaglebone.local
Port [22]:  (just hit enter)
User: root

Connecting to ssh://root@beaglebone.local:22

 GateOneFilled.jpeg

Commands to setup and install Adafruit_BBIO

Now that you're connected to the BBB, you'll want to start with setting the date and time so that it's accurate. Copy and paste the following into your terminal (you may want to make it execute this on startup in the future):

Copy Code

/usr/bin/ntpdate -b -s -u pool.ntp.org

These commands will require internet access. If you get errors, please view the FAQ page for resolutions.
Next, execute each of the following lines. Copy and paste the following one-by-one into the terminal, and hit enter:

Copy Code

opkg update && opkg install python-pip python-setuptools python-smbus
pip install Adafruit_BBIO

Test your Installation (optional)

You can optionally test if your installation was successful by simply trying to load one of the modules. Execute the following command from the console (not from within the python interpretor), it shouldn't throw any errors, but return one line:

Copy Code

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

#you should see this or similar:

<module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>

You can also validate by executing the 'python' command to enable the interpreter, and run the following code (you can tell you're in the right place when you see the ">>>" in your terminal):

Copy Code

import Adafruit_BBIO.GPIO as GPIO; print GPIO

#you should see this or similar:

<module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>

Manual Installation (optional)

You can also install Adafruit_BBIO by cloning the git repository. The following commands should get it installed as well:

Copy Code

git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git

#set the date and time

/usr/bin/ntpdate -b -s -u pool.ntp.org

#install dependency

opkg update && opkg install python-distutils python-smbus

cd adafruit-beaglebone-io-python

python setup.py install

.END

Adafruit_BBIO written by Justin Cooper

Adafruit_BBIO 0.0.19 - A module to control BeagleBone IO channels

https://pypi.python.org/pypi/Adafruit_BBIO

Download

Adafruit_BBIO-0.0.19.tar.gz

**PLEASE NOTE:  This library may have breaking changes as development continues.  Please read the changelog anytime you update the library!**

**The PWM Duty Cycle range was reversed in 0.0.15 from 100(off)-0(on) to 0(off)-100(on).  Please update your code accordingly.**

**Adafruit's BeagleBone IO Python Library**

This is a set of Python tools to allow GPIO, PWM, and ADC access on the BeagleBone using the Linux 3.8 Kernel and above (latest releases).

It has been tested on the 5-20 and 6-6 Angstrom image on the BeagleBone Black.

**Note: BBIO has been renamed to Adafruit_BBIO.**

**Installation on Angstrom**

Easiest::

    /usr/bin/ntpdate -b -s -u pool.ntp.org
    opkg update && opkg install python-pip python-setuptools
    pip install Adafruit_BBIO

Manual::

    git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
    #set the date and time
    /usr/bin/ntpdate -b -s -u pool.ntp.org
    #install dependency
    opkg update && opkg install python-distutils
    cd adafruit-beaglebone-io-python
    python setup.py install

** Installation on Ubuntu/Debian **

Easiest::

    sudo ntpdate pool.ntp.org
    sudo apt-get update
    sudo apt-get install build-essential python-dev python-pip -y
    #easy_install -U distribute  //debian only
    sudo pip install Adafruit_BBIO

Manual::

    sudo ntpdate pool.ntp.org
    sudo apt-get update
    sudo apt-get install build-essential python-dev python-pip -y
    git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
    cd adafruit-beaglebone-io-python
    sudo python setup.py install
    cd ..
    sudo rm -rf adafruit-beaglebone-io-python

**Usage**

Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples.

**GPIO Setup**

Import the library, and setup as GPIO.OUT or GPIO.IN::

    import Adafruit_BBIO.GPIO as GPIO
    GPIO.setup("P8_14", GPIO.OUT)

You can also refer to the pin names::

    GPIO.setup("GPIO0_26", GPIO.OUT)

**GPIO Output**

Setup the pin for output, and write GPIO.HIGH or GPIO.LOW. Or you can use 1 or 0.::

    import Adafruit_BBIO.GPIO as GPIO
    GPIO.setup("P8_14", GPIO.OUT) GPIO.output("P8_14", GPIO.HIGH)

**GPIO Input**

Inputs work similarly to outputs.::

    import Adafruit_BBIO.GPIO as GPIO
    GPIO.setup("P8_14", GPIO.IN)

Polling inputs::

    if GPIO.input("P8_14"):
      print("HIGH")
    else:
      print("LOW")

Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::

    GPIO.wait_for_edge(channel, GPIO.RISING)

Detecting events::

    GPIO.add_event_detect("P9_12", GPIO.FALLING)
    #your amazing code here
    #detect wherever:
    if GPIO.event_detected("P9_12"):
      print "event detected!"

**PWM**::

    import Adafruit_BBIO.PWM as PWM
    #PWM.start(channel, duty, freq=2000, polarity=0)
    #duty values are valid 0 (off) to 100 (on)
    PWM.start("P9_14", 50)
    PWM.set_duty_cycle("P9_14", 25.5)
    PWM.set_frequency("P9_14", 10)

    PWM.stop("P9_14")
    PWM.cleanup()

    #set polarity to 1 on start:
    PWM.start("P9_14", 50, 2000, 1)

**ADC**::

    import Adafruit_BBIO.ADC as ADC
    ADC.setup()

    #read returns values 0-1.0
    value = ADC.read("P9_40")

    #read_raw returns non-normalized value
    value = ADC.read_raw("P9_40")

**Running tests**

Install py.test to run the tests. You'll also need the python compiler package for py.test.::

    opkg update && opkg install python-compiler
    #Either pip or easy_install
    pip install -U pytest
    easy_install -U pytest

Execute the following in the root of the project::

    py.test

**Credits**

The BeagleBone IO Python library was originally forked from the excellent MIT Licensed [RPi.GPIO](https://code.google.com/p/raspberry-gpio-python) library written by Ben Croston.

**License**

Written by Justin Cooper, Adafruit Industries. BeagleBone IO Python library is released under the MIT License.

0.0.19
* Fix for SPI.xfer crashes python after 3 calls
* Added a retry to reading for the analog inputs to avoid a bug where reading back and forth between two analog inputs would cause the resource to be unavailable every 16 scans (zthorson)
* Updated the build_path to be more selective over what paths it chooses (zthorson)
* Update Debian installation instructions in README (justinledwards)
* Increase the size of the buffer used for storing device tree names (SaintGimp)

0.0.18
----
* UART - Include UART overlays, and compile upon installation
* UART - Rename UART overlays
* Adafruit_I2C - Remove readU16Rev and readS16Rev
* Adafruit_I2C - Updated readU16/readS16 for correct 16-bit reads

0.0.17
----
* Fix SPI memory leaks
* Clean up of PWM code (bit-hacker, jwcooper)
* Remove UART debug statements

0.0.16
----
* Add polarity as optional fourth parameter to PWM.start().  Valid values are 0 and 1.  Default is still 0.
* Fix for actually setting the polarity in start.
* Add new unit tests to check that the polarity is being set properly, and valid values passed in.

0.0.15
----
* Fix PWM duty cycle so 0 is off and 100 is on.  Set polarity to 0 by default.
* Give extra buffer space in export, and unexport functions for gpio that are more than 2 digits (Chris Desjardins)
* Add new test case for 3 digit gpio (Chris Desjardins)
* Fix for test_direction_readback. gpio_get_direction wasn't properly null terminating the direction string (Chris Desjardins)

0.0.14
----
* Fix GPIO.gpio_function to work with the IO name (zthorson)
* Fix IOErrors not getting raised when fopen fails while loading overlays into device tree (bradfordboyle, jwcooper)
* Add new UART tests

0.0.13
----
* Remove the gpio parameter from callbacks (cdesjardins)

0.0.12
----
* Bump version due to pypi issues

0.0.11
----
* New UART module to export UART overlays
* Alpha support for SPI
* Add small delay after loading any device tree overlays

0.0.10
____
* Fix direction for event detection code
* Fix for segmentation faults on add_event_detect

0.0.9
____
* Fix for ADC Segmentation Faults

0.0.8
____
* Temp remove overlay compilation.  Ubuntu failures.

0.0.7
____
* Refactor and clean up adc and pwm
* Fix tests for Adafruit_BBIO rename

0.0.6
____
* Include Adafruit_I2C.py as top-level module

0.0.5
----
* Rename from BBIO to Adafruit_BBIO to reduce library conflicts and confusion.

0.0.4
----
* Support for pip and easy_install

0.0.3
____
* ADC enabled

0.0.2
____
* PWM enabled

0.0.1
____

* Initial Commit

* GPIO mostly working

* Initial GPIO unit tests

* PWM in progress


File Type Py Version Uploaded on Size

Adafruit_BBIO-0.0.19.tar.gz (md5) Source 2013-11-25 35KB

Downloads (All Versions):

118 downloads in the last day

496 downloads in the last week

2437 downloads in the last month

Author: Justin Cooper

Home Page: https://github.com/adafruit/adafruit-beaglebone-io-python/

Keywords: Adafruit BeagleBone IO GPIO PWM ADC

License: MIT

Categories

Development Status :: 3 - Alpha

Intended Audience :: Developers

License :: OSI Approved :: MIT License

Operating System :: POSIX :: Linux

Programming Language :: Python :: 2.6

Programming Language :: Python :: 2.7

Programming Language :: Python :: 3

Topic :: Home Automation

Topic :: Software Development

Topic :: System :: Hardware

Package Index Owner: jwcooper, adafruit

DOAP record: Adafruit_BBIO-0.0.19.xml

Website maintained by the Python community

Real-time CDN by Fastly / hosting by Rackspace / design by Tim Parkin Copyright © 1990-2014, Python Software Foundation

.END