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

Thread: Trouble with SCL2 and SDA2 IC2 with 4.1

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    4

    Trouble with SCL2 and SDA2 IC2 with 4.1

    Hello!
    Recently, I have been trying to get data off a BMP388 using pins 24 and 25 (SCL2 and SDA2). I cannot get anything to work. Here is the code I have been using. I really need help.

    Code:
    #include <Wire.h>
    #include <SPI.h>
    #include <Adafruit_Sensor.h>
    #include "Adafruit_BMP3XX.h"
    #include "WireIMXRT.h"
    
    #define BMP_SCK 24
    #define BMP_MISO 12
    #define BMP_MOSI 25
    #define BMP_CS 10
    
    #define Wire Wire2
    #define SEALEVELPRESSURE_HPA (1013.25)
    
    Adafruit_BMP3XX bmp;
    
    void setup() { 
      Wire2.begin();
      Serial.begin(115200);
      while (!Serial);
      Serial.println("Adafruit BMP388 / BMP390 test");
    
      if (!bmp.begin_I2C(&Wire2)){   // hardware I2C mode, can pass in address & alt Wire
      //if (! bmp.begin_SPI(BMP_CS)) {  // hardware SPI mode  
      //if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  // software SPI mode
        Serial.println("Could not find a valid BMP3 sensor, check wiring!");
        while (1);
      }
    
      // Set up oversampling and filter initialization
      bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
      bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
      bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
      bmp.setOutputDataRate(BMP3_ODR_50_HZ);
    }
    
    void loop() {
      if (! bmp.performReading()) {
        Serial.println("Failed to perform reading :(");
        return;
      }
      Serial.print("Temperature = ");
      Serial.print(bmp.temperature);
      Serial.println(" *C");
    
      Serial.print("Pressure = ");
      Serial.print(bmp.pressure / 100.0);
      Serial.println(" hPa");
    
      Serial.print("Approx. Altitude = ");
      Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");
    
      Serial.println();
      delay(2000);
    }
    Last edited by defragster; 08-09-2022 at 03:37 AM. Reason: Added $ CODE markers for readability

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,358
    If all instances of Wire have been changed to Wire2 this could be removed: #define Wire Wire2

    Has this been tested to work on Wire with the appropriate changes?
    > proper pullups and wiring?

    Some i2c Devices start slower and some delay can help before activating them.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,787
    Looks like this should work. Adafruit's library is designed to work with any I2C port, so you shouldn't need to use "#define Wire Wire2" or edit the library to change "Wire" to "Wire2", as is needed with older libraries that are designed for only the default Wire port.

    My guess is you may have a mistake or misunderstanding in the wiring. Maybe we could help more if you show photos of how you connected the hardware to Teensy?

  4. #4
    Junior Member
    Join Date
    Aug 2022
    Posts
    4
    Yeah, everything works when I have the wires connected to SCL and SDA (pins 19 and 18).

  5. #5
    According to the header file:
    Code:
     bool begin_I2C(uint8_t addr = BMP3XX_DEFAULT_ADDRESS,
                     TwoWire *theWire = &Wire);
    I would try this:
    Code:
    bmp.begin_I2C(BMP3XX_DEFAULT_ADDRESS, &Wire2);

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,787
    Quote Originally Posted by LionA View Post
    Yeah, everything works when I have the wires connected to SCL and SDA (pins 19 and 18).
    I'm assuming you're editing this line when you connect the wires to pins 18 and 19?

    Code:
      if (!bmp.begin_I2C(&Wire2)){   // hardware I2C mode, can pass in address & alt Wire
    But I can't see your screen. Maybe you're editing it to "bmp.begin_I2C(&Wire)" or maybe "bmp.begin_I2C()"? Sometimes small details matter. And I still can't see how you're connecting the wires to pins 24 & 25, though hearing the hardware works with pins 18 & 19 is a good sign. Still, very difficult to help like this, basically blind guessing, but trying anyway.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,358
    Quote Originally Posted by MarkzP View Post
    According to the header file:
    Code:
     bool begin_I2C(uint8_t addr = BMP3XX_DEFAULT_ADDRESS,
                     TwoWire *theWire = &Wire);
    I would try this:
    Code:
    bmp.begin_I2C(BMP3XX_DEFAULT_ADDRESS, &Wire2);
    That makes sense. I saw note for passing address, but didn't look into the prototype for expected ordering of the values.

  8. #8
    Junior Member
    Join Date
    Aug 2022
    Posts
    4
    MarkzP the savior. Thank you guys so much for all of your help!!!!

  9. #9
    Junior Member
    Join Date
    Aug 2022
    Posts
    4
    MarkzP the savior. Thank you guys so much for all of your help!!!!

Posting Permissions

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