The wiring-x86
module provides an unified API for all the platforms it
supports. In case of a platform-specific API was added it will be explicitly
mentioned in the documentation.
Two classes are exposed my the module:
GPIOEdison
GPIOGalileoGen2
GPIOGalileo
The module is generally imported and intialised as follows:
from wiringx86 import GPIOEdison as GPIO
gpio = GPIO()
GPIO
([debug])Create a new GPIO object.
Parameters: | debug (bool) – Optional debug parameter. |
---|---|
Return type: | A GPIO object. |
The GPIO()
constructor is used to create a new gpio object:
from wiringx86 import GPIOEdison as GPIO
gpio = GPIO()
The debug
constructor options can be used to enable the debug mode
showing the interaction with sysfs:
gpio = GPIO(debug=False)
digitalWrite
(pin, state)Configure a gpio pin for output.
Parameters: |
|
---|
The digitalWrite()
method is used to set the state for a given gpio
pin. The available states are high
and low
. These are generally passed
as GPIO
properties such as gpio.HIGH
for convenience:
gpio.digitalWrite(13, gpio.HIGH)
The GPIO pin is assumed to be configured as gpio.OUTPUT
when writing.
digitalRead
(pin)Read the state of a GPIO pin.
Parameters: | pin (int) – Arduino pin number (0-19). |
---|---|
Returns: | Current value of the GPIO pin. |
Return type: | int |
Read the current state of a GPIO pin:
state = gpio.digitalRead(pin)
The GPIO pin is assumed to be configured as gpio.INPUT
analogWrite
(pin, value)Write analog output (PWM) to a pin.
Parameters: |
|
---|
The gpio pin is assumed to be configured as gpio.PWM
. Generates a PWM signal
with the desired duty cycle. The value must be in range 0-255.
analogRead
(pin)Read analog input from the pin
Param: | int pin: Arduino analog pin number (14-19). |
---|---|
Returns: | Digital representation with 10 bits resolution (range 0-1023) of voltage on the pin. |
The GPIO pin is assumed to be configured as gpio.ANALOG_INPUT
. Returns
values in range 0-1023:
value = gpio.analogRead(analogpin)
setPWMPeriod
(pin, period)Set the PWM period.
Param: | int pin: Arduino PWM pin number (3, 5, 6, 9, 10, 11). |
---|---|
Param: | int period: PWM period in nanoseconds. |
On the Galileo Gen2 all PWM channels share the same period. When this is set all the PWM outputs are disabled for at least 1ms while the chip reconfigures itself. The PWM pin is then ignored.
pinMode
(pin, mode)Set the mode of a GPIO pin.
Parameters: |
|
---|
This function must be called before doing any other operation on the pin. It sets up the muxing needed for the pin to put it in one of the following modes:
For example:
gpio.pinMode(pin, gpio.OUTPUT)
cleanup
(self)Do a general cleanup.
Close all open handlers for reading and writing. Unexport all exported GPIO pins and unexport all exported PWM channels:
gpio.cleanup()
Calling this function is not mandatory but it’s recommended once you are finished using the library and if it is being used with a larger application that runs for a long period of time.