Judul : Compass Sensor BNO055
link : Compass Sensor BNO055
Compass Sensor BNO055
Halo Sobat Arduino Indonesia, berbagi hal yang baru lagi nih, berhubung sensor kompas gy 271 dan 273 yang semakin hari semakin kirang bagus datanya dan kadang-kadang beli juga dapetnya yang palsu a.k.a FAKE. maka memutuskan untuk move on dari kompas yang lama, nah kali ini pilihan jatuh pada produk adafruit BNO055, memang sih harganya 10x lipatnya yang versi hmc5883 atau hmc5983 tapi kita test dulu yanh performanya beberapa hari ini.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
Sensor ----------- Arduino
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);
}
Demikianlah Artikel Compass Sensor BNO055
Sekianlah artikel Compass Sensor BNO055 kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Compass Sensor BNO055 dengan alamat link https://arduinolibs.blogspot.com/2017/11/compass-sensor-bno055.html
0 Response to "Compass Sensor BNO055"
Post a Comment