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 1 year has passed since last update.

1時間で作るM5Stackと防水温度センサ(DS18B20)を使った水温計

Posted at

はじめに

メダカを育てている水槽の水温を測りたいと思います

image.png

完成品

こんな感じに完成しました!
1時間

DSC_1387.JPG

材料

M5Stack Basic

DS18B20が使われた防水温度センサ

防水温度センサの改造

Seeedからそのまま使えるものも販売されているのですが、配送に時間が掛かるなどもあるので、自分で改造して作ることにします。

こちらの記事でも改造した内容があるので参考になります。

購入した防水温度センサは、電線が出ているだけなので、ここをGroveコネクタに接続します。
そして、その間でプルアップ抵抗を挟みます。

DSC_1385.JPG

完成!

DSC_1386.JPG

プログラミング

コーディングしても良かったのですが、見つけました!
DS18B20用のカスタムブロック!これで、UIFlowが使えるので、開発環境を整えたりする手間も省けます。

カスタムブロックを初めて使ったので、そこはちょっと調べましたが、ロード自体はそんなに難しくなく、ブロックも分かりやすかったので、そのまま使えました。

Blockyだとこんな感じ。

image.png

Pythonだとこんな感じ。

from m5stack import *
from m5ui import *
from uiflow import *
import time

setScreenColor(0x222222)

labelTemp = M5TextBox(104, 99, "Temp", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0)

from machine import Pin
import _onewire

def init(pin):
  Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)

def convert(pin):
  _onewire.reset(Pin(pin))
  _onewire.writebyte(Pin(pin), 0xcc)
  _onewire.writebyte(Pin(pin), 0x44)

def read(pin):
  _onewire.reset(Pin(pin))
  _onewire.writebyte(Pin(pin), 0xcc)
  _onewire.writebyte(Pin(pin), 0xbe)
  tlo = _onewire.readbyte(Pin(pin))
  thi = _onewire.readbyte(Pin(pin))
  _onewire.reset(Pin(pin))
  temp = tlo + thi * 256
  if temp > 32767:
    temp = temp - 65536
  temp = temp * 0.0625
  return(temp)

init(21)

while True:
  convert(21)
  labelTemp.setText(str("%.2f"%((read(21)))))
  wait_ms(100)
  wait_ms(2)

完成品

最初にも紹介しましたがこんな感じで完成しました!

DSC_1387.JPG

まとめ

作ると決めて、約1時間ぐらい。材料が手元にあったので、ある程度サクサク出来ましたが、こんなのがたった1時間で作れるのは、M5Stackのおかげです。
あとは、防水温度センサですが、普通に環境温度も取れるし、土壌に差しても使えると思うし、なんだかんだでちょっと使い勝手が良いのかもと思います。

おまけ

ここまでやって最後に、Atom S3で動かしたかったのですが、ATOM S3 は UIFLOW2になるので、カスタムブロックが使えるのかがよく分からず。まぁ、とりあえずは動いたので、そちらはまた気が向いたら~

あとは、このブログ自体は約30分で書き上げました。実際に作ってる時間より長くは掛けたくなかったので良かったです(笑)

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?