RaspberryPiとBNO080で加速度を計測する

# Outline
BNO080 をI2C接続をして、加速度を出力する。
<img src=https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/483299/3a3e0a61-d223-5fc1-4c84-b938cd63f6dc.jpeg width=220>

# Hardware setup
* raspberry pi
* [Qwiic - BNO080搭載 VR IMUモジュール](https://www.switch-science.com/products/3840)

| Raspberry-pi | 配線 | BNO080 |
|:-----------|------------:|:------------:|
|01 3.3V        | <-> | VCC |
|03 SDA        | <-> | SDA|
|05 SCL        | <-> | SCL|
|09 GND        | <-> | GND|


<img src=https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/483299/ffde3264-9d1f-262e-86a7-91358d0c6aa2.png width=320>

# ディレクトリ構成
```
home/
├ bno080_accel.py
├ bno080_accel_Quaternion.py  # 接続＆表示テスト
```

# install
```
pip install board
sudo pip3 install adafruit-circuitpython-bno08x
```
check hardwear setting `i2cdetect -y 1`

# run
```
mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-bno08x
```
```
cd ~/IMU_BNO08x/
python3 bno080_accel_Quaternion.py
```

# code
```py:bno080_accel_Quaternion.py
import time
import board
import busio
from adafruit_bno08x import (
    BNO_REPORT_ACCELEROMETER,
    BNO_REPORT_GYROSCOPE,
    BNO_REPORT_MAGNETOMETER,
    BNO_REPORT_ROTATION_VECTOR,
)
from adafruit_bno08x.i2c import BNO08X_I2C

i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
bno = BNO08X_I2C(i2c,address=0x4b)

bno.enable_feature(BNO_REPORT_ACCELEROMETER)
bno.enable_feature(BNO_REPORT_GYROSCOPE)
bno.enable_feature(BNO_REPORT_MAGNETOMETER)
bno.enable_feature(BNO_REPORT_ROTATION_VECTOR)

while True:

    time.sleep(0.1)
    print("Acceleration:")
    accel_x, accel_y, accel_z = bno.acceleration  # pylint:disable=no-member
    print("X: %0.6f  Y: %0.6f Z: %0.6f  m/s^2" % (accel_x, accel_y, accel_z))
    print("")

    print("Gyro:")
    gyro_x, gyro_y, gyro_z = bno.gyro  # pylint:disable=no-member
    print("X: %0.6f  Y: %0.6f Z: %0.6f rads/s" % (gyro_x, gyro_y, gyro_z))
    print("")

    print("Magnetometer:")
    mag_x, mag_y, mag_z = bno.magnetic  # pylint:disable=no-member
    print("X: %0.6f  Y: %0.6f Z: %0.6f uT" % (mag_x, mag_y, mag_z))
    print("")

    print("Rotation Vector Quaternion:")
    quat_i, quat_j, quat_k, quat_real = bno.quaternion  # pylint:disable=no-member
    print(
        "I: %0.6f  J: %0.6f K: %0.6f  Real: %0.6f" % (quat_i, quat_j, quat_k, quat_real)
    )
    print("")


```

# output

```py:bno080_accel_Quaternion.py
Acceleration:
X: -0.988281  Y: 4.984375 Z: 8.304688  m/s^2

Gyro:
X: 0.005859  Y: 0.001953 Z: 0.000000 rads/s

Magnetometer:
X: -18.125000  Y: -72.187500 Z: -15.812500 uT

Rotation Vector Quaternion:
I: 0.244324  J: 0.051941 K: 0.012756  Real: 0.968201

```

# 参考
* [Adafruit_CircuitPython_BNO08x/examples/](https://github.com/adafruit/Adafruit_CircuitPython_BNO08x/tree/main/examples)
* [pip install adafruit-circuitpython-bno08x](https://pypi.org/project/adafruit-circuitpython-bno08x/)
* [CircuitPython](https://github.com/adafruit/circuitpython)
* [Adafruit_CircuitPython_BNO08x Helper library for the Hillcrest Laboratories BNO08x IMUs](https://github.com/adafruit/Adafruit_CircuitPython_BNO08x)
* [Pi-BNO080](https://github.com/fm4dd/pi-bno080)
* [ラズベリーパイでデータロガー！電圧測定してグラフにしてみた](https://misoji-engineer.com/archives/raspberrypi-data-logger.html)
* [SparkFun Qwiic VR IMU with the BNO080](https://github.com/sparkfun/Qwiic_IMU_BNO080)
* [Adafruit 9-DOF Orientation IMU Fusion Breakout - BNO085  Python & CircuitPython](https://learn.adafruit.com/adafruit-9-dof-orientation-imu-fusion-breakout-bno085/python-circuitpython)
* [RaspberryPiでI2Cを使えるように設定【2018年】](https://qiita.com/fujit33/items/763b09a6e71e65519740)
* [Adafruit_CircuitPython_BNO08x](https://github.com/adafruit/Adafruit_CircuitPython_BNO08x)