j5.components.gpio_pin module¶
Classes for GPIO Pins.
-
exception
j5.components.gpio_pin.
BadGPIOPinModeError
[source]¶ Bases:
Exception
The pin is not in the correct mode.
-
class
j5.components.gpio_pin.
GPIOPin
(identifier: int, backend: j5.components.gpio_pin.GPIOPinInterface, *, initial_mode: Union[Type[j5.components.component.DerivedComponent], j5.components.gpio_pin.GPIOPinMode], hardware_modes: Set[j5.components.gpio_pin.GPIOPinMode] = {<GPIOPinMode.DIGITAL_OUTPUT: 3>}, firmware_modes: Set[Type[j5.components.component.DerivedComponent]] = {})[source]¶ Bases:
j5.components.component.Component
A GPIO Pin.
-
DEFAULT_FW_MODE
= {}¶
-
DEFAULT_HW_MODE
= {<GPIOPinMode.DIGITAL_OUTPUT: 3>}¶
-
analogue_read
() → float[source]¶ Get the scaled analogue reading of the pin.
Returns: scaled analogue reading
-
analogue_write
(new_value: float) → None[source]¶ Set the analogue value of the pin.
Parameters: new_value – analogue value Raises: ValueError – pin value must be between 0 and 1
-
digital_read
() → bool[source]¶ Get the digital state of the pin.
Returns: digital read state of the pin.
-
digital_write
(state: bool) → None[source]¶ Set the digital state of the pin.
Parameters: state – digital state.
-
firmware_modes
¶ Get the supported firmware modes.
Returns: supported firmware modes.
-
identifier
¶ An integer to identify the component on a board.
Returns: component identifier.
-
static
interface_class
() → Type[j5.components.gpio_pin.GPIOPinInterface][source]¶ Get the interface class that is required to use this component.
Returns: interface class.
-
last_digital_write
¶ Get the last set digital state of the pin.
This does not perform a read operation, it only gets the last set value, which is usually cached in memory.
Returns: last set digital state of the pin
-
mode
¶ Get the mode of this pin.
Returns: current mode of the pin.
-
pwm_write
(new_value: float) → None[source]¶ Set the PWM value of the pin.
Parameters: new_value – new duty cycle Raises: ValueError – pin value must be between 0 and 1
-
-
class
j5.components.gpio_pin.
GPIOPinInterface
[source]¶ Bases:
j5.components.component.Interface
An interface containing the methods required for a GPIO Pin.
-
get_gpio_pin_digital_state
(identifier: int) → bool[source]¶ Get the last written state of the GPIO pin.
Parameters: identifier – pin number Returns: Last known digital state of the pin.
-
get_gpio_pin_mode
(identifier: int) → j5.components.gpio_pin.GPIOPinMode[source]¶ Get the hardware mode of a GPIO pin.
Parameters: identifier – pin number. Returns: mode of the pin.
-
read_gpio_pin_analogue_value
(identifier: int) → float[source]¶ Read the scaled analogue value of the GPIO pin.
Parameters: identifier – pin number Returns: scaled analogue value of the pin.
-
read_gpio_pin_digital_state
(identifier: int) → bool[source]¶ Read the digital state of the GPIO pin.
Parameters: identifier – pin number Returns: digital state of the pin.
-
set_gpio_pin_mode
(identifier: int, pin_mode: j5.components.gpio_pin.GPIOPinMode) → None[source]¶ Set the hardware mode of a GPIO pin.
Parameters: - identifier – pin number to set.
- pin_mode – mode to set the pin to.
-
write_gpio_pin_dac_value
(identifier: int, scaled_value: float) → None[source]¶ Write a scaled analogue value to the DAC on the GPIO pin.
Parameters: - identifier – pin number
- scaled_value – scaled analogue value to write
-
-
class
j5.components.gpio_pin.
GPIOPinMode
[source]¶ Bases:
enum.IntEnum
Hardware modes that a GPIO pin can be set to.
-
ANALOGUE_INPUT
= 4¶ The analogue voltage of the pin can be read.
-
ANALOGUE_OUTPUT
= 5¶ The analogue voltage of the pin can be set using a DAC.
-
DIGITAL_INPUT
= 0¶ The digital state of the pin can be read
-
DIGITAL_INPUT_PULLDOWN
= 2¶ Same as DIGITAL_INPUT but internal pull-down is enabled
-
DIGITAL_INPUT_PULLUP
= 1¶ Same as DIGITAL_INPUT but internal pull-up is enabled
-
DIGITAL_OUTPUT
= 3¶ The digital state of the pin can be set.
-
PWM_OUTPUT
= 6¶ A PWM output signal can be created on the pin.
-