I2C problem, help please

Hello. Ich am making small robot. Arduino Mega, 1x MPU6050(Jeff Rolberg library), 2x VL53L0X(adafruit), lition 7.4V 2.5Ah for power all.
Direkt connection: MPU to pins 21,20 , the distance sensors to other SDA and SCL pins. And all sensors get power from the arduino and the arduino from the battery.
And have such problem:
When the all sensors work together in one code , the mpu start slower work and show wrong values and even sometimes just stop measuring.

If they work in different codes work perfect.

May be I make someting wrong with I2C comunication and the program get slower.

Thank you!

This is not clear to me. On Mega, D20 is SDA and D12 is SCL. Can you confirm all 3 sensors are correctly connected to these same 2 pins? I assume they are since your code works as long as only one sensor is being addressed.

Who knows. I didn't really try hacking into your computer and finding the mystery code you're trying to compile. Or drive to your home and peek through the window to see how you connected everything together.
Would you like me to? :smirk:

on my board there are 4 pins with I2C. 20,21 and other two pins with NAME : "SCL" and "SDA".

According to the Arduino documentation, they're connected. So both pins marked SCL are in fact the 'D21' and both pins marked SDA are 'D20'. You can (but don't have to) verify this with a continuity meter.

If you want help with your problem, you'll have to post your code.

Can you give a link to the sensor modules (a link to where you bought them), because those sensors are 3.3V sensors and the Arduino Mega is a 5V board.

The Arduino Mega has onboard 10k pullup resistors to 5V for SDA and SCL. If you connect those directly to the MPU-6050, then its voltage gets pushed towards 5V.

Can you show a photo of the wiring ?

1 Like

The sensor are from Aliexpres - all there are same VL53L0X, i wired them how has the man in the video from Robojax in Youtube.
Vin=> 5V, GND=>GND, SCL,SDA =>SCL, SDA, Xshut to D20. Library from Adafruit.

Alone the code for both VL53L0X work fine. Measuring good.

I am sorry picture couldnt send, they are 50 cables around. And you will see only one mess, but everything is conected good. But without any pullups. directly.

Sind Sie Deutsche?

Have you set different I2C addresses on each VL53L0X module?

The VL53L0X has a default I2C address of 0x29!

You can change it, but only in software. That means you have to wire the SHUTDOWN pin and hold all but one sensor in reset while you reconfigure one sensor at a time

1. According to data sheets the I2C address of VL53L0X is 0x52. You have two sensors of this kind in the system. How have you choosen the I2C address for the other sensor given the following pin diagram (Fig-1) of the sensor.

VL53L0X
Figure-1:

2. What address have you selected for MU6050? Is it 0x68 or 0x69 (with the help of the AD0-pin)?

From Section-3, Page-18 of data sheets: The I2C bus on the VL53L0X has a maximum speed of 400 kbits/s and uses a device address of 0x52.

Would appreciate to know which page(s) of the data sheets contain the procedures of changing the address of VL53L0X by software.

Section 2.8 of the datasheet (page 15):

2.8 Device programming and control
Device physical control interface is I2C, described in Section 3: Control interface.
A software layer (API) is provided to control the device. The API is described in the VL53L0X API User Manual.

The VL53L0X API User Manual:

6.6 I2C device address
User can change the I2C address of the device.
VL53L0X_SetDeviceAddress()

1 Like

Some VL53L0X modules on AliExpress have level shifters for SDA and SCL, some don't. I don't know if there is a module with a level shifter for the XSHUT pin. So I assume that there is not a single VL53L0X module on AliExpress that you may connect to your Arduino Mega.
Most MPU-6050 modules don't have level shifters for SDA and SCL, so you may not connect that module to your Mega board.
I really would like to know how the wiring is. If you, for example, use a flat ribbon cable with SDA next to SCL, then 20 cm cable length might already be too much.

ok, I understand. my sensors are:1 stück VL53L0X Zeit von Flug (ToF) laser Ranging Sensor Breakout 940nm GY VL53L0XV2 Laser Abstand Modul I2C IIC|Integrated Circuits| - AliExpress

and the cable are: 15cm standard jumper wire + 15 cm some 0.2mm2 multicore cable, between soldered, both together next to each other

sensors.ino (9.9 KB)
here is my code

my addresses are 0x31 and 0x33 VL53L0X, 0x68 is MPU

What is the problem with your codes? It is compiled very well in my MEGA.

With my Mega the value of Y get slower in Serial monitor as normal and 10 sec after start to give very wrong haotik numbers and even sometimes just block and nothing more. Need restart. And this is when work together with both VL53L0X

Unfortunately, I don't have VL53L0X sensors except MPU6050 to reproduce your results.

Yes, only MPU work perfekt for 30min max test from me.

VL53L0X 's also work perfect alone, for 2min tests.

But all three not

Can you briefly describe the function of your sketch/project so that I can conveniently remove some of the unnecessary/dedundant codes from your sketch?