ラズパイ5 pythonの仮想環境 ⑫ 気圧センサDPS310
Infineon社のDPS310は、温度と気圧が出力されるMEMSセンサです。最高±0.002 hPa(または±0.02m)の高精度モードをもつので高度を扱う用途に適しています。
●Adafruitのブレークアウト・ボード
STEMMA QT(JST SH 4ピン)コネクタは2か所に装着されていて、どちらにつないでもかまいません。このコネクタを使ってI2Cで制御する場合、特に、ジャンパ線をつなぐなどは不要です。
Adafruit DPS310 Precision Barometric Pressure and Altitude Sensor
●気圧センサDPS310のおもなスペック
- 動作電圧 3.3V(デバイスは1.7~3.6 V)
- 測定範囲 300~1200hPa
- 確度 ±0.06hPa(or ±0.5m)
- 分解能 ±0.002hPa(or ±0.02 m)(high precision mode)
- インターフェース SPI(最大10MHz)、I2C(最大3.4MHz)
- スレーブ・アドレス 0x77。SDOピン(裏面のAddr)の設定で0x76も設定できる
気圧センサを比較します。
型名 | 会社名 | 電源電圧 [V] |
測定範囲 |
絶対確度圧力 [hPa] |
相対確度圧力 [hPa] |
その他の機能 |
BMP280 | Bosch | 1.71~3.6 | 300~1100 | ±1 | ±0.12 | 温度 |
---|---|---|---|---|---|---|
BME280 | Bosch | 1.71~3.6 | 300~1100 | ±1 | ±0.12 | 温度、湿度 |
BMP388 | Bosch | 1.65~3.6 | 300~1250 | ±0.40 | ±0.08 | 温度 |
BMP390 | Bosch | 1.65~3.6 | 300~1250 | ±0.50 | ±0.03 | 温度 |
BME680 | Bosch | 1.71~3.6 | 300~1100 | ±0.6 | ±0.12 | 温度、湿度、汚れ |
BME688 | Bosch | 1.71~3.6 | 300~1100 | ±0.6 | ±0.12 | 温度、湿度、汚れ |
DPS310 | Infineon | 1.7~3.6 | 300~1200 | ±1 | ±0.06 | 温度 |
LPS25HB | STMicroelectronics | 1.7~3.6 | 260~1260 | ±0.2 | ±0.1 | 温度 |
LPS35HW |
STMicroelectronics | 1.7~3.6 | 260~1260 | ±1 | ±0.1 | 温度 |
●環境
- ハードウェア Raspberry Pi 5(4GBモデル)
- OS Raspberry Pi OS (64ビット)、リリース日December 5th 2023
- Windows10 22H2にて、ssh(OpenSSH_9.2p1 Debian-2+deb12u2, OpenSSL 3.0.11 19 Sep 2023)および、VNC Viewerを動作させている
●接続
●ライブラリを用意
yoshi@ras05:~ $ python -m venv envdps
yoshi@ras05:~ $ source envdps/bin/activate
(envdps) yoshi@ras05:~ $ pip list
Package Version
---------- -------
pip 23.0.1
setuptools 66.1.1
(envdps) yoshi@ras05:~ $ pip install smbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting smbus
Using cached smbus-1.1.post2.tar.gz (104 kB)
Preparing metadata (setup.py) ... done
Installing collected packages: smbus
DEPRECATION: smbus is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for smbus ... done
Successfully installed smbus-1.1.post2
(envdps) yoshi@ras05:~ $ pip install DigitalPressureSensor
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting DigitalPressureSensor
Using cached https://www.piwheels.org/simple/digitalpressuresensor/DigitalPressureSensor-1.0.0-py3-none-any.whl (4.5 kB)
Installing collected packages: DigitalPressureSensor
Successfully installed DigitalPressureSensor-1.0.0
(envdps) yoshi@ras05:~ $ pip list
Package Version
--------------------- ---------
DigitalPressureSensor 1.0.0
pip 23.0.1
setuptools 66.1.1
smbus 1.1.post2
サンプルの実行ファイルです。
RaspberryPi_DPS/Examples/TempPressValues_310.py
hPaの単位に変更し、dps310.pyで保存しました。
import DPS dps310 = DPS.DPS() while True: except KeyboardInterrupt: |
実行している様子です。
関数化するほどのではないので、このまま利用します。
●グラフィック・ディスプレイに測定結果を表示
(envdps) yoshi@ras05:~ $ pip install st7789
(envdps) yoshi@ras05:~ $ pip install pillow
(envdps) yoshi@ras05:~ $ pip install numpy
(envdps) yoshi@ras05:~ $ pip install spidev
/home/yoshi/envadc/lib/python3.11/site-packages/ST7789のなかにある__init__.pyを、 /home/yoshi/envdps/lib/python3.11/site-packages/ST7789のなかにある__init__.pyにコピペします。
測定値をグラフィック・ディスプレイに表示するプログラムです。
import time dps310 = DPS.DPS() MESSAGE = "DPS310 Pressure Sensor" disp = ST7789.ST7789( height=240,width=320,rotation=0, disp.begin() while 1: |
実行中の様子です。
●ソース
# 64 times (High Precision) | 1040384 <- Configured
と書かれているので、分解能 ±0.002hPa(or ±0.02 m)で測定しているものと思われます。
python仮想環境 備忘録 仮想環境の作成 python -m venv envtest 有効化 source envtest/bin/activate 無効化 deactivate 初期状態に(いったん deactivate してから) python -m venv --clear envtest
|