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 1 year has passed since last update.

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

Posted at

Outline

BNO080 をI2C接続をして、加速度を出力する。

Hardware setup

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

ディレクトリ構成

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

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

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

参考

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?