I2C Trouble starting two buses QT PY

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
KJRC
 
Posts: 23
Joined: Sun Mar 07, 2021 3:31 am

I2C Trouble starting two buses QT PY

Post by KJRC »

I am attempting to use two I2C buses on a QT PY RP2040 w/ Arduino IDE. I can get one bus to start. However, I cant seem to find the correct command(s) to start both Wire and Wire1 at the same time.

I tested my wiring with adafruit code successfully (I2CScan from the testbed). I just cant get my code to work. Please see below code.


#

Code: Select all

include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>

Adafruit_MPL3115A2 mpl;
Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);
  delay(5000);
  while (!Serial) {
    delay(10); 
  }

  Wire.begin(); 
  delay(1000);            
  Wire1.begin();     
  
  // the MPL is wired to GPIO 24&25. I can see this one.
  if (!mpl.begin()) {
    Serial.println("Could not find sensor mpl. Check wiring.");
    while(1);
  }
  
  //program always tanks here. The MPU breakout is on the STEMMA (GPIO22&23)
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
there is more to the code but it is not relevant as we never get that far...
I get the "Failed to find MPU6050 chip" in the serial monitor.

Thanks for any help
K

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: I2C Trouble starting two buses QT PY

Post by neradoc »

I believe you want to pass &Wire1 to begin(), so that it knows that it must use the other bus.
https://adafruit.github.io/Adafruit_MPU ... 506179144d

Like that:

Code: Select all

mpu.begin(MPU6050_I2CADDR_DEFAULT, &Wire1)

User avatar
KJRC
 
Posts: 23
Joined: Sun Mar 07, 2021 3:31 am

Re: I2C Trouble starting two buses QT PY

Post by KJRC »

Neradcoc,
Thanks much works perfect. Here is what I updated my code to to make it work....


Code: Select all

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>

Adafruit_MPL3115A2 mpl;
Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);
  delay(5000);
  while (!Serial) {
    delay(10); // will pause Zero, Leonardo, etc until serial console opens
  }
  Serial.println("starting Wire");
  Wire.setSDA(24);
  Wire.setSCL(25);
  Wire.begin();
  Serial.println("starting Wire1");
  Wire1.begin();
  Serial.println("Wire Done");


  // 
  if (!mpu.begin(0x68, &Wire1)) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”