忍者ブログ
[339]  [338]  [337]  [336]  [335]  [334]  [333]  [332]  [329]  [328]  [327
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

LM61CIZ Raspberrypi mpc3208 pythonで温度測定

LM35については、電圧*100なので簡単に温度が測定可能である。
マイナスには対応していないので、LM61CIZを購入してテストして
みた

意外な事にgoogle先生に聞いてもRaspberryPiとLM61のサンプルが
あまり見当たらない

MPC3208を12ビットで読みだして、ポート0にLM35を
ポート1にLM61を接続した
ともにVCCは3.3vで使用

データシートを見ると
 V=(0.01*T)+0.600
温度1度につき0.01vでオフセットが0.6vという式である

 T=(v-0.600)/0.01 で計算できる

結果はLM35に対して+2度ほど温度が高い
データシートを見ると20度で+-2.5度という事で誤差範囲だが
ちとこれでは使えない

サンプルプログラムは以下である

import spidev
import time
import sys
spi= spidev.SpiDev()
spi.open(0,0)

#12ビット精度で読み出し
def  adc_read12(ch):
    r = spi.xfer2([4|2|(ch >> 2), (ch & 3) << 6,0])
    v=((r[1] & 0xF) << 8 ) + r[2]
    return v

#12読み出しデータをボルトに変換
def conv_volts(data,places):
    volts = (data *3.3)/float(4096)
    volts=round(volts,places)
    return volts

#LM35用ボルト温度変換
def conv_temp(volts,places):
    temp =  volts * 100 
    temp  =round(temp,places)
    return temp

#LM61用ボルト温度変換
def conv_temp61(volt,places):
    temp = (float)(volt -0.600)  / 0.01
    temp  =round(temp,places)
    return temp

#実行
while True:
    try:
        d=adc_read12(0)
        print("adc  : {:8} ".format(d))
        v=conv_volts(d,4)
        print("volts: {:8.2f}".format(v))
        t=conv_temp(v,4)
        print("temp : {:8.2f}".format(t))
        d=adc_read12(1)
        print("adc  : {:8} ".format(d))
        v=conv_volts(d,8)
        print("volts: {:8.4f}".format(v))
        t=conv_temp61(v,8)
        print("temp : {:8.2f}".format(t))
        print("------------------------")
        time.sleep(5)
        
    except KeyboardInterrupt:
        break
spi.close()  

拍手

PR
カレンダー
03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]