Unable to run two I2C Devices at the same time

Hey there
So I'm having severe trouble getting two I2C devices to run. Namely these are the accelerometer GY-521 which I am running without a library and the A/D transformer GY-MCP3421 which I am running with the library MCP342X.h (GitHub - uChip/MCP342X: Arduino Library for MCP3421, MCP3422, MCP3423, MCP3424, MCP3425, MCP3426, MCP3427, MCP3428 ADCs). I would like to run that without a library as well to get full control over it but I not that good in terms of programming to pull that of.
So I've run the Arduino nano with the GY-521 for some time without any trouble. Running it even without pullup resistors via the 3.3V connection on the nano. On a seperate breadbord with an additional nano I tried out the A/D transformer and it worked pretty good too. Same connection here (gnd, 3.3V, A5 and A4). After that I connected the A/D transformer to the first setup. You can see a picture of my wiring here (Imgur: The magic of the Internet). Ignore the DMS for now as that device is not connected yet.
I encountered two problems here: firstly the A/D Transformer doesnt output a signal other than 0V. in my testsetup ive connected VIN+ and VIN- via a 10k resistor and put 1V over that via a voltage source. That was perfectly readable. But no matter what I do I cant get the A/D Transformer to read anything. On top of that whenever the resistor is between VIN+ and VIN- on the A/D transformer the accelerometer also gives out only zeros.
You can find my sketch here:
#include<Wire.h> //Hinzufügen der Wire.h Library zum kommunizieren mit dem MPU- - Pastebin.com
It consists of the working sketch I had before adding the A/D transformer and the sketch that made the A/D transformer work. deleting the A/D part out and putting the resistor between VIN+ and VIN- also gives me zeros on the accelerometer.

Does anyone have any idea on how to fix this?

sledgar:
Running it without pullup resistors

SCL and SDA must always have a pull-up resistor.

My guess is your voltage drops too low. The GY-521 is a breakout board that includes a voltage regulator that expects a 5V input voltage. If you use just one board the voltage may be just sufficient to get pull to a high state but the second board may drop it just below.

Please give links to your modules (a link to where you bought them).

The MPU-6050 is a 3.3V sensor with a 3.3V I2C bus.
The Arduino Nano is a 5V board with a 5V I2C bus.
The MCP3421 can run at 5V and at 3.3V.
Please tell us how everything is connected and how the Arduino Nano is powered.

When you say that the Arduino Nano with the GY-521 is running without any trouble, then we question that :wink: (that is our job on this forum).
It might work, but not according to the specifications. As soon as you add something to the I2C bus, it might stop working, or as soon as you power the Arduino Nano via VIN instead of via the USB cable, then it might stop working.

I actually made it wotk myself
@Erik_Baas well yes and no. yes, you need a pullup resistor but most breakout bords already have one installed. So do both modules I have.
@Koepel take a look at the imgur link to see how I connected everything. It all works good now. both devices are connected via the 3.3V voltage supply. The only problem there was that both devices had the same i2c adress. putting a signal on the ad0 pin on the accelerometer changed its adress so that I could communicate with both devices individually. So that was the only fix needed here.
The Arduino is powered via a 9V battery. The Nano has a voltage regulator which allows for higher voltages than 5V

the a/d transformer

the accelerometer

First of all, I'm glad you found the problem with the same I2C address :smiley: I had not looked into that, because that does not happen very often.

There is more to say about the I2C bus:

You run the MCP3421 at 3.3V, then it has a 3.3V I2C bus.
The GY-521 module gets 3.3V to its VIN pin. That has to go through a voltage regulator, and will become about 3.2V. The MPU-6050 chip will run at 3.2V and it will have a 3.2V I2C bus.
The Arduino Nano has a 5V I2C bus.
Those different voltage levels connected to the same I2C bus is not nice.
Can you read the first thing and the last thing on this page that I made: How to make a reliable I2C bus · Koepel/How-to-use-the-Arduino-Wire-library Wiki · GitHub.

The GY-521 has 2k2 pullup resistors to 3.3V (in your project 3.2V).
The MCP3221 has 10k pullup resistor to VCC (in your project 3.3V).
The Arduino Nano has internal pullup resistors (let's assume 50k to 5V).
The sink current will be (3.2/2k2) + (3.3/10k) + (5/50k) = 1.9 mA, that is okay.

Nothing will get damaged, but the Arduino Nano wants 3.5V on the I2C bus to recognize it as a high level.

Solution #1: Buy a 3.3V Arduino board and have a 3.3V I2C bus.
Solution #2: Buy a gyro/accelerometer with onboard level shifters and run the MCP3221 at 5V and have a 5V I2C bus.
Solution #3: Buy a seperate I2C level shifter module to create a 3.3V I2C bus.
Solution #4: Ignore all of this, but you may encounter troubles when changing the wiring, or adding a longer wire, or adding another I2C device, or running the Arduino from USB power, and so on.

I don't know what you see on Imgur, but I see a transparent PNG image with a black background.
This is how it is with a white background:

weird. for me the imgur link looks good. but great that you could see it now.

hmm I see the problem with the 5V I2C bus but why would that matter for me when everything works? I mean what exactly would change if I would fix that problem? But interesting nontheless to hear about that

sledgar:
why would that matter for me when everything works?

Because it could stop working when you change the smallest thing, as I wrote. Then you ask on this forum why your I2C bus does not work :wink: Well, now you know.

When you power the GY-521 with 5V to VCC, then the voltage regulator on the module makes 3.3V. That is an improvement (3.2 -> 3.3).
When you upgrade to a Arduino Mega, then it is possible to damage sensors. Because the Arduino Mega has onboard pullup resistors of 10k to 5V. That means that current from the 5V is flowing into the SDA and SCL pins via those resistors. The newer Bosch sensors can not deal with that on their SDA and SCL pins and might get damaged.

So when you connect a 3.3V I2C bus to a 5V I2C bus, then I see trouble everywhere. I have not even mentioned everything !

Well but it does work without any problem right now. It was simply the address problem.
Problem is that I have very very limited space in terms of devices that only the nano fits into. I dont have place for other devices. If I would have too high voltages I would aggree that I could potentially damage the modules but too low voltage? What would that do bad apart from simply not working which is it in its current final state.

sledgar:
It was simply the address problem.

Correct.
In my opinion, different I2C voltage levels can not be ignored. If you know about it, and the Nano looks happy, then your project will probably be just fine.

The I2C bus is not fault tolerant, so I prefer not to do things that are outside the specifications.
According to the datasheet, the Arduino Nano needs 3.5V on its SDA and SCL pins to see a high level.
Your MPU-6050 runs at 3.2V and that module has strong pullup resistors to 3.2V. That means that the Nano does not get the 3.5 Volt I2C levels that it wants.

I can not tell how much risk you take. I see problems when you upgrade to a Mega board or when you add another I2C device.
Adding a I2C level shifter will make it better, but most level shifters also weakens the SDA and SCL signal.

The Nano actually needs 0.7 * VCC for SDA and SCL. That means that if you run the Nano at 4.7V, then it only needs 3.29V for SDA and SCL. If you then also power the GY-521 with 5V to let the MPU-6050 run at 3.3V, then everything is within the specifications.
I can go on for days with this :wink:

okay
thank you for the information. I will keep that in mind the next time I work with I2C! For now I guess I will leave it like that. SImply out of the reason I have soldered everything and nothing will get changed on the setup in terms of I2C devices anymore. Its for my bachelors degree or rather my final exam and I have added everything I need. So there is no need to upgrade the board.
Nontheless this is something I will keep in mind for the next time.

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