STM32F732 Arduino I2C 테스트를 참고 해서 9축 IMU센서 BNO055 센서 모듈을 테스트 해보자.
우선 BNO055 센서 라이브러리를 설치 한다
https://github.com/adafruit/Adafruit_BNO055
BNO055 기본 예제
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)
// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
// id, address
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
bno.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" xxx");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" xxx");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" xxx");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
/**************************************************************************/
/*
Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println("WebSerial 3D Firmware"); Serial.println("");
/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
/* Use external crystal for better accuracy */
bno.setExtCrystalUse(true);
/* Display some basic information on this sensor */
displaySensorDetails();
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);
/* The WebSerial 3D Model Viewer expects data as heading, pitch, roll */
Serial.print(F("Orientation: "));
Serial.print(360 - (float)event.orientation.x);
Serial.print(F(", "));
Serial.print((float)event.orientation.y);
Serial.print(F(", "));
Serial.print((float)event.orientation.z);
Serial.println(F(""));
/* The WebSerial 3D Model Viewer also expects data as roll, pitch, heading */
imu::Quaternion quat = bno.getQuat();
Serial.print(F("Quaternion: "));
Serial.print((float)quat.w(), 4);
Serial.print(F(", "));
Serial.print((float)quat.x(), 4);
Serial.print(F(", "));
Serial.print((float)quat.y(), 4);
Serial.print(F(", "));
Serial.print((float)quat.z(), 4);
Serial.println(F(""));
/* Also send calibration data for each sensor. */
uint8_t sys, gyro, accel, mag = 0;
bno.getCalibration(&sys, &gyro, &accel, &mag);
Serial.print(F("Calibration: "));
Serial.print(sys, DEC);
Serial.print(F(", "));
Serial.print(gyro, DEC);
Serial.print(F(", "));
Serial.print(accel, DEC);
Serial.print(F(", "));
Serial.print(mag, DEC);
Serial.println(F(""));
delay(BNO055_SAMPLERATE_DELAY_MS);
}
동작 테스트는 Adafruit 3D Model Viewer로 가능하다.
https://adafruit-3dmodel-viewer.glitch.me/
반응형