Sebenarnya sensor ini gak hanya kompas saja sih, tapi IMU 9DOF, ada acceleronya, gyro, magneto. nah untuk kompas kita pakai yang magnetometer. oke langsung saja sobat Arduino, saya akan berbagi source code bagaimana sensor BNO055 menghasilkan sudutnya.
Nah pertama kita sambung dulu ke arduino, pakai komunikasi i2c ya
Vin 5V
gnd gnd
SDA A4
SCL A5
Setelah di sambung menggunakan kabel jampur langsung coba program berikut ini
//arduino.web.id
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
/* This driver reads raw data from the BNO055
Connections
===========
Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground
History
=======
2015/MAR/03 - First release (KTOWN)
*/
/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055();
float heading;
/**************************************************************************/
/*
Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println("Test Heading"); 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);
bno.setExtCrystalUse(true);
}
void loop(void)
{
// Possible vector values can be:
// - VECTOR_ACCELEROMETER - m/s^2
// - VECTOR_MAGNETOMETER - uT
// - VECTOR_GYROSCOPE - rad/s
// - VECTOR_EULER - degrees
// - VECTOR_LINEARACCEL - m/s^2
// - VECTOR_GRAVITY - m/s^2
imu::Vector<3> vector = bno.getVector(Adafruit_BNO055::VECTOR_MAGNETOMETER);
/* Display the floating point data */
Serial.print("X: ");
Serial.print(vector.x());
Serial.print(" Y: ");
Serial.print(vector.y());
Serial.print(" Z: ");
Serial.print(vector.z());
heading = atan2(vector.y(), vector.x());
if(heading < 0)
heading += 2*PI;
// Convert radians to degrees
heading = heading * 180/M_PI;
Serial.print(" head: ");
Serial.print(heading);
Serial.println("");
delay(BNO055_SAMPLERATE_DELAY_MS);
}
nah silahkan di coba di serial monitor
Mudah bukan, Salam Arduino Indonesia
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
/* This driver reads raw data from the BNO055
Connections
===========
Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground
History
=======
2015/MAR/03 - First release (KTOWN)
*/
/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055();
float heading;
/**************************************************************************/
/*
Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println("Test Heading"); 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);
bno.setExtCrystalUse(true);
}
void loop(void)
{
// Possible vector values can be:
// - VECTOR_ACCELEROMETER - m/s^2
// - VECTOR_MAGNETOMETER - uT
// - VECTOR_GYROSCOPE - rad/s
// - VECTOR_EULER - degrees
// - VECTOR_LINEARACCEL - m/s^2
// - VECTOR_GRAVITY - m/s^2
imu::Vector<3> vector = bno.getVector(Adafruit_BNO055::VECTOR_MAGNETOMETER);
/* Display the floating point data */
Serial.print("X: ");
Serial.print(vector.x());
Serial.print(" Y: ");
Serial.print(vector.y());
Serial.print(" Z: ");
Serial.print(vector.z());
heading = atan2(vector.y(), vector.x());
if(heading < 0)
heading += 2*PI;
// Convert radians to degrees
heading = heading * 180/M_PI;
Serial.print(" head: ");
Serial.print(heading);
Serial.println("");
delay(BNO055_SAMPLERATE_DELAY_MS);
}
Tidak ada komentar:
Posting Komentar