I'm using a Rapberry Pi 4 Model B with 4 same I2C sensors. I want to get real-time data from them, but my knowledge of I2C is limited. I know that I can connect them, using different buses, but same address, and I was wondering if I could connect them using different addresses also. I know that this is possible with a multiplexer, but I don't know if there is any software approach.
Yes, you can easily do this in software if your hardware provides the ability to change its i2c address. This is typically accomplished through the use of pullup resistors on the hardware which can be connected (or disconnected) by switches, solder bridges, etc. After all,
i2c is a bus - not a point-to-point connection :)
Check your hardware documentation, or you can share your device specs, and we can check if you're unsure on how to do this.
From the URL you provided in your comment, I found this:
The sensor has 32 modifiable I2C addresses, ...
Therefore : Yes, you can put all 4 of your sensors on the same i2c bus.
Correction : All GPIO have pullups, BUT all but a very few (maybe 2?) of these pullups are only enabled in software. If you will make reference to this commonly-used RPi Pinout reference, then click on GPIO2, you will find this explanatory note:
SDA includes a fixed, 1.8 kΩ pull-up to 3.3v, which means this pin is not suitable for use as a general purpose IO where no pull-up resistor is desired.
GPIO2 and GPIO3 are the default i2c bus on RPi4B, aka
i2c1. You will need to enable this bus before using it. It may be enabled using either the
raspi-config utility, or from adding a line to the file
In closing: I've gone a bit beyond your original question now, and so any follow-on questions on this topic should probably be submitted as a new question. Hope this helped.