0
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.

Nicla Sense MEプラスArduino IDEでセンサ・インターフェーシング

Posted at

 前回、Arduino.ccからNicla Sense MEのライブラリをダウンロードしました。現時点で、古いです。gasとか、実際のボードに入っているセンサIDとはすでに異なっています。BLEで利用したセンサデータは問題ありませんでした。
 新しいライブラリを取得します。
   https://github.com/arduino-libraries/Arduino_BHY2
C:\Users\ユーザ名\Documents\Arduino\librariesにコピーします。フォルダ名はArduino_BHY2です。古いのは、別のドライブに移動させておきます。
(参考URL)https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BME688-Nicla-Sense-me-how-to-access-the-data/m-p/46319

サンプルを動かす

  C:\Users\ユーザ名\Documents\Arduino\libraries\Arduino_BHY2\examples\Standalone
に入っているStandalone.inoをダブルクリックし、Arduino IDEを立ち上げ、コンパイルしてボードに書き込みます。
 次の値を読み出しています。右側のデータはセンサIDです。
  C:\Users\yoshi\Documents\Arduino\libraries\Arduino_BHY2\src\sensors
のSensorID.hに書かれています。数値表現は、マニュアル
  https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bhi260ap-ds000.pdf
のTable88に掲載されています。

  • Acceleration SENSOR_ID_ACC
  • Gyroscope SENSOR_ID_GYRO
  • Temperature SENSOR_ID_TEMP
  • Gas SENSOR_ID_GAS

2021-10-14 (6).png

直接読めるセンサと計算結果のデータ

 温度、湿度、気圧、ガス、加速度、磁気、ジャイロは、直接センサのデータを読み出します。
 IMUのデータから計算したオイラー角、クオータニオンは、計算値を読み出します。

# include "Arduino.h"
# include "Arduino_BHY2.h"

Sensor  temp(SENSOR_ID_TEMP);
SensorOrientation   ori(SENSOR_ID_ORI);
Sensor   hum(SENSOR_ID_HUM);
Sensor   baro(SENSOR_ID_BARO);
SensorXYZ accel(SENSOR_ID_ACC);
SensorXYZ gyro(SENSOR_ID_GYRO);
SensorQuaternion quater(SENSOR_ID_RV);
SensorXYZ magnet(SENSOR_ID_MAG);
Sensor gas(SENSOR_ID_GAS);


void setup(){
  Serial.begin(9600);
  while(!Serial);

  BHY2.begin();
  accel.begin();
  gyro.begin();
  temp.begin();
  gas.begin();
  
  ori.begin();
  hum.begin();
  baro.begin();
  quater.begin();
  magnet.begin();
}

void loop(){
  static auto printTime = millis();
  BHY2.update();

  if (millis() - printTime >= 2000) {
    printTime = millis();
    Serial.println("");
    Serial.println(String("gas ohm? : ") + String(gas.value(), 1));
    Serial.println(String("Temperature: ") + String(temp.value(), 1));
    Serial.println(String("Humidity: ") + String(hum.value(), 1));
    Serial.println(String("Barometer : ") + String(baro.value(), 1));
    Serial.println(String("Acceleration :x,y,z ") + String(accel.x()) + ", " +  String(accel.y()) + ", " + String(accel.z()));
    Serial.println(String("Gyroscope :x,y,z ") + String(gyro.x()) + ", " +  String(gyro.y()) + ", " + String(gyro.z()));
    Serial.println(String("Magnetometer :x,y,z ") + String(magnet.x()) + ", " +  String(magnet.y()) + ", " + String(magnet.z()));
    Serial.println(String("Orientation(Euler):head,pitch,roll ") + String(ori.heading(), 3)+", "+ String(ori.pitch(), 3)+", "+ String(ori.roll(), 3));
    Serial.println(String("Quaternion :x,y,z,w ") + String(quater.x()) + ", " +  String(quater.y()) + ", " + String(quater.z())+ ", "+ String(quater.w()));

//    Serial.println(String("acceleration: ") + accel.toString());
//    Serial.println(String("gyroscope: ") + gyro.toString());
//    Serial.println(String("magnet: ") + magnet.toString());    
  }
}

 実行中の様子です。執筆時点で、Orientation(Euler)、Quaternion などの値は、時間が経過すると0になることがあります。
 湿度はほかの湿度計の表示に比べて低めに出ています。ボードを手で握れば、温度と湿度は上がっていくので、問題なく動作はしているようです。
 GasはCO2の値ではなく、環境ガスの値のようです。別のセンサで測ったCO2の値は約700ppmぐらいでした。

2021-10-14 (5).png

0
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
0
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?