差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
tempsensor [2023/07/31 10:57]
chengshunkai
tempsensor [2023/08/01 16:39] (当前版本)
chengshunkai
行 242: 行 242:
 1.[[https://​www.honeywell.com/​cn/​zh-cn|honeywell]] (霍尼韦尔国际公司) 1.[[https://​www.honeywell.com/​cn/​zh-cn|honeywell]] (霍尼韦尔国际公司)
  
-2.[[https://​www.te.com/​chn-zh/​home.html|外部链接]] (泰科电子有限公司)+2.[[https://​www.te.com/​chn-zh/​home.html|泰科]] (泰科电子有限公司)
  
-3.[[https://​www.ti.com/​cn/​|外部链接]] (德州仪器公司)+3.[[https://​www.ti.com/​cn/​|TI]] (德州仪器公司)
  
-4.[[https://​www.st.com/​content/​st_com/​zh.html|外部链接]] (意法半导体有限公司)+4.[[https://​www.st.com/​content/​st_com/​zh.html|ST]] (意法半导体有限公司)
  
-5.[[https://​www.omron.com.cn/​|外部链接]] (欧姆龙公司)+5.[[https://​www.omron.com.cn/​|OMRON]] (欧姆龙公司)
  
-6.[[https://​www.panasonic.com/​cn/​|外部链接]] (松下电器产业株式会社)+6.[[https://​www.panasonic.com/​cn/​|Panasonic]] (松下电器产业株式会社)
  
-7.[[ https://​www.amphenol.com/​|外部链接]] (安费诺集团)+7.[[ https://​www.amphenol.com/​|Amphenol]] (安费诺集团)
  
-8.[[https://​www.nxp.com/​|外部链接]] (恩智浦半导体有限公司)+8.[[https://​www.nxp.com/​|NXP]] (恩智浦半导体有限公司)
  
-9.[[https://​www.sensirion.com/​cn/​|外部链接]] (Sensirion公司)+9.[[https://​www.sensirion.com/​cn/​|Sensirion]] (Sensirion公司)
  
-10.[[https://​www.maximintegrated.com/​|外部链接]] (美信集成产品公司)+10.[[https://​www.maximintegrated.com/​|Maxim]] (美信集成产品公司)
  
-11.[[https://​www.analog.com/​cn/​index.html|外部链接]] (安纳洛格设备公司)+11.[[https://​www.analog.com/​cn/​index.html|ANLOK]] (安纳洛格设备公司)
  
-12.[[https://​www.microchip.com/​zh/​|外部链接]] (微芯科技公司)+12.[[https://​www.microchip.com/​zh/​|Microship]] (微芯科技公司)
  
-13.[[https://​www.siemens.com/​cn/​zh/​home.html|外部链接]] (西门子公司)+13.[[https://​www.siemens.com/​cn/​zh/​home.html|Siemens]] (西门子公司)
  
-14.[[https://​www.emerson.com/​cn-zh|外部链接]] (艾默生电气公司)+14.[[https://​www.emerson.com/​cn-zh|Emerson]] (艾默生电气公司)
  
 ### 10. 常用的温度传感器介绍 ### 10. 常用的温度传感器介绍
行 758: 行 758:
         time.sleep(1) ​ # 等待 1 秒,然后进行下一次读数         time.sleep(1) ​ # 等待 1 秒,然后进行下一次读数
  
 +**数字温度传感器TCN75A**
  
 +TCN75AVUA是一种温度传感器芯片其测温物理原理基于热敏电阻原理。
 +
 +在TCN75AVUA芯片中,使用了一种称为负温度系数(NTC)的热敏电阻。
 +
 +NTC热敏电阻的电阻值随温度升高而下降,而在温度下降时电阻值则上升。
 +
 +该芯片中的热敏电阻与温度敏感元件组成一个温度敏感电路。
 +
 +在特定的温度下,电路会产生一个电压,该电压与温度成比例。
 +
 +芯片内部的模拟电路和ADC将该电压转换为相应的数字值,这个数字值就代表测量到的温度。
 +
 +由芯片TCN75A设计了一款数字温度传感器,该传感器使用I2C通信,可直接读取温度。
 +
 +{{ :​20230801163603.jpg?​600 |}}
 +
 +{{ :​20230728165827.jpg?​600 |}}
 +
 +    from machine import I2C,Pin
 +    import math
 +    import time
 +
 +    # I2C 地址
 +    TCN75A = 0x48
 +
 +    #​I2C设备内部寄存器
 +    TA = 0x00#​温度寄存器地址
 +    CONFIG = 0x01#​配置寄存器地址
 +    THYST = 0x02#​温度报警下限地址
 +    TSET = 0x03#​温度报警上限地址
 +
 +    #​常用参数
 +    Temp_9bit = 0x00#​设置温度精度为0.5 C
 +    Temp_10bit = 0x20#​设置温度精度为0.25 C
 +    Temp_11bit = 0x40#​设置温度精度为0.125 C
 +    Temp_12bit = 0x60#​设置温度精度为0.0625 C
 +    Comparator = 0x00#​设置报警输出为比较器模式
 +    Interrupt = 0x02#​设置报警输出为中断模式
 +    Alert_high = 0x04#​设置报警输出为高
 +    Alert_low = 0x00#​设置报警输出为低
 +
 +
 +    code=0
 +    temp=0
 +    #​初始化I2C
 +    i2c = I2C(id=0,​scl=Pin(21),​sda=Pin(20),​freq=50_000)
 +
 +    #​向指定寄存器写入数据
 +    def reg_write(i2c,​ addr, reg, data):
 +        # Construct message
 +        msg = bytearray()
 +        msg.append(data)
 +
 +        i2c.writeto_mem(addr,​ reg, msg)
 +
 +    #​从指定寄存器中读取指定字节的数据
 +    def reg_read(i2c,​ addr, reg, nbytes):
 +
 +        data = i2c.readfrom_mem(addr,​ reg, nbytes)
 +        return data
 +
 +    #​读取总线上挂载的I2C设备并返回其地址
 +    addr_list = i2c.scan()
 +    print(addr_list)
 +
 +    reg_write(i2c,​TCN75A,​TA,​Temp_12bit)#​设置温度精度
 +
 +    while True:
 +        code=reg_read(i2c,​TCN75A,​TA,​ 2)
 +        temp=code[0]+code[1]*0.00390625#​将接收到的数据转换为温度
 +        print("​Temperature = "​+str(temp)+"​ C")
 +        time.sleep(1)