在Python和C中Steinhart-Hart和Beta热敏电阻温度模型。实现和实用程序
thermistor-utils的Python项目详细描述
热敏电阻实用程序
基于python的库实现热敏电阻值转换的模型 从温度到电阻,反之亦然。在
斯坦哈特——哈特模型
实现精度
如何使用
# import the Steinhart--Hart and or the Beta converterfromthermistor_utilsimportSH_converter
从a、B和C系数创建转换器:
^{pr2}$如果它们不可用,转换器可以从 三个均匀分布的温度和电阻读数。在
根据温度/分辨率读数创建转换器:
readings=((0,27445),(25,10000),(50,4160),)conv=SH_converter.from_points(readings)
以适合后续使用的形式打印系数 python和C:
print(repr(conv))# SH_converter(0.0008402250578523375, 0.00025963477647737156, 1.5674403473853433e-07, 0, 50)print(conv.to_cstr())# {0.0008402250578523375, 0.00025963477647737156, 1.5674403473853433e-07, 0, 50}# compact but less precise representation# (inverse of coefficients and no temperature range)print(conv.to_cstr(compact=True,with_temps=False))# {1./1190, 1./3852, 1./6379828}
使用C中的参考实现(示例1.C):
#include<stdio.h>#include<thermistor_utils.h>intmain(void){structsh_scoefficients={0.0008402250578523375,0.00025963477647737156,1.5674403473853433e-07};// 25C to Ohm and 10k Ohm to CelsiusdoubleR_at_25=sh_resistance(coefficients,25),T_at_10000=sh_temperature(coefficients,10000);printf("25 Celsius -> %.0f Ohms\n",R_at_25);printf("10k Ohms -> %.0f Celsius\n",T_at_10000);}
要从examples目录编译和运行:
$ mkdir -p ../bin $ gcc -o ../bin/example-1 \ -I../src/include \ ../src/sh_converter.c \ -lm \ example-1.c $ ../bin/example-1 25 Celsius -> 10000 Ohms 10k Ohms -> 25 Celsius
贝塔模型
实现精度
如何使用
# import the Steinhart--Hart and or the Beta converterfromthermistor_utilsimportBeta_converter
从beta值创建转换器:
beta,R0,T0=(3380,10000,25)conv=Beta_converter(beta,R0,T0)
以适合以后在中使用的形式打印beta值 python和C:
print(repr(conv))# Beta_converter(3380, 10000, 25)print(conv.to_cstr())# {3380, 10000, 25}
使用C中的参考实现(示例2.C):
#include<stdio.h>#include<thermistor_utils.h>intmain(void){structbeta_sbpar={3380,10000,25};// 25C to Ohm and 10k Ohm to CelsiusdoubleR_at_25=beta_resistance(bpar,25),T_at_10000=beta_temperature(bpar,10000);printf("25 Celsius -> %.0f Ohms\n",R_at_25);printf("10k Ohms -> %.0f Celsius\n",T_at_10000);}
要从examples目录编译和运行:
$ mkdir -p ../bin $ gcc -o ../bin/example-2 \ -I../src/include \ ../src/beta_converter.c \ -lm \ example-2.c $ ../bin/example-2 25 Celsius -> 10000 Ohms 10k Ohms -> 25 Celsius
- 项目
标签: