Changing SDA and SCL pins using Wire.h

Hello,
I'm need to use two bmp581 sensors on one arduino nano and need to get data from both sensors, and due to pcb board design can't change the address of sensors. Can i assign sda and scl to another pins using Wire.h? I'm using SparkFun_BMP581_Arduino_Library.h for pressure sensors.

Welcome to the forum

What does the PCB design have to do with the address of the sensors ? If the PCB design cannot be changed then it will be difficult to use alternative pins too

It is possible to change the address of sensor if I connect sdo pin of sensor to ground, instead of vdd, but i can't do it, so I'm searching for a software solution

Why not? That would solve the problem, in just a few seconds.

Because sensor is 2x2mm and all the other components and connections are also in mm scale

That makes no sense.

If you can attach power, ground, SDA and SCL to that sensor, you can certainly change the address. Quite trivial with this board:

I'm using arduino nano

My pcb is not as big as this it's hard to do soldering, and I don't have a separate connection for sdo as on this board

you can't use another pins for Hardware I2C.
What you can try is a library which emulates a Soft I2C.

If I were you - I would correct the PCB.

1 Like

Alternatively, you could use an I2C multiplexer.

#include <Wire.h>
#include "SparkFun_BMP581_Arduino_Library.h"

// Create a new sensor object
BMP581 pressureSensor;

// I2C address selection
uint8_t i2cAddress = BMP581_I2C_ADDRESS_DEFAULT; // 0x47


void setup()
{
    // Start serial
    Serial.begin(115200);
    Serial.println("BMP581 Example1 begin!");

    // Initialize the I2C library
    Wire.begin();

    // Check if sensor is connected and initialize
    // Address is optional (defaults to 0x47)
    while(pressureSensor.beginI2C(i2cAddress) != BMP5_OK)
    {
        // Not connected, inform user
        Serial.println("Error: BMP581 not connected, check wiring and I2C address!");

        // Wait a bit to see if connection is established
        delay(1000);
    }

    Serial.println("BMP581 connected!");
}

void loop()
{
    // Get measurements from the sensor
    bmp5_sensor_data data = {0,0};
    int8_t err = pressureSensor.getSensorData(&data);

    // Check whether data was acquired successfully
    if(err == BMP5_OK)
    {
        // Acquisistion succeeded, print temperature and pressure
        Serial.print("Temperature (C): ");
        Serial.print(data.temperature);
        Serial.print("\t\t");
        Serial.print("Pressure (Pa): ");
        Serial.println(data.pressure);
    }
    else
    {
        // Acquisition failed, most likely a communication error (code -2)
        Serial.print("Error getting data from sensor! Error code: ");
        Serial.println(err);
    }

    // Only print every second
    delay(1000);
}

Ultimately I need to substract pressure readings from sensor1 from sensor2:data1-data2.
I used this code to get data from one sensor, is there a way to store this data and use it when I connect second sensor after disconnecting first one?

How will you do that? (just curious)

I'm asking is there a way to store data in Arduino even after disconnecting it from pc, and then I'll connect another sensor and use that stored data

It is my understanding the Sensor address is changed at the sensor not the processor.

Yes only at sensor

Is the PCB design for the sensor or the main board? If for the sensor, what makes it not able to be changed, even if a trace has to be cut?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.