Virtual Pins

More virtual pins can be seamlessly added in other packages.

Binary PWM

Binary PWM

Virtual pin

Pin type: Raw analog pin (input + output as defined by the real pin).

This virtual pin converts a single digital pin to PWM output.

YAML config

name: "FrontLed"  # Unique name of the pin.
type: electronic_io.BinaryPWM  # Type of the pin (the class to load).
digital_pin:  # Real digital pin this pin uses.
  pin: 'C0'
unit: 'PWM'  # Optional. The unit to use for the virtual pin.
min_value: 0.0  # Optional. The minimum value this pin can report.
max_value: 0.0  # Optional. The maximum value this pin can report.
sampling_period: 0.0  # Optional. Duration of the period of measurement.
is_readable/is_writable/can_persist: These are inherited from the real pin, but can be overridden here.
on_threshold: 1e-6
readback_on_value: 1.0
readback_off_value: 1.0
class electronic_io.virtual_pins.binary_pwm.BinaryPWM(name, pin_info, pin, on_threshold, readback_on_value, readback_off_value)

Bases: electronic_io.pins.VirtualPin

This virtual pin converts a single digital pin to PWM.

Create the digital pin combo virtual pin.

Parameters:
  • name (str) – Unique name of the pin.
  • pin_info (RawAnalogIOInfo) – Metadata about the virtual pin.
  • pin (DigitalPin) – The real pins to operate on.
  • on_threshold (float) – When the value to be written is larger than this value, the pin will be set to ON.
  • readback_on_value (float) – The PWM value to return when the real pin is ON.
  • readback_off_value (float) – The PWM value to return when the real pin is OFF.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(pin_name, config, io_board)

Create the pin from the given config dictionary and board information.

Parameters:
  • pin_name (str) – Name of the pin (its config dictionary key).
  • config (dict) – Configuration of the pin.
  • io_board (IOBoardClient) – The I/O board this pin should use (but it is not added to it automatically).
Returns:

The virtual pin.

Return type:

VirtualPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None

Digital Pin Combo

Digital Pin Combo

Virtual pin

Pin type: Raw analog pin (input + output as defined by the real pins).

This virtual pin combines the values of several digital pins into a single float value.

YAML config

name: "FrontLed"  # Unique name of the pin.
type: electronic_io.DigitalPinCombo  # Type of the pin (the class to load).
pins:  # Real pins this pin uses. All of them have to be digital.
  - pin: 'C0'
  - pin: 'C1'
unit: 'PWM'  # Optional. The unit to use for the virtual pin.
min_value: 0.0  # Optional. The minimum value this pin can report.
max_value: 0.0  # Optional. The maximum value this pin can report.
sampling_period: 0.0  # Optional. Duration of the period of measurement.
is_readable/is_writable/can_persist: These are inherited from the real pins, but can be overridden here.
combinations:  # Definitions of which combination means what value. Reverse lookup is done in nearest-neighbor
               # fashion and the first combo specifier (if multiple are defined) is returned.
  - combo: [0b00, 0b01]  # This way, one value can be assigned to multiples combos. The first combo is "canonical"
    value: 0.0           # (returned in reverse lookup).
  - combo: 0b11          # The combo items are binary representation of the pin values in the order they were defined
    value: 0.5           # (the first defined pin is the least significant bit, i.e. the rightmost one).
  - combo: 0b10
    value: 1.0
class electronic_io.virtual_pins.digital_pin_combo.DigitalPinCombo(name, pin_info, pins, combinations)

Bases: electronic_io.pins.VirtualPin

This virtual pin combines the values of several digital pins into a single float value.

Create the digital pin combo virtual pin.

Parameters:
  • name (str) – Unique name of the pin.
  • pin_info (RawAnalogIOInfo) – Metadata about the virtual pin.
  • pins (List[DigitalPin]) – The real pins to operate on.
  • Tuple[int]], float] combinations (Dict[Union[int,) – Which combinations of pins mean what value.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(pin_name, config, io_board)

Create the pin from the given config dictionary and board information.

Parameters:
  • pin_name (str) – Name of the pin (its config dictionary key).
  • config (dict) – Configuration of the pin.
  • io_board (IOBoardClient) – The I/O board this pin should use (but it is not added to it automatically).
Returns:

The virtual pin.

Return type:

VirtualPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None

Linear ADC Pin

Linear ADC Pin

Virtual pin

Pin type: Raw analog pin (input + output as defined by the real pin).

This virtual pin implements a single linear conversion between analog-digital converter (ADC) values and raw floats.

YAML config

name: "Voltage1"  # Unique name of the pin.
type: electronic_io.LinearADCPin  # Type of the pin (the class to load).
adc_pin:  # The digitized analog pin to use.
  pin: 'I1'
linear_coeff: 0.005859375  # Linear coefficient of the D->A transform.
constant_coeff: -12.0  # Constant offset in the D->A transform.
unit: 'V'  # Optional. The unit to use for the virtual pin.
min_value: 0.0  # Optional. The minimum value this pin can report.
max_value: 0.0  # Optional. The maximum value this pin can report.
sampling_period: 0.0  # Optional. Duration of the period of measurement.
is_readable/is_writable/can_persist: These are inherited from the real pins, but can be overridden here.
class electronic_io.virtual_pins.linear_adc_pin.LinearADCPin(name, pin_info, adc_pin, linear_coeff, constant_coeff)

Bases: electronic_io.pins.VirtualPin

This virtual pin implements a single linear conversion between analog-digital converter (ADC) values and raw floats.

Create the linear ADC pin.

Parameters:
  • name (str) – Unique name of the pin.
  • pin_info (RawAnalogIOInfo) – Metadata about the virtual pin.
  • adc_pin (DigitizedAnalogPin) – The digitized analog pin to use.
  • linear_coeff (float) – Linear coefficient of the D->A transform.
  • constant_coeff (float) – Constant offset in the D->A transform.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(pin_name, config, io_board)

Create the pin from the given config dictionary and board information.

Parameters:
  • pin_name (str) – Name of the pin (its config dictionary key).
  • config (dict) – Configuration of the pin.
  • io_board (IOBoardClient) – The I/O board this pin should use (but it is not added to it automatically).
Returns:

The virtual pin.

Return type:

VirtualPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None