Teensy 4.0 multiple I2C devices question

Status
Not open for further replies.

FishEatPork

New member
Hi all.
I'm working on a project with a Teensy 4.0, BMP280, and BNO055 and am starting my code with some initial checks. I want the code to attempt to connect to the devices and then serial print a message if they are successful or not. I have the code working with the BNO055 but the BMP280 is giving me problems. The BNO055 works as intended and reports depending if it's connected or not but the BNO055 will always report back saying it's connected even if it isn't. If someone could help me diagnose and solve the issue that would be great! Thanks!
Heres my code:
Code:
#include <Wire.h> //libs
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <Adafruit_BMP280.h>
#include <utility/imumaths.h>
#include <SPI.h>
#include <Servo.h>

Adafruit_BMP280 bmp; //Puts BMP280 into I2C communication
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); //gets temp
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); //gets pressure
Adafruit_BNO055 bno = Adafruit_BNO055(55); //defines bno as the BNO055 sensor

int ledred = 14;    // Red LED connected to digital pin 14
int ledblu = 15;    // Blue LED connected to digital pin 15
int ledgrn = 16;    // Green LED connected to digital pin 16

void setup() {
  // put your setup code here, to run once:
  pinMode(ledred, OUTPUT);
  pinMode(ledblu, OUTPUT);
  pinMode(ledgrn, OUTPUT);
  
  Serial.begin(9600); //attempt to establish a serial connection
  
  if(!bno.begin()){ //attempts to establish connection with BNO055 on 0x28
    error("BNO055 FAIL TO CONNECT");
  }else{
    Serial.println("BNO055 SUCESSFULL CONNECTION");
    digitalWrite(ledgrn, HIGH);
  }
  if(!bmp.begin()){ //attempts to establish connection with BMP280 on 0x77
    error("BMP280 FAIL TO CONNECT");
  }else{
    Serial.println("BMP280 SUCESSFULL CONNECTION");
    digitalWrite(ledgrn, HIGH);
  }

}

void loop() {
  // put your main code here, to run repeatedly:

}

int error(String err) {
  Serial.println("ERROR - " + err + " - Mission abort"); //prints the error to serial
  digitalWrite(ledred, HIGH);
  while(1); //stops the program until reset
}
 
As a quick check, try running the Wire library's Scanner example.

Does it correctly detect when the BNO055 is disconnected?
 
Status
Not open for further replies.
Back
Top