Aller au contenu

# RESISTANCE_TO_TEMPERATURE

Ce contenu n’est pas encore disponible dans votre langue.

The RESISTANCE_TO_TEMPERATURE node converts resistance to temperature. The resistance should be a reading from a thermistor in Ohms. Params: unit : select Which unit of temperature to return. Returns: out : Scalar The resulting temperature.
Python Code
from typing import Literal
from flojoy import Scalar, flojoy
from numpy import log

@flojoy
def RESISTANCE_TO_TEMPERATURE(
default: Scalar,
unit: Literal["K", "C", "F"] = "K",
nominal_resistance: float = 1e4,
nominal_temperature: float = 298.15,
beta_coefficient: float = 3950,
) -> Scalar:
"""The RESISTANCE_TO_TEMPERATURE node converts resistance to temperature.

The resistance should be a reading from a thermistor in Ohms.

Parameters
----------
unit: select
Which unit of temperature to return.

Returns
-------
Scalar
The resulting temperature.
"""

steinhart = log(default.c / nominal_resistance)  # X = ln(R/Ro)
steinhart /= beta_coefficient  # X / B
steinhart += 1.0 / (nominal_temperature)  # X + (1/To)
kelvin = 1.0 / steinhart  # 1 / X
celsius = kelvin - 273.15
fahren = celsius * 9 / 5 + 32

match unit:
case "K":
c = kelvin
case "C":
c = celsius
case "F":
c = fahren

return Scalar(c=c)


Find this Flojoy Block on GitHub

## Example

In this example, two measurements are extracted from an Arduino and plotted.

Here is a list of nodes to add:

• OPEN_SERIAL
• SINGLE_MEASUREMENT_SERIAL x2
• VECTOR_INDEXING x4
• LINE x2
• RESISTANCE_TO_TEMPERATURE x2
• APPEND x2
• FEEDBACK x2
• LOOP

Connect the nodes as seen in the example. Next set the number of loops to zero with the LOOP node parameters. Connect the 3 serial nodes to the desired serial device in the node parameters.

The SINGLE_MEASUREMENT_SERIAL should be returning two seperate measurements in the form of a Vector. Therefore, the VECTOR_INDEXING nodes should be set to 0 and 1 to extract the first and second measurements respectively (light intensity and temperature (in resistance)).

The RESISTANCE_TO_TEMPERATURE nodes convert the resistance of the thermistor to temperature.

The Arduino code used is: