2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MicroPythonでADT7410からデータを取得する

Posted at

はじめに

MicroPythonでADT7410から温度データを取得してみたいと思います。

環境

・ マイクロコントローラー : ESP-WROOM-32
ESP32.jpeg
・ ファームウェア : MicroPython1.3
MicroPython.jpg
・ センサー : ADT7410(温度センサー)
ADT7410.jpg

ADT7410用ライブラリ

以下がADT7410のライブラリになります。

ADTLib.py
from machine import I2C, Pin
p21 = Pin(21, Pin.IN, Pin.PULL_UP)
p22 = Pin(22, Pin.IN, Pin.PULL_UP)

class ADT7410:
    def __init__(self):
        self.i2c = I2C(scl = Pin(22), sda = Pin(21), freq = 10000)

    def getTemperature(self):
        data = self.i2c.readfrom_mem(0x48, 0x00, 2)
        temp = (data[0] << 8 | data[1]) >> 3
        if(temp >= 4096):
            temp -= 8192
        value = temp * 0.0625
        return value

    def temperature(self):
        temp = self.getValue()
        return temp

ADT7410からデータを取得

ADT7410用のライブラリを用いて実際にデータを取得します。

ADT.py
from time import sleep
import ADTLib

while True:
    adt = ADTLib.ADT7410()
    temp = adt.getTemperature()
    print("TEMPERATURE : ", temp)
    sleep(3)

実行結果

TEMPERATURE :  21.1875                                                                                                                                
TEMPERATURE :  24.375                                                                                                                                 
TEMPERATURE :  25.9375                                                                                                                                
TEMPERATURE :  26.8125                                                                                                                                
TEMPERATURE :  27.3125                                                                                                                                
TEMPERATURE :  27.6875                                                                                                                                
TEMPERATURE :  27.9375                                                                                                                                
TEMPERATURE :  28.125                                                                                                                                 
TEMPERATURE :  28.1875                                                                                                                                
TEMPERATURE :  28.3125                                                                                                                                
TEMPERATURE :  28.375                                                                                                                                 
TEMPERATURE :  28.4375                                                                                                                                                                                                                                                               
TEMPERATURE :  27.8125                                                                                                                                
TEMPERATURE :  26.875                                                                                                                                 
TEMPERATURE :  26.125                                                                                                                                 
TEMPERATURE :  25.625                                                                                                                                 
TEMPERATURE :  25.125                                                                                                                                 
TEMPERATURE :  24.75                                                                                                                                  
TEMPERATURE :  24.375                                                                                                                                 
TEMPERATURE :  24.0                                                                                                                                   
TEMPERATURE :  23.75                                                                                                                                  
TEMPERATURE :  23.5                                                                                                                                   
TEMPERATURE :  23.25                                                                                                                                  
TEMPERATURE :  23.0                                                                                                                                   
TEMPERATURE :  22.8125                                                                                                                                
TEMPERATURE :  22.625                                                                                                                                 
TEMPERATURE :  22.5                                                                                                                                   
TEMPERATURE :  22.375                                                                                                                                 
TEMPERATURE :  22.25                                                                                                                                  
TEMPERATURE :  22.0625 

おわりに

今回はMicroPythonでADT7410からデータを取得しました。
今後は使ったセンサーのライブラリをまとめていくつもりです。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?