XIAOでMCP9808(温度センサ)を使用する(CircuitPython版)
2020/7/2
CPY XIAO MCP9808
CPY XIAO MCP9808
概要
XIAOで以下のMCP9808(温度センサ)を使用する(CircuitPython版)。 CircuitPythonのインストールについては「XIAOにCircuitPythonをインストールする」を参照のこと。 (ホストPCとしてはubuntuを想定している)
Adafruit MCP9808 Precision I2C Temperature Sensor Guide
接続
以下の接続でボードを接続する:
XIAO | MCP9808 |
---|---|
3V3 | Vdd |
GND | GND |
SDA(D4) | SDA |
SCL(D5) | SCL |
The default I2C address is 0x18
外部ライブラリのインストール方法
adafruitのアーカイブから以下のものを
CIRCUITPY/libにコピーする:
adafruit_mcp9808.mpy
adafruit_bus_device(ディレクトリ)
デモ・プログラム
testmcp9808.py
import time
import board
import busio
import adafruit_mcp9808
i2c_bus = busio.I2C(board.SCL, board.SDA)
# To initialise using the default address:
mcp = adafruit_mcp9808.MCP9808(i2c_bus)
# To initialise using a specified address:
# Necessary when, for example, connecting A0 to VDD to make address=0x19
# mcp = adafruit_mcp9808.MCP9808(i2c_bus, address=0x19)
while True:
tempC = mcp.temperature
tempF = tempC * 9 / 5 + 32
print("Temperature: {} C {} F ".format(tempC, tempF))
time.sleep(2)
出力例
picocom /dev/ttyACM0 -b115200
...
<省略>
...
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 5.3.0 on 2020-04-29; Seeeduino XIAO with samd21g18
>>> import testmcp9808
Temperature: 31.5 C 88.7 F
Temperature: 31.4375 C 88.5875 F
Temperature: 31.5 C 88.7 F
Temperature: 31.5 C 88.7 F
Temperature: 31.5 C 88.7 F
Temperature: 31.5625 C 88.8125 F
Temperature: 31.5 C 88.7 F
...
...
参考情報
Seeeduino XIAO Get Started By Nanase
コインサイズ Arduino互換機 Seeeduino XIAO を使ってみた
以上
| 固定リンク
「linux」カテゴリの記事
- platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法(2021.03.10)
- micro:bit Yotta開発ツール(linux版)(2021.01.09)
- PlatformIOをRaspberryPi4で動かしてみる(実験)(2020.10.20)
- headless RaspberryPiインストール方法(v2)(2020.10.20)
- wio-terminalのファームウェア・アップデートについて(linux版)(2020.10.15)
「CircuitPython」カテゴリの記事
- MicroPython/CircuitPython Performance Test(2021.02.07)
- PicoボードにMicropython/CircuitPythonをインストールする(2021.02.03)
- XIAOでMPL3115A2(気圧・高度・気温センサ)を使用する(CircuitPython版)(2020.07.02)
- XIAOでMCP9808(温度センサ)を使用する(CircuitPython版)(2020.07.02)
- XIAOにCircuitPythonをインストールする(2020.06.09)
この記事へのコメントは終了しました。
コメント