XIAOでMPL3115A2(気圧・高度・気温センサ)を使用する(Arduino版)
2020/7/2
PlatformIO cli XIAO MPL115A2
PlatformIO cli XIAO MPL115A2
概要
XIAOで以下のMPL3115A2(気圧・高度・気温センサ)を使用する(Arduino版)。 開発ツールのインストールについては開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)を参照のこと。 (ホストPCとしてはubuntuを想定している)
MPL115A2 - I2C Barometric Pressure/Temperature Sensor
接続
以下の接続でボードを接続する:
XIAO | MPL3115A2 |
---|---|
3V3 | Vin |
GND | GND |
SDA(D4) | SDA |
SCL(D5) | SCL |
The default I2C address is 0x60
外部ライブラリのインストール方法
# 外部ライブラリを検索する
# (ここでは例として「MPL3115A2」を検索する)
「platformio lib MPL3115A2」のキーワードでwebで検索する。
「#796 Adafruit MPL3115A2 Library」が見つかるので、これをインストールする。名前と番号のどちらかでインストールできるが名前のほうは同じ名前で異なるライブラリが登録されている可能性があるので番号でインストールする:
pio lib install 796
#実際にコンパイルがエラーになったので、
#以下のように直接ライブラリのソースをダウンロードする:
cd src
wget https://raw.githubusercontent.com/adafruit/Adafruit_MPL3115A2_Library/master/Adafruit_MPL3115A2.cpp
wget https://raw.githubusercontent.com/adafruit/Adafruit_MPL3115A2_Library/master/Adafruit_MPL3115A2.h
デモ・プログラム
src/testmpl3115a2.ino
/**************************************************************************/
/*!
@file Adafruit_MPL3115A2.cpp
@author K.Townsend (Adafruit Industries)
@license BSD (see license.txt)
Example for the MPL3115A2 barometric pressure sensor
This is a library for the Adafruit MPL3115A2 breakout
----> https://www.adafruit.com/products/1893
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
// Power by connecting Vin to 3-5V, GND to GND
// Uses I2C - connect SCL to the SCL pin, SDA to SDA pin
// See the Wire tutorial for pinouts for each Arduino
// http://arduino.cc/en/reference/wire
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
void setup() {
//Serial.begin(9600);
Serial.begin(115200);
Serial.println("Adafruit_MPL3115A2 test!");
}
void loop() {
if (! baro.begin()) {
Serial.println("Couldnt find sensor");
return;
}
float pascals = baro.getPressure();
// Our weather page presents pressure in Inches (Hg)
// Use http://www.onlineconversion.com/pressure.htm for other units
//Serial.print(pascals/3377); Serial.println(" Inches (Hg)");
Serial.print(pascals/100); Serial.println(" hPa");
float altm = baro.getAltitude();
Serial.print(altm); Serial.println(" meters");
float tempC = baro.getTemperature();
Serial.print(tempC); Serial.println("*C");
Serial.println("");
delay(250);
}
出力例
picocom /dev/ttyACM0 -b115200
...
<省略>
...
1002.59 hPa
89.19 meters
31.00*C
1002.59 hPa
89.25 meters
31.00*C
1002.64 hPa
88.87 meters
31.00*C
1002.69 hPa
88.94 meters
31.00*C
1002.64 hPa
88.75 meters
31.00*C
1002.61 hPa
88.81 meters
31.00*C
...
参考情報
Seeeduino XIAO Get Started By Nanase
コインサイズ Arduino互換機 Seeeduino XIAO を使ってみた
以上
| 固定リンク
「PlatformIO」カテゴリの記事
- NuEVI/NuRADのビルド(2022.08.18)
- Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする(2022.02.03)
- uncannyeyesスケッチをplatformioでビルドする(2022.01.31)
- LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする(2022.01.30)
- Wio-Terminal/M5Core2のWiFiAnallyzer(2022.01.24)
「Arduino」カテゴリの記事
- platformioのために新しいユーザーを設定する(2022.02.06)
- MAKER_PI_RP2040でI2Cを使う(Arduino編)(2022.01.09)
- M5Stamp-PICO Arduino Install(2021.12.12)
- M5Stamp-C3 Arduino Install(2021.12.12)
- Arduino-CLIのインストール(2021.05.19)
「XIAO」カテゴリの記事
- PlatformIOとArduino(本家)ツールの差分(2020.10.18)
- XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版)(2020.10.17)
- XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)(2020.10.16)
- XIAO/M5AtomでOLED128x128(I2C)を制御する((XIAO/Arduino版、M5Atom/Arduino版)(2020.10.15)
- XIAO/M5AtomでLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)(2020.10.14)
この記事へのコメントは終了しました。
コメント