Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 4.0 multiple I2C devices question

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    2

    Teensy 4.0 multiple I2C devices question

    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
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,115
    As a quick check, try running the Wire library's Scanner example.

    Does it correctly detect when the BNO055 is disconnected?

  3. #3
    Junior Member
    Join Date
    May 2020
    Posts
    2
    Quote Originally Posted by PaulStoffregen View Post
    As a quick check, try running the Wire library's Scanner example.

    Does it correctly detect when the BNO055 is disconnected?
    Yup.
    BNO055 on 0x28
    BMP280 on 0x77

    With the scanner I can unplug and plug back in the sensors and they are detected perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •