Skip to main content

cffi-based Python bindings for FreeBSD GPIO

Project description

Requirements:

  • Python 2.7 or 3.4

  • cffi

  • sysctl

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.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distributions

File details

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

File metadata

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

File hashes

Hashes for fbsd_gpio-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4f397418042c71e72fbfbf6610f90b04237127f223296d3a82bbe87ff6c7ac04
MD5 9141b9227cb24f2a64f235b5edd22052
BLAKE2b-256 3959d31e0abc3ea567100b89fd9fb9e4c10bd38d701f2d428f14a7652609c733

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fbsd_gpio-0.4.0.freebsd-11.0-CURRENT-arm.tar.gz
Algorithm Hash digest
SHA256 cc8cf00b539318ad684cc3a8d148c4c158faa2191a0375c485348b9200c26b5e
MD5 29f0c43fc8525e8abbb993b32208ca3b
BLAKE2b-256 c4d8a65ec8babfe4777f0b6bfb905eb9be20afe296e45978ace1f7998991f70c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fbsd_gpio-0.4.0.27-freebsd-11.0-CURRENT-arm.tar.gz
Algorithm Hash digest
SHA256 b3cb75f3a6295fc5f3f5d9560214715717aa906a478386e5c3c82c5936599285
MD5 9aebcb04d0ccc67195a889ca5d5f673b
BLAKE2b-256 44ec2700231e6c1f31708a257f79d53b0206f599eb6d5c192607981e3215b61a

See more details on using hashes here.

Supported by

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