Skip to content

READ_N_PINS

The READ_N_PINS node allows you to measure and output voltages from Flexiforce sensors using a Phidget InterfaceKit.Params:default : OrderedPairDefault value to be used if no input is connected to the node, by default Nonen_sensors : intDefines the number of pressure sensors connected to the Phidget InterfaceKit.Returns:out : OrderedPairThe output of the node is a list of voltages measured from the sensors.
Python Code
from typing import Optional

from flojoy import OrderedPair, flojoy
from Phidget22.Devices.VoltageRatioInput import VoltageRatioInput


def onVoltageRatioChange(self, voltageRatio):
    # Declaration of the Event handler, print Voltage variation for a channel.
    print("VoltageRatio [" + str(self.getChannel()) + "]: " + str(voltageRatio))


@flojoy(deps={"Phidget22": "1.14.20230331"})
def READ_N_PINS(
    default: Optional[OrderedPair] = None,
    n_sensors: int = 1,
) -> OrderedPair:
    """The READ_N_PINS node allows you to measure and output voltages from Flexiforce sensors using a Phidget InterfaceKit.

    Parameters
    ----------
    default : OrderedPair, optional
        Default value to be used if no input is connected to the node, by default None
    n_sensors : int
        Defines the number of pressure sensors connected to the Phidget InterfaceKit.

    Returns
    -------
    OrderedPair
        The output of the node is a list of voltages measured from the sensors.
    """

    voltage: list[float] = []
    pressions: list[float] = []
    sensor_num: list[int] = []

    for i in range(0, n_sensors):
        sensor_num.append(i + 1)
        # Creation of an instance of the VoltageRationInput class
        voltage_ratio_input = VoltageRatioInput()
        # Set Channel for Communication with the Phidget Interface Kit :
        voltage_ratio_input.setChannel(i)
        # Assign the handler that will be called when the event occurs :
        voltage_ratio_input.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
        # Open the Channel after event handler is set :
        voltage_ratio_input.openWaitForAttachment(5000)
        volt_i: float = (
            voltage_ratio_input.getVoltageRatio()
        )  # Measure Voltage from the sensor
        voltage.append(volt_i)  # Add Voltage to the list of measurements

        # Example of a Calibration to convert Voltage into pressions :
        pression_i: float = (volt_i - calibration1) / calibration2
        pressions.append(pression_i)

    return OrderedPair(x=sensor_num, y=voltage)

Find this Flojoy Block on GitHub

Example

Having problem with this example app? Join our Discord community and we will help you out!
React Flow mini map

This example shows how to use the PHIDGET22 node to measure pressures from Flexiforce sensors using a Phidget Interface Kit. The appendix contains all information about hardware requirements and sensor connections (Images).

After connecting the pressure sensors, the following nodes are placed:

The PHIDGET22 node communicates with the Phidget Interface Kit. It measures voltages from the sensors and converts them into pressures because of the two calibration parameters (the user has to calibrate his sensors). This node has another parameter, n_sensors, the number of pressure sensors in your experiment.

The BAR node displays all pressure measurements on the same figure.

Calibration:

  • Apply known pressures (at least 4) and measure sensor voltages with the Phidget control panel.
  • Plot the voltage as a function of the forces applied. You can choose the unit of your choice.
  • Find the linear equation (y=ax+b) between the voltage measured and the pressure applied on the sensor.
  • A and B are the calibration parameters that convert voltage into pressure.

To update the measurements with time, you can add the LOOP node to create a loop. (Refer to the LOOP node documentation for the loop settings).