r/ArduinoHelp • • 1d ago

2 sensors on the same bus

I am working of an iot project for my diploma I have a max30102 and an mpu6050 Al says I can connect them on the same I2C bus and the code will be simpler but I am a beginner at coding and this project is already haunting my nights enough so any advice from professionals will coding actually be simpler and any tips on how the code will look like and frankly I don't trust AI nor do i want to fully rely on it for code

My max is connected the SDA and SCL of the esp but my mpu is connect to 2 and 15

Any advice on this will be very helpful

1 Upvotes

8 comments sorted by

2

u/gbatx 1d ago

You can have multiple devices on a single i2c bus, they just each need unique addresses. Have you read the i2c specification docs?

1

u/moonrose_07 1d ago

No i bought the heartrate of of ali express and the maual was in picture that weren't readable and the mpu6050 of of temu and I couldn't find the manual😭😭😭

1

u/Anonymity6584 1d ago

Look what ic is on these modules and search thats datasheet, chinese can name these anything they want.

1

u/gm310509 1d ago

Supporting documentation is the most important part when buying stuff like this. It won't come with the module, so if the vendor can't provide readable documentation for their module then you will be flying blind.

If that is the case, swipe left until you find a vendor that does provide some.

For clarity, the sensors you describe (e.g. MPU6050) are named after the Integrated Circuit (IC) that provides the main function of the module.

However, the IC by itself isn't terribly useful in your situation as you have to put it onto something that allows you to hook it up. That is what you are getting when you buy a module. But the module is a custom (often copied) PCB design and may offer different features such as how to set an I2C address or switch it from SPI to I2C if the chip supports both and stuff like that. Without the documentation, you really won't know for sure how to drive it.

1

u/JGhostThing 14h ago

google "mpu 6050 datasheet" and see what you find. You could also search for "mpu 6050 docs"

1

u/duane11583 9h ago

Be clear this is a noob

You can have multiple devices provided they are all with unique addresses.

The word Device is a politically correct name for slave device

Often the device is a memory chip or a sensor chip

You cannot easily have multiple controllers or masters technically you can but many chips cannot really support that  in my nearly 40 years of embedded work I have never seen it happen that is how rare and unusual multiple i2c masters are

Often the controller or master is the arduino or your esp32 or an stm32 

You can convert some (not all) i2c and spi interfaces on a micro controller to operate as a slave or device but this is often very rare in hobby solutions and sometimes the chip does not support both slave and master mode

1

u/InevitablyCyclic 1d ago

I2C is designed to allow lots of devices on the same two wires. The requirements are that 1) they all have unique addresses (most parts have jumper options to select a couple of options. I'd hope the AI would flag this if it was a potential issue, you can always check manually by looking at the driver code). 2) you don't put so much load on the bus it takes too long to transition (not an issue with 2 things unless you have some really long cables) and 3) you don't try to access them at the same time.

That last one may or may not be handled by the drivers/libraries, it depends how they are written but is normally best to handle by structuring your code so that it never happens. Unless you are using interrupts or DMA this is not normally going to be a problem.

Assuming you meet these requirements you can connect them both to the same pins and it will just work.

1

u/creativejoe4 1d ago

Read the datasheets. It will tell you everything you need to know. You can put multiple i2c slaves on the same bus if the datasheets say it will work/supported, they should but I have seen some pretty strange stuff in the past, so you should double check anyway. The datasheet will also have the addresses you need.

I can't give much advice on the code since I have no clue what your doing with it. But the code will be pretty easy so don't worry about that, you can find a tutorial for whatever you will need, just copy and paste, then tweak it. You could also just make a detailed document about your project, give a hardware description, add requirements and acceptance criteria and tell AI to make the code for you and to explain what it did and how it works, connect your hardware, and let the AI flash and debug the project until you are happy with it.