Skip to main content

cffi-based Python bindings for FreeBSD GPIO

Project description

Requirements:

  • Python 2.7 or 3.4

  • cffi

  • sysctl

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

Uploaded Source

Built Distribution

File details

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

File metadata

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

File hashes

Hashes for fbsd_gpio-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0df37f9bb3bac3575ff5637f7c1ae694e31750b4db5a12b9f04d4178d06cbb1d
MD5 36372a11044356eb1c880cb00e166d63
BLAKE2b-256 74024834672d6c523907c8ee3e0e1b65279e0878732b86289bc60d700dff1155

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fbsd_gpio-0.3.0.freebsd-11.0-CURRENT-arm.tar.gz
Algorithm Hash digest
SHA256 af6f498f7bfb04404ba71512330b0e6db8c48edfb7526b82377981a8ddc1255b
MD5 15b88849ab0371e69833f32a87bf50af
BLAKE2b-256 c869301d23e46d92ef02364b61c8b9384eb83dc27b327b793f68448661405703

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