{"id":15023336,"url":"https://github.com/adafruit/adafruit-beaglebone-io-python","last_synced_at":"2025-05-15T18:06:14.621Z","repository":{"id":8889321,"uuid":"10608524","full_name":"adafruit/adafruit-beaglebone-io-python","owner":"adafruit","description":"Adafruit's BeagleBone IO Python Library","archived":false,"fork":false,"pushed_at":"2024-05-08T20:20:54.000Z","size":616,"stargazers_count":478,"open_issues_count":30,"forks_count":219,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-05-15T18:06:12.717Z","etag":null,"topics":["beaglebone","beaglebone-black","python"],"latest_commit_sha":null,"homepage":"http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adafruit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-10T20:15:00.000Z","updated_at":"2025-02-20T05:06:46.000Z","dependencies_parsed_at":"2024-06-19T00:20:11.550Z","dependency_job_id":"7035dede-342e-4802-b6d2-2420f7fd006d","html_url":"https://github.com/adafruit/adafruit-beaglebone-io-python","commit_stats":{"total_commits":506,"total_committers":47,"mean_commits":10.76595744680851,"dds":0.6818181818181819,"last_synced_commit":"7361d9a997bce4ab79c83c4ef30442e8dd13f363"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adafruit%2Fadafruit-beaglebone-io-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adafruit%2Fadafruit-beaglebone-io-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adafruit%2Fadafruit-beaglebone-io-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adafruit%2Fadafruit-beaglebone-io-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adafruit","download_url":"https://codeload.github.com/adafruit/adafruit-beaglebone-io-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394719,"owners_count":22063984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beaglebone","beaglebone-black","python"],"created_at":"2024-09-24T19:58:57.896Z","updated_at":"2025-05-15T18:06:14.576Z","avatar_url":"https://github.com/adafruit.png","language":"C","readme":"# Adafruit Beaglebone I/O Python API\n\n[![Documentation Status](https://readthedocs.org/projects/adafruit-beaglebone-io-python/badge/?version=latest)](http://adafruit-beaglebone-io-python.readthedocs.io/en/latest/?badge=latest)\n[![PyPI version](https://badge.fury.io/py/Adafruit_BBIO.svg)](https://badge.fury.io/py/Adafruit_BBIO)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/Adafruit_BBIO.svg)](https://pypi.python.org/pypi/Adafruit_BBIO/)\n\nAdafruit BBIO is an API to enable [GPIO](README.md#gpio-setup), [PWM](README.md#pwm), [ADC](README.md#adc), [UART](README.md#uart), [SPI](README.md#spi) and [eQEP](README.md#eqep) (Quadrature Encoder) hardware access from Python applications running on the Beaglebone. \n\n* It is recommended to use an [official BeagleBoard.org Debian image](https://beagleboard.org/latest-images)\n  * **Currently recommended image: [Debian 10.3 \"Buster\" IoT (2020-04-06)](http://beagleboard.org/latest-images)** _(default kernel is 4.19.x-ti)_\n\n* Adafruit_BBIO supports Linux kernels 3.8 through 4.19\n\n* New versions of Adafruit_BBIO may break backwards compatibility. Please read the [changelog](CHANGELOG.md).\n\n* It is recommended to use Python 3\n\n## Installation on Debian\n\nNote: Follow the instructions on BeagleBoard.org to [get connected to the Internet](https://beagleboard.org/upgrade#connect)\n\n**Easiest:**\n```\nsudo apt-get update\nsudo apt-get install build-essential python3-dev python3-pip -y\nsudo pip3 install Adafruit_BBIO\n```\n    \n**Manual:**\n```\nsudo apt-get update\nsudo apt-get install build-essential python3-dev python3-pip -y\ngit clone git://github.com/adafruit/adafruit-beaglebone-io-python.git\ncd adafruit-beaglebone-io-python\nsudo python3 setup.py install\n```\n\nUpgrade Adafruit_BBIO to latest version on [PyPI](https://pypi.python.org/pypi/Adafruit_BBIO):\n```\nsudo pip3 install --upgrade Adafruit_BBIO\n```\n    \n## Usage\n\nUsing the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples.\n\n### Pin Numbers\n\nPlease note that there is no '0' prefix for the pin numbers.  For example, pin 7 on header P8 is `P8_7`.\n\n**Correct:**\n```\nGPIO.setup(\"P8_7\", OUT )\n```\n\n**INCORRECT:**\n```\nGPIO.setup(\"P8_07\", OUT )\n```\n\nRefer to `pins_t table[]` in [common.c](https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c#L73) all the pin labels.\n\n### config-pin\n\n[config-pin](https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io) is now used on the official BeagleBoard.org Debian Jessie and Stretch images to control pin mode (e.g. pin mux).\n\n```\ndebian@beaglebone:~$ config-pin -q P9_14\nP9_14 Mode: pwm\n\ndebian@beaglebone:~$ config-pin -l P9_14\ndefault gpio gpio_pu gpio_pd pwm\n\ndebian@beaglebone:~$ config-pin P9_14 gpio\n\ndebian@beaglebone:~$ config-pin -q P9_14\nP9_14 Mode: gpio Direction: in Value: 0\n\ndebian@beaglebone:~$ config-pin P9_14 pwm\n\ndebian@beaglebone:~$ config-pin -q P9_14\nP9_14 Mode: pwm\n```\n\n### GPIO Setup\n\nImport the library, and setup as GPIO.OUT or GPIO.IN::\n\n    import Adafruit_BBIO.GPIO as GPIO\n    GPIO.setup(\"P8_14\", GPIO.OUT)\n\nYou can also refer to the pin names::\n\n    GPIO.setup(\"GPIO0_26\", GPIO.OUT)\n\n### GPIO Output\n\nSetup the pin for output, and write GPIO.HIGH or GPIO.LOW. Or you can use 1 or 0.::\n\n    import Adafruit_BBIO.GPIO as GPIO\n    GPIO.setup(\"P8_14\", GPIO.OUT)\n    GPIO.output(\"P8_14\", GPIO.HIGH)\n\n### On-Board LEDs\n\nOn-board LEDs (USR0-USR3) are handled by LED class driver rather than the GPIO pin driver.\n\nThey have a different path in the /sys/ filesystem.\n\nSetup the pin for output and write GPIO.HIGH or GPIO.LOW::\n\n    import Adafruit_BBIO.GPIO as GPIO\n    import time\n    \n    for i in range(4):\n        GPIO.setup(\"USR%d\" % i, GPIO.OUT)\n\n    while True:\n        for i in range(4):\n            GPIO.output(\"USR%d\" % i, GPIO.HIGH)\n            time.sleep(1)\n        for i in range(4):\n            GPIO.output(\"USR%d\" % i, GPIO.LOW)\n            time.sleep(1)\n    \n### GPIO Input\n\nInputs work similarly to outputs.:\n\n    import Adafruit_BBIO.GPIO as GPIO\n    GPIO.setup(\"P8_14\", GPIO.IN)\n    \nPolling inputs:\n    \n    if GPIO.input(\"P8_14\"):\n      print(\"HIGH\")\n    else:\n      print(\"LOW\")\n\nWaiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH:\n\n    GPIO.wait_for_edge(channel, GPIO.RISING)\n\n    or\n    \n    GPIO.wait_for_edge(channel, GPIO.RISING, timeout)\n\nDetecting events:\n\n    GPIO.add_event_detect(\"P9_12\", GPIO.FALLING) \n    #your amazing code here \n    #detect wherever: \n    if GPIO.event_detected(\"P9_12\"):\n      print(\"event detected!\")\n\n### PWM\n**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.**\n\n    import Adafruit_BBIO.PWM as PWM \n    #PWM.start(channel, duty, freq=2000, polarity=0) \n    #duty values are valid 0 (off) to 100 (on) \n    PWM.start(\"P9_14\", 50)\n    PWM.set_duty_cycle(\"P9_14\", 25.5) \n    PWM.set_frequency(\"P9_14\", 10)\n\n    PWM.stop(\"P9_14\")\n    PWM.cleanup()\n    \n    #set polarity to 1 on start:\n    PWM.start(\"P9_14\", 50, 2000, 1)\n\n### ADC\n\n    import Adafruit_BBIO.ADC as ADC\n    ADC.setup()\n\n    #read returns values 0-1.0 \n    value = ADC.read(\"P9_40\")\n\n    #read_raw returns non-normalized value \n    value = ADC.read_raw(\"P9_40\")\n\n### [UART](https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart)\n* Use [`config-pin` to set pin mode](https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io) for [UART1 and UART2 pins](http://beagleboard.org/static/images/cape-headers-serial.png)\n```\nconfig-pin P9.21 uart  # UART2_TXD\nconfig-pin P9.22 uart  # UART2_RXD\nconfig-pin P9.24 uart  # UART1_TXD\nconfig-pin P9.26 uart  # UART1_RXD\n```\n* [Install pyserial](https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart#using-uart-with-python)\n```\nsudo pip install pyserial\n```\n* [Test UART1](https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart#using-uart-with-python)\n```\nimport Adafruit_BBIO.UART as UART\nimport serial\n\nUART.setup(\"UART1\")\n\nwith serial.Serial(port = \"/dev/ttyO1\", baudrate=9600) as ser:\n    print(\"Serial is open!\")\n    ser.write(b\"Hello World!\")\n\n```\n* Available UART names on BeagleBone\n  * `UART1`: /dev/ttyO1, Rx: P9_26, Tx: P9_24\n  * `UART2`: /dev/ttyO2, Rx: P9_22, Tx: P9_21\n  * `UART4`: /dev/ttyO4, Rx: P9_11, Tx: P9_13\n  * `UART5`: /dev/ttyO5, Rx: P8_38, Tx: P8_37\n  * note: `UART5` requires `disable_uboot_overlay_video=1` in `/boot/uEnv.txt`\n* Available UART names on PocketBeagle\n  * `PB-UART0`: /dev/ttyO0, Rx: P1_30, Tx: P1_32\n  * `PB-UART1`: /dev/ttyO1, Rx: P2_11, Tx: P2_09\n  * `PB-UART2`: /dev/ttyO2, Rx: P1_08, Tx: P1_10\n* [Loopback test with UART1 and UART2](https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/uart#testing-and-using-the-uart)\n\n\n### [SPI](https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/spi)\n* Use [`config-pin` to set pin mode](https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io) for [SPI pins](http://beagleboard.org/static/images/cape-headers-spi.png)\n  * SPI0\n    * SPI0_CS0: `config-pin p9.17 spi_cs`\n    * SPI0_D0: `config-pin p9.21 spi`\n    * SPI0_D1: `config-pin p9.18 spi`\n    * SPI0_SCLK: `config-pin p9.22 spi_sclk`\n  * SPI1\n    * SPI1_CS0: `config-pin p9.20 spi_cs`\n    * SPI1_CS0: `config-pin p9.28 spi_cs`\n    * SPI1_CS1: `config-pin p9.19 spi_cs`\n    * SPI1_CS1: `config-pin p9.42 spi_cs`\n    * SPI1_D0: `config-pin p9.29 spi`\n    * SPI1_D1: `config-pin p9.30 spi`\n    * SPI1_SCLK: `config-pin p9.31 spi_sclk`\n* Example:\n```\nfrom Adafruit_BBIO.SPI import SPI\n#spi = SPI(bus, device) #/dev/spidev\u003cbus\u003e.\u003cdevice\u003e\n\n# /dev/spidev0.0\nspi = SPI(1,0)\nprint(spi.xfer2([32, 11, 110, 22, 220]))\nspi.close() \n\n# /dev/spidev0.1\nspi = SPI(1,1)\nprint(spi.xfer2([32, 11, 110, 22, 220]))\nspi.close() \n\n# /dev/spidev1.0\nspi = SPI(2,0)\nprint(spi.xfer2([32, 11, 110, 22, 220]))\nspi.close() \n\n# /dev/spidev1.1\nspi = SPI(2,1)\nprint(spi.xfer2([32, 11, 110, 22, 220]))\nspi.close() \n```\n\n### eQEP\n\nTo use the enhanced Quadrature Encoder Pulse (eQEP) module, please refer to the [`Encoder` module's documentation](https://github.com/adafruit/adafruit-beaglebone-io-python/tree/master/Adafruit_BBIO#usage).\n\n## Running tests\n\nInstall py.test to run the tests. You'll also need the python compiler package for pytest:\n```\nsudo pip3 install pytest\n```\nExecute the following in the root of the project:\n```\npytest\n```\nNOTE: `sudo` should not be required as udev configures group ownership and permission for [GPIO](https://github.com/rcn-ee/repos/blob/master/bb-customizations/suite/stretch/debian/80-gpio-noroot.rules) and [PWM](https://github.com/rcn-ee/repos/blob/master/bb-customizations/suite/stretch/debian/81-pwm-noroot.rules)\n\n## Reporting issues\n\nWhen reporting issues, plesae run the following script which will print the system configuration:\n```\nsudo /opt/scripts/tools/version.sh\n```\nand paste the output in a reply.\n\nThis script should be present for any Debian or Ubunut image downloaded from:\nhttps://beagleboard.org/ or https://rcn-ee.com/\n\n\n## Credits\n\nThe 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.\n\n## License\n\nWritten by Justin Cooper, Adafruit Industries. BeagleBone IO Python library is released under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadafruit%2Fadafruit-beaglebone-io-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadafruit%2Fadafruit-beaglebone-io-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadafruit%2Fadafruit-beaglebone-io-python/lists"}