gadgets.io
The classes of gadgets.io can be used outside of the
gadgets system. They don’t depend on zeromq and don’t
perform any of the gadgets communication.
IO
-
class gadgets.io.io.IO[source]
All subclasses of Device have an ‘io’ property. It should return
an object that provides this interface.
-
close()[source]
close the io device
-
off()[source]
turn the io device off
-
on()[source]
turn on the io device
-
status[source]
status of the io device
Counter
-
class gadgets.io.counter.Counter(pin, ticks)[source]
Blocks for a given number of rising edges on a gpio pin.
-
wait()[source]
Blocks until for the number of rising
edges specified by self._ticks
GPIO
GPIOFactory
GPIO
-
class gadgets.io.gpio.GPIO(pin, direction='in', pullup=False)[source]
Turning on a pin using the linux sysfs interface requires you to:
- make sure the mux mode of the pin is set to gpio (which requires you to find out the name of the pin)
- figure out the number to write to /sys/class/gpio/export in order to enable the gpio interface
- write ‘out’ to /sys/class/gpio/gpio<gpio number>/direction
- write 1 to /sys/class/gpio/gpio<gpio number>/value
All this just to turn on a pin. This GPIO class takes care of all
that for you. All you have to do is pick the port and pin (port 8,
pin 3 in this case) and initialize a GPIO object like:
>>> from gadgets.pins.beaglebone import pins
>>> from gadgets.io import GPIO
>>> gpio = GPIO(pins['gpio'][8][3])
Now you can turn the pin on and off by:
>>> gpio.on()
>>> gpio.off()
If you want to use a gpio pin as input, you initialize it like this:
>>> from gadgets.pins.beaglebone import pins
>>> gpio = GPIO(pins['gpio'][8][11], direction='in')
You can then read the value of the pin by:
-
close()[source]
Closes the file that GPIO uses to set/read the
value of the pin.
-
home_dir[source]
After a gpio pin is enabled the sysfs interface for the
pin is created as a directory. This property creates
the path to that directory.
-
mux_path[source]
creates the full path to the sysfs mux interface
for this pin.
-
off()[source]
Sets the gpio pin low.
-
on()[source]
Sets the gpio pin high.
-
value()[source]
Get the value of the gpio pin.
Poller
-
class gadgets.io.poller.Poller(pin, timeout=None, edge='rising')[source]
Poller performs a poll on a gpio line. Just call wait and it will block
until the gpio pin goes high.
>>> from gadgets.pins.beaglebone import pins
>>> from gadgets.io import GPIO
>>> poller = Poller(pins['gpio'][8][3])
>>> poller.wait()
This will then block until the pin goes high.
-
close()[source]
Closes the file descriptor that Poller uses for the
Linux poll.
-
wait()[source]
Blocks until the pin goes high
PWM
-
class gadgets.io.pwm.PWM(pin, frequency=20000, mux_path='/sys/kernel/debug/omap_mux')[source]
Uses the pwm pins’ sysfs interface. You can use a pwm pin like this:
>>> from gadgets.pins.beaglebone import pins
>>> from gadgets.io import GPIO
>>> pwm = PWM(pins['pwm'][8][13])
Now you can turn it on and vary the duty percent:
>>> pwm.on() #turns the pin on with a 100 duty_percent
>>> pwm.duty_percent = 50
NOTE: The beaglebone pwm clock must be enabled before using this class.
You can enable it by calling enable-pwm from the command line (requires
gadgets and python-mmap to be installed)
-
duty_percent[source]
Set the duty_percent with a value from 0 to 100.
The value is written to the sysfs duty_percent interface.
If the pwm was turned off before this call, the pwm will be
turned on.
-
off()[source]
turns off the pwm and sets the duty cycle to 0
-
on()[source]
turns on the pwm and sets the duty cycle to 100