Created
May 14, 2021 17:21
-
-
Save patrickatkeylogic/093607024389251e4ec1417fe9f6cefe to your computer and use it in GitHub Desktop.
Working with multiple BNO055 chips on a single I2C line
This file contains hidden or 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
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BNO055.h> | |
#include <utility/imumaths.h> | |
Adafruit_BNO055 bno = Adafruit_BNO055(1, 0x28); | |
Adafruit_BNO055 bno2 = Adafruit_BNO055(2, 0x28); | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println("Starting..."); | |
pinMode(25, OUTPUT); | |
pinMode(26, OUTPUT); | |
digitalWrite(25, LOW); | |
digitalWrite(26, HIGH); | |
if (!bno.begin()) | |
{ | |
Serial.println("BNO055 #1 not detected... Check your wiring or I2C ADDR!"); | |
while (1); | |
} | |
Serial.println("BNO055 number 1"); | |
delay(1000); | |
digitalWrite(25, HIGH); | |
digitalWrite(26, LOW); | |
if (!bno2.begin()) | |
{ | |
Serial.println("BNO055 #2 not detected... Check your wiring or I2C ADDR!"); | |
while (1); | |
} | |
Serial.println("BNO055 number 2"); | |
delay(1000); | |
} | |
void loop() | |
{ | |
// First chip (ADR on pin 25) | |
digitalWrite(25, LOW); | |
digitalWrite(26, HIGH); | |
delay(50); | |
sensors_event_t event; | |
bno.getEvent(&event); | |
printEvent(&event); | |
delay(50); | |
// Second chip (ADR on pin 26) | |
digitalWrite(25, HIGH); | |
digitalWrite(26, LOW); | |
delay(50); | |
sensors_event_t event2; | |
bno2.getEvent(&event2); | |
printEvent(&event2); | |
delay(50); | |
Serial.println(); | |
} | |
void printEvent(sensors_event_t* event) | |
{ | |
Serial.print("Sensor #"); | |
Serial.print(event->sensor_id); | |
Serial.print("\t"); | |
Serial.print("Orientation: "); | |
Serial.print((float)event->orientation.x); | |
Serial.print("\t"); | |
Serial.print((float)event->orientation.y); | |
Serial.print("\t"); | |
Serial.print((float)event->orientation.z); | |
Serial.print("\t\t"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment