In this tutorial we show you how to get raw sensor data from the Adafruit BNO055 9-axis sensor. We are using an Arduino Nano, since it allows for neat, compact builds on a breadboard. The sensor can provide acceleration along x,y and z axis, rotational velocities around x, y and z axis, as well as the strength of the earth’s magnetic vector along the sensor’s x, y, and z axis. The sensor can do a lot more than this, but to get things started, we will show you how to get these raw sensor readings from the device.
The video shows you how to connect the sensor, and below we include the code developed in the video. We strongly suggest you type the code in yourself, as you follow along with the video. You will never learn how to develop projects on your own, if you just copy and paste my code.
The code below is for demo purposes only, and should not be used in any real applications. It just demonstrates how to work with this sensor in benchtop presentations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BNO055.h> #include <utility/imumaths.h> #define BNO055_SAMPLERATE_DELAY_MS (100) Adafruit_BNO055 myIMU = Adafruit_BNO055(); void setup() { // put your setup code here, to run once: Serial.begin(115200); myIMU.begin(); delay(1000); int8_t temp=myIMU.getTemp(); myIMU.setExtCrystalUse(true); } void loop() { // put your main code here, to run repeatedly: imu::Vector<3> acc =myIMU.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER); imu::Vector<3> gyro =myIMU.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE); imu::Vector<3> mag =myIMU.getVector(Adafruit_BNO055::VECTOR_MAGNETOMETER); Serial.print(acc.x()); Serial.print(","); Serial.print(acc.y()); Serial.print(","); Serial.print(acc.z()); Serial.print(","); Serial.print(gyro.x()); Serial.print(","); Serial.print(gyro.y()); Serial.print(","); Serial.print(gyro.z()); Serial.print(","); Serial.print(mag.x()); Serial.print(","); Serial.print(mag.y()); Serial.print(","); Serial.println(mag.z()); delay(BNO055_SAMPLERATE_DELAY_MS); } |