Well you’re not connecting the BME library object Adafruit_BME280 bme with your newly created arduino::MbedI2C Wire1 at all, so those are completely separate objects. With
you would at least have to do
bool status = bme.begin(0x76, &Wire1); // Initialize the temperature sensor
Does the I2C scanner when configured for Wire1 show anyhting?
#include <Arduino.h>
#include <Wire.h>
#define WIRE1_SDA 0
#define WIRE1_SCL 1
arduino::MbedI2C Wire1(WIRE1_SDA, WIRE1_SCL);
void setup()
{
Wire1.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire1.beginTransmission(address);
error = Wire1.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
#define WIRE1_SDA 0
#define WIRE1_SCL 1
arduino::MbedI2C Wire1(WIRE1_SDA, WIRE1_SCL);
void setup() {
// put your setup code here, to run once:
//Wire.begin();
Wire1.begin();
bool status = bme.begin(0x76, &Wire1); // Initialize the temperature sensor
if (!status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
So the begin method should only be called of Wire1. (When it was called at Wire and Wire1, the system hangs)
With this code, my sensor is giving correct values.
But there are 2 I2C channels on RP2040. On my pcb there will be 2 I2C devices connected.
So for one connection I could create the Wire1.
But when I will use the second one. How could I change the SDA and SCL pins of the Wire member?