Skip to main content

cffi-based Python bindings for FreeBSD GPIO

Project description

Requirements:

  • Python 2.7 or 3.4

  • cffi

How to install

Python package on FreeBSD 11 have problem when using python source that needed to compile thing, so the easiest way is to use the binary packages uploaded to pypi:

pip install --only-binary freebsd-11 fbsd_gpio

How to use

The fbsd_gpio module expose two classes, GpioController and GpioPin

Use gpio controller unit 0 (/dev/gpioc0) and list all the pins name:

from fbsd_gpio import GpioController

gpioc = GpioController(0)
for pin in gpioc:
    print(pin)

Set pin 127 to output and logical value 1

from fbsd_gpio import GpioController, GPIO_VALUE_HIGH

gpioc = GpioController(0)
gpioc.pin_output(127)
# The two following lines are equivalent
gpioc.pin_set(127, GPIO_VALUE_HIGH)
gpioc.pin_high(127)

Alternativelly you can use the GpioPin class:

from fbsd_gpio import GpioPin, GPIO_VALUE_HIGH

pin = GpioPin(127, unit=0)
pin.ouput = True
# The following lines are equivalent
pin.set(GPIO_VALUE_HIGH)
pin.high()
pin(GPIO_VALUE_HIGH)

Or use the name of the pin directly:

from fbsd_gpio import GpioController, GPIO_VALUE_HIGH

gpioc = GpioController(0)
gpioc.gpioled0.output = True
# The three following lines are equivalent
gpioc.gpioled.set(GPIO_VALUE_HIGH)
gpioc.gpioled0.high()
gpioc.gpioled0(GPIO_VALUE_HIGH)

Get the value of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
if pin.input:
    print('Pin is input mode')
else
    print('Pin is output mode')
# The two following lines are equivalent
    value = pin.get()
    value = pin()

Toggle the value of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
pin.toggle()

Change the name of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
pin.name = 'green_led'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fbsd_gpio-0.4.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distributions

File details

Details for the file fbsd_gpio-0.4.1.tar.gz.

File metadata

  • Download URL: fbsd_gpio-0.4.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fbsd_gpio-0.4.1.tar.gz
Algorithm Hash digest
SHA256 6ff91424bd19d65029b8bd6155e70f2ea2579fda21ba762458cb9b94e29acc57
MD5 cb818433f838c8a5e6d25548ac07e777
BLAKE2b-256 26e4bf66f30ef8f86a3431921dc6f7f17720ddfbf4c27c73e173392adbd800d8

See more details on using hashes here.

File details

Details for the file fbsd_gpio-0.4.1.freebsd-11.0-CURRENT-arm-py34.tar.gz.

File metadata

File hashes

Hashes for fbsd_gpio-0.4.1.freebsd-11.0-CURRENT-arm-py34.tar.gz
Algorithm Hash digest
SHA256 53d80700d16fe06fb75767f1716c3215b69281775c990e5f966570d992cdc1ea
MD5 227104fb334c81b3ddc3bdf7eedd05c2
BLAKE2b-256 7975599de965b931bf8dce3bee8fdb09e540d00006ab4869cbc1bef1a883eaa9

See more details on using hashes here.

File details

Details for the file fbsd_gpio-0.4.1.freebsd-11.0-CURRENT-arm-py27.tar.gz.

File metadata

File hashes

Hashes for fbsd_gpio-0.4.1.freebsd-11.0-CURRENT-arm-py27.tar.gz
Algorithm Hash digest
SHA256 4e680e46d5acc1738856391eab5b128a4989f35955813919ae9e1b4fd204c3a5
MD5 e3427bf88a3be94a54e8e4b7c1751814
BLAKE2b-256 db8db3b823347fcb099cea20f5af2a381c1ebef404247623966e3cd963107478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page