Created
May 16, 2017 01:32
-
-
Save ricklentz/e5b780278f9c5b864433d1c1ab1387ef to your computer and use it in GitHub Desktop.
read the BNO055 minicomputer's orientation values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import sys | |
import time | |
from Adafruit_BNO055 import BNO055 | |
# Create and configure the BNO sensor connection. Make sure only ONE of the | |
# below 'bno = ...' lines is uncommented: | |
# Raspberry Pi configuration with serial UART and RST connected to GPIO 18: | |
bno = BNO055.BNO055(serial_port='/dev/ttyAMA0', rst=18) | |
# BeagleBone Black configuration with default I2C connection (SCL=P9_19, SDA=P9_20), | |
# and RST connected to pin P9_12: | |
#bno = BNO055.BNO055(rst='P9_12') | |
# Enable verbose debug logging if -v is passed as a parameter. | |
if len(sys.argv) == 2 and sys.argv[1].lower() == '-v': | |
logging.basicConfig(level=logging.DEBUG) | |
# Initialize the BNO055 and stop if something went wrong. | |
if not bno.begin(): | |
raise RuntimeError('Failed to initialize BNO055! Is the sensor connected?') | |
# Print system status and self test result. | |
status, self_test, error = bno.get_system_status() | |
print('System status: {0}'.format(status)) | |
print('Self test result (0x0F is normal): 0x{0:02X}'.format(self_test)) | |
# Print out an error if system status is in error mode. | |
if status == 0x01: | |
print('System error: {0}'.format(error)) | |
print('See datasheet section 4.3.59 for the meaning.') | |
# Print BNO055 software revision and other diagnostic data. | |
sw, bl, accel, mag, gyro = bno.get_revision() | |
print('Software version: {0}'.format(sw)) | |
print('Bootloader version: {0}'.format(bl)) | |
print('Accelerometer ID: 0x{0:02X}'.format(accel)) | |
print('Magnetometer ID: 0x{0:02X}'.format(mag)) | |
print('Gyroscope ID: 0x{0:02X}\n'.format(gyro)) | |
print('Reading BNO055 data, press Ctrl-C to quit...') | |
while True: | |
# Read the Euler angles for heading, roll, pitch (all in degrees). | |
heading, roll, pitch = bno.read_euler() | |
# Read the calibration status, 0=uncalibrated and 3=fully calibrated. | |
sys, gyro, accel, mag = bno.get_calibration_status() | |
# Print everything out. | |
print('Heading={0:0.2F} Roll={1:0.2F} Pitch={2:0.2F}\tSys_cal={3} Gyro_cal={4} Accel_cal={5} Mag_cal={6}'.format( | |
heading, roll, pitch, sys, gyro, accel, mag)) | |
# Other values you can optionally read: | |
# Orientation as a quaternion: | |
#x,y,z,w = bno.read_quaterion() | |
# Sensor temperature in degrees Celsius: | |
#temp_c = bno.read_temp() | |
# Magnetometer data (in micro-Teslas): | |
#x,y,z = bno.read_magnetometer() | |
# Gyroscope data (in degrees per second): | |
#x,y,z = bno.read_gyroscope() | |
# Accelerometer data (in meters per second squared): | |
#x,y,z = bno.read_accelerometer() | |
# Linear acceleration data (i.e. acceleration from movement, not gravity-- | |
# returned in meters per second squared): | |
#x,y,z = bno.read_linear_acceleration() | |
# Gravity acceleration data (i.e. acceleration just from gravity--returned | |
# in meters per second squared): | |
#x,y,z = bno.read_gravity() | |
# Sleep for a second until the next reading. | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment