单片机热敏电阻测温

作者

QQ群:852283276
微信:arm80x86
微信公众号:青儿创客基地
B站:主页 https://space.bilibili.com/208826118

参考

matplotlib之散点图
python 对于任意数据和曲线进行拟合并求出函数表达式的三种方案。
numpy.linspace()等差数列函数

方法

首先测得不同温度下对应的电压,这样的通过ADC测出电压就可以反推出温度,首先用python绘图,看看情况,安装matplotlib,会自动安装numpy, cycler, python-dateutil, kiwisolver, pyparsing, matplotlib

# pip uninstall matplotlib
PS C:\dog\program\fj\dcl4\prj\python> pip install matplotlib
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/1a/c0/69e3f695d7384012e90be1e16570c08953baae00fd98094179ef87c7d5a2/matplotlib-3.1.1-cp37-cp37m-win_amd64.whl (9.1MB)
     |████████████████████████████████| 9.1MB 159kB/s
Collecting numpy>=1.11 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/26/26/73ba03b2206371cdef62afebb877e9ba90a1f0dc3d9de22680a3970f5a50/numpy-1.17.0-cp37-cp37m-win_amd64.whl (12.8MB)
     |████████████████████████████████| 12.8MB 285kB/s
Collecting cycler>=0.10 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting python-dateutil>=2.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
     |████████████████████████████████| 235kB 117kB/s
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/c6/ea/e5474014a13ab2dcb5056608e0716c600c3d8a8bcffb10ed55ccd6a42eb0/kiwisolver-1.1.0-cp37-none-win_amd64.whl (57kB)
     |████████████████████████████████| 61kB 231kB/s
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/11/fa/0160cd525c62d7abd076a070ff02b2b94de589f1a9789774f17d7c54058e/pyparsing-2.4.2-py2.py3-none-any.whl (65kB)
     |████████████████████████████████| 71kB 143kB/s
Requirement already satisfied: six in c:\users\qinge\appdata\roaming\python\python37\site-packages (from cycler>=0.10->matplotlib) (1.12.0)
Requirement already satisfied: setuptools in c:\users\qinge\appdata\local\programs\python\python37\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (40.6.2)
Installing collected packages: numpy, cycler, python-dateutil, kiwisolver, pyparsing, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.1.0 matplotlib-3.1.1 numpy-1.17.0 pyparsing-2.4.2 python-dateutil-2.8.0

编写绘图程序,采用多项式拟合,

import matplotlib.pyplot as plt
import numpy as np
 
x = [0.376, 0.397, 0.42 , 0.443, 0.465, #-24 -20
     0.49 , 0.516, 0.543, 0.571, 0.6,   #-19 -15
     0.631, 0.662, 0.695, 0.728, 0.763, #-14 -10
     0.799, 0.836, 0.874, 0.913, 0.953, #-9  -5
     0.994, 1.037, 1.08 , 1.124, 1.17,  #-4   0
     1.216, 1.263, 1.312, 1.361, 1.41,  # 1   5
     1.461, 1.512, 1.564, 1.617, 1.67,  # 6   10
     1.724, 1.778, 1.833, 1.888, 1.943, # 11  15
     1.999, 2.054, 2.11 , 2.166, 2.222, # 16  20
     2.278, 2.334, 2.389, 2.445, 2.5,   # 21  25
     2.555, 2.609, 2.663, 2.717, 2.77,  # 26  30
     2.822, 2.874, 2.926, 2.976, 3.026, # 31  35
     3.076, 3.124, 3.172, 3.219, 3.265, 
     3.31 , 3.355, 3.398, 3.441, 3.483, 
     3.524, 3.564, 3.603, 3.642, 3.679, 
     3.716, 3.752, 3.787, 3.821, 3.854, 
     3.887, 3.918, 3.949, 3.979, 4.008, 
     4.036, 4.064, 4.091, 4.117, 4.142, 
     4.167, 4.191, 4.214, 4.237, 4.259, 
     4.28 , 4.301, 4.321, 4.34 , 4.359]
y = np.arange(-24, 76, 1.0)
f = np.polyfit(x, y, 3)
p = np.poly1d(f)
print('p is :\n', p)
yf=np.polyval(f, x)
plt.figure()
plt.scatter(x, y, c='r')
plt.plot(x, yf)
plt.show()

长这样,几乎就是一条直线,
113
多项式表达式,把这个表达式灌入单片机即可,

PS C:\dog\program\fj\dcl4\prj\python> python .\temperature.py
p is :
        3         2
1.854 x - 12.44 x + 44.69 x - 38.15
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
内包含具体程序,仿真图、论文、焊接过程及芯片资料等详细资料,部分内容如下: 设计的主要内容及技术指标 要求温度控制系统完成以下功能: 1.基本功能 1)具有声光报警功能; 2)使用液晶显示; 3)温度上、下限报警值设定;温度上、下限报警; 4)手动方式设定温度上下限; #include //头文件 #include #include"eeprom52.h" //调用STC89C52单片机的EEPROM控制程序 #include "math.h" #define uchar unsigned char //宏定义 #define uint unsigned int //宏定义 #define LCD1602_dat P0 //LCD1602的数据传输IO口 sbit LCD1602_rs=P2^5;//LCD1602命令数据控制IO sbit LCD1602_rw=P2^6; //LCD1602读写IO控制 sbit LCD1602_e=P2^7; //数据脉冲输入 sbit beep=P2^0; //蜂鸣器IO sbit led_1=P1^5; //超上限指示灯 sbit led_2=P1^6;//超下限指示灯 sbit key_1=P3^5; //设置按键 sbit key_2=P3^6;//加按键 sbit key_3=P3^7;//减按键 sbit TCL2543_EOC = P1^0; //转换结束标志IO口 sbit TCL2543_CLK = P1^1; //I/O时钟输入 sbit TCL2543_ADIN = P1^2; //串行数据输入端 sbit TCL2543_DOUT = P1^3; //串行数据输出端 sbit TCL2543_CS = P1^4; //片选脚IO float zhi; //暂存读取的输入变量 int temp; //读取DS18B20的温度数据 char temp_h,temp_l; //温度上下限制存储变量 uchar state,ms; //系统设置项变量、50ms定时变量 bit s1,beep1; //设置闪烁标志位、报警标志位 void delay(uint T) //系统延时程序 { while(T--); } // 其中 port 为通道: 通道0:port = 0x01 通道1:port = 0x02 通道2:port = 0x04 ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值